How can I tell Moq to return a Task?

前端 未结 4 1668
盖世英雄少女心
盖世英雄少女心 2020-11-27 09:56

I\'ve got an interface which declares

Task DoSomethingAsync();

I\'m using MoqFramework for my tests:

[TestMethod()]
public          


        
4条回答
  •  死守一世寂寞
    2020-11-27 10:24

    You only need to add .Returns(Task.FromResult(0)); after the Callback.

    Example:

    mock.Setup(arg => arg.DoSomethingAsync())
        .Callback(() => {  })
        .Returns(Task.FromResult(0));
    

提交回复
热议问题