Task.WhenAll
will call StartAsync
, that will throw.The exception is thrown on the calling thread. Before a task could be created.
You want StartAsync
to return a Task
:
firstProcessor.Setup(x => x.StartAsync(It.IsAny<TextWriter>())).Returns(new Task(() => { throw new Exception("err"); }));