Search code examples
c#moqnsubstitute

What is the NSubstitute equivalent of the Moq VerifyNoOtherCalls() method


I'm currently a heavy Moq user and I'm researching other mocking frameworks.

I'm looking on NSubstitute and like their syntax and the ease of creating test spies.

The only feature I'm missing in NSubstitute is VerifyNoOtherCalls. It is very handy because it lets me to quickly explore existing calls for all method's methods and decide if they are legitimate or not. This is especially helpful when I have to cover legacy code which has no tests at all or covered partially.

I've searched the NSubstitute docs and cannot find the equivalent option in their framework. Can anyone suggest how I might do this?


Solution

  • There is no equivalent for this in NSubstitute. It is possible to implement something similar using the ReceivedCalls() extension method, which will return a list of all calls received. It's a bit fiddly, but possible to query this to ensure no additional calls were received.

    If you don't mind checking internal details, you can check Received.InOrder for some other implementation ideas.