Quantcast
Viewing all articles
Browse latest Browse all 3

Answer by Stephen Cleary for Moq Throw async exception in one of tasks in call to Task.WhenAll

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.")));

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>