Using Rhinomocks, how can I verify that a Mock/stub was never called at all? Meaning no methods was called on the mock/stub?
I am aware of the AssertWasNotCalled method, but this method requires that I mention a method name. (Perhaps I have a class with 10 different methods that could be called).
Log.AssertWasNotCalled(x => x.LogAndReportException(null, null), x => x.IgnoreArguments());
You can use a Strict mock, althought this is a feature that may go away in the future:
var mocks = new MockRepository();
var cm = mocks.StrictMock<ICallMonitor>();
cm.Replay();
cm.HangUp(); // this will cause VerifyAllExpectations to throw
cm.VerifyAllExpectations();
In this syntax, a Strick Mock only allows explicitly defined calls.
You can use the StrictMock
method to create a strict mock - this will fail if any unexcepted method call is used. According to Ayende's site, this is discouraged, but it sounds like exactly the scenario where it would be useful.
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