3

Using NSubstitute. For some tests I want to assert that a Substitute has received no calls whatsoever. I could use DidNotReceiveWithAnyArgs() for every method in the interface, but that is tedious and not as robust (if a new method is added to the interface, a developer could easily overlook adding that to the test).

I'm looking for something functionally similar to Moq's VerifyNoOtherCalls() being called without any other Verify checks.

E-Riz
  • 31,431
  • 9
  • 97
  • 134

1 Answers1

7

The extension method ReceivedCalls(), which returns all calls that were received by the substitute, can be used to test that no calls were received.

For example (using FluentAssertions):

mySubstitute.ReceivedCalls().Should().BeEmpty();

Or using MSTest assertions:

Assert.IsFalse(mySubstitute.ReceivedCalls().Any());
E-Riz
  • 31,431
  • 9
  • 97
  • 134