As Bruno correctly pointed out, the problem is that the mocked StartAsync
is throwing an exception synchronously, not returning a faulted task.
However, the correct code cannot use new Task
(which will cause a hang, since the task is never started). Instead, use Task.FromException
:
FirstProcessor.Setup(x => x.StartAsync(It.IsAny<TextWriter>())).Returns( Task.FromException(new Exception("some exception happened.")));