Isolator Extensibility – Verifying An Instance Was Not Called

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:

public void FakeInstanceWasNotCalled()
var fakeObject = Isolate.Fake.Instance<SomeObject>();

And the VerifyInstanceWasNotCalled looks like this:

public static void VerifyInstanceWasNotCalled<T>(T fakeObject)
foreach (MethodInfo info in typeof (T).GetMethods())
string methodName = info.Name;
Isolate.Verify.NonPublic.WasNotCalled(fakeObject, methodName);

And you’ve got yourself a verification method for the whole method or interface.