Using Isolator’s Verify (C#) or Assert.TheseCalls, we have the option to use WasNotCalled (or VB DidNotHappen) to verify a method was not called.
What if I want to check that on a single instance, any of the methods were not called?
I’ll use a bit of reflection to get all the method names, and use the Verify.NonPublic version of WasNotCalled to make sure the calls weren’t made.
So if my test looks like this:
1 |
[TestMethod]<br /><span class="kwrd">public</span> <span class="kwrd">void</span> FakeInstanceWasNotCalled()<br />{<br /> var fakeObject = Isolate.Fake.Instance<SomeObject>();<br /> IsolatorExtensions.VerifyInstanceWasNotCalled(fakeObject);<br />} |
And the VerifyInstanceWasNotCalled looks like this:
1 |
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> VerifyInstanceWasNotCalled<T>(T fakeObject)<br />{<br /> <span class="kwrd">foreach</span> (MethodInfo info <span class="kwrd">in</span> <span class="kwrd">typeof</span> (T).GetMethods())<br /> {<br /> <span class="kwrd">string</span> methodName = info.Name;<br /> Isolate.Verify.NonPublic.WasNotCalled(fakeObject, methodName);<br /> }<br />} |
And you’ve got yourself a verification method for the whole method or interface.