Hi,
This is an interesting approach, and you stumbled on a limitation in Isolator along the way; as part of Isolator's internal implementation, when you perform a WhenCalled() on a call chain that begins with a live (i.e. non faked) object, fakes are created along the call chain that behave like the real objects. This means that when you performed:
Isolate.WhenCalled(() => Mock.OtherMethod()...
It caused the getter of the Mock property, which is defined on an object that's not faked (FizzMockWrap) to return a CallOriginal fake, which interfered with the behavior you expected from Buzz() (to return recursive fakes).
Working around this is easy - replace the FizzMockWrap implementation by accessing a field rather than a property. This way we don't override the field's behavior:
internal class FizzMockWrap
{
private Fizz mock;
public Fizz Mock { get { return mock; } }
public FizzMockWrap()
{
mock = Isolate.Fake.Instance<Fizz>();
Isolate.WhenCalled(() => mock.OtherMethod()).DoInstead(c => 0);
}
public static Fizz MakeFakeStatic()
{
var staticMock = Isolate.Fake.Instance<Fizz>();
Isolate.WhenCalled(() => staticMock.OtherMethod()).DoInstead(c => 0);
Isolate.Swap.NextInstance<Fizz>().With(staticMock);
return staticMock;
}
}
Please let me know if this workaround works for you. I will look into fixing the original issue and avoid overriding the fake instance.
Thanks,
Doron
Typemock Support