All your bases belong to us part 1- Changing Behavior

Handling ‘hidden’ base methods is tricky when testing components.
A ‘hidden’ base is a virtual method that has an overridden implementation.

In isolator 8.1 we have added a new API OnBase() to help in these situations.

For example:

public class BaseClass
    public virtual int VirtualMethod(bool call)
        // do something with the network
        int theValue = 0;
        return theValue;
public class DerivedClass : BaseClass
    public override int VirtualMethod(bool call)
        return base.VirtualMethod(call) + 1;

Faking only the base method is now easy. Use OnBase to tell Isolator to fake only the base of the method.

public void FakeBase_OnlyBaseIsFaked()
    var unfake = new DerivedClass();
    Isolate.WhenCalled(() => unfake.VirtualMethod(false)).OnBase().WillReturn(10);
    Assert.AreEqual(11, unfake.VirtualMethod(true));

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

Isolate.WhenCalled(() => unfake.VirtualMethod(false))


 tip OnBase is supported for NonPublic method too.

In Insights you can see that the derived is not faked and the base is:


Part 2