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 … Read more

How to verify that method was NOT called in Moq?

How do I verify that method was NOT called in Moq? Does it have something like AssertWasNotCalled? UPDATE: Starting from Version 3.0, a new syntax can be used: mock.Verify(foo => foo.Execute(“ping”), Times.Never()); 8 s 8 Run a verify after the test with the Times.Never() option. _mock.Object.DoSomething() _mock.Verify(service => service.ShouldntBeCalled(), Times.Never());