All your bases belong to us part 2- Verifying Called

We saw in part 1 how to change the behavior of ‘hidden’ base methods.
To verify that a base method was called, in the coming isolator 8.1 we have added a new API OnBase().

For example:

public class BaseClass
{
     public virtual int VirtualMethod(bool call)
     {
         return 1;     
     }
}
 
public class DerivedClass : BaseClass
{     
   public override int VirtualMethod(bool call)     
   {
         if (call)
             return base.VirtualMethod(call) + 1;
         return 1;     
   }
}
 

Verifying that a base method was called is now easy. Use OnBase to tell Isolator to verify only the base of the method.

[TestMethod]
public void VerifyBase_BaseWasNotCalled()
{
     // Same as new DerivedClass, but Isolator tracks calls
     var unfake = Isolate.Fake.Instance<DerivedClass(Members.CallOriginal);
 
     unfake.VirtualMethod(false);
     
    // Verify that base was not called     
    Isolate.Verify.OnBase().WasNotCalled(() => unfake.VirtualMethod(true));
}
 

Isolator also supports verifying a base of a base, to do this simply pass the type of the base you want to fake. E.g.

Isolate.Verify.OnBase(typeof(BaseClass)).WasNotCalled(() => unfake.VirtualMethod(true));

 

tip_thumb112 OnBase is supported for NonPublic method too.

Part 1

TOP