When I use DSharp.Testing.Mock I can use the following syntax:
FMyMock.Setup.WillReturn(1).Exactly(2).WhenCalling....
FMyMock.Setup.WillExecute.Exactly(2).WhenCalling....
but what is the equivalent syntax if I use Spring.Mocking?
With Spring.Mocking
you don't need to explicitly define any expectation if it should not return a specific value when using Dynamic
mode (which is the default mode). Only the Strict
mode needs specifying every expectation.
However you don't specify the number of expected calls - if you wish to verify the number of calls, then you use mock.Received(...)
after you execute the code you wanted to test.
If you want to return different values for subsequent calls, then you can specify multiple values on the Returns
method. Or you explicitly specify a param matcher for the different return values if the input parameters have different values.
But the overall philosophy is to write less mocking code to achieve the testability of your SUT. The more mocking code you write, the more you risk assuming internals of your implementation that might change in the future and break your tests.