Although I prefer stubbing over mocking as much as possible, sometimes it is unavoidable to check the behavior of your test objects. It is a tradeoff to make between rewriting the application logic to make it easier testable or using some mocking magic.
In NSubstitute, the stubbing library of my choice, you can use the Received() or DidNotReceive() extension methods:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var calculator=Substitute.For<ICalculator>(); | |
calculator.Add(1, 2); | |
// Check received with second arg of 2 and any first arg: | |
calculator.Received().Add(Arg.Any<int>(), 2); |
More information: https://nsubstitute.github.io/help/received-calls/