I have mocks working where I test that methods on my mocked object are called with the correct parameters, and return the right result.
Now I want to check another condition. In this case, NO methods should be run on the mocked object. How can I express this in a unit test?
You could create your mock as strict. That way only the methods you Setup (or Expect, depending on which version of Moq you're playing with) are allowed to be run.
var foo = new Mock<IFoo>(MockBehavior.Strict);
foo.Expect(f => f.Bar());
Any time a method is called on foo other than Bar(), an exception will be raised and your test will fail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With