MethodCallContextContinueFakingThisMethodRecursively Property

Typemock Isolator Developer Guide
Allow recursive calls to this faked method to be faked and reenter DoInstead lambda

Namespace:  TypeMock
Assembly:  TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
Syntax

public bool ContinueFakingThisMethodRecursively { get; set; }

Property Value

Type: Boolean
Remarks

The default is to call the original implementation to the faked method so that it is easy to use context.Method to invoke the original method, without creating a recursive endless loop
Examples

public int Foo(int i)
{
    if (i==0) return 1;
    return Foo(i)+1;
}

[Isolated,TestMethod]
public void Test()
{
    bool called=false;
    Isolate.WhenCalled(() => Foo(0)).DoInstead(context=> 
    { 
         // allow calls down the stack to be faked
         context.ContinueFakingThisMethodRecursively = true;

         // call original code with different arg
         int passedVal = (int)context.Parameters[0];
         return context.Method.Invoke(context.Instance, new object[] { passedVal + 1});
    });
    Assert.AreEqual(foo(), 1);
}
See Also

Reference