NSubstitute
NSubstitute copied to clipboard
Add .ReceivedNothingElse() method
NSubstitute already allows powerful assertion that calls were made. However that's only part of the problem.
If can also be useful to check that other calls haven't happened. For smaller objects this isn't too bad, but for larger objects it can quickly become cluttered. Worse, if the object being substituted is itself extended the tests must be manually extended to cover those methods.
If NSubstitute were extended with a .ReceivedNothingElse() method, it would be trivial in a code review to check that that was the final call made to a substitute object, and be confident that a passing test was correctly asserting all calls.
A duplicate of #203?
I still like this idea from #203 for achieving this:
Have you seen
Received.InOrder? It uses the beginnings of a call query model, and checks the query against aSequenceInOrderAssertion. This works differently to the assertion you're after (only checks for extra calls to methods in the query while ignoring other calls, excludes properties), but if you write your own assertion code you could probably haveReceived.Only(...)or similar that will let you check you got the required calls, and throw if there are extraReceivedCalls(). (If you need it, we could look at adding aNonMatchingCallsproperty toIQueryResults?)