How can I tell Moq to return a Task?

I’ve got an interface which declares

Task DoSomethingAsync();

I’m using MoqFramework for my tests:

[TestMethod()]
public async Task MyAsyncTest()
{
   Mock<ISomeInterface> mock = new Mock<ISomeInterface>();
   mock.Setup(arg => arg.DoSomethingAsync()).Callback(() => { <my code here> });
   ...
}

Then in my test I execute the code which invokes await DoSomethingAsync(). And the test just fails on that line. What am I doing wrong?

4 Answers
4

Leave a Comment