The other day I was pairing with a colleague. We where working on unit testing some classes that where using the new async and await features. We ran into some issue trying to get mocking working for our classes dependencies. Here is some example code on how we got things to work.
So given the following code:
And we can test it like this:
Note the usage of the TaskCompletionSource in the unit test along with the declaration of the test using “async Task”.