C# – How to verify that method was NOT called in Moq

cmoqnet

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());

Best Answer

Run a verify after the test which has a Times.Never enum set. e.g.

_mock.Object.DoSomething()
_mock.Verify(service => service.ShouldntBeCalled(), Times.Never);