IsolateWhenCalledT1, TResult Method (FuncT1, TResult)

Typemock Isolator Developer Guide
Accepts a method in the form of a parametric Lambda expression, to set a specific behavior on it. The expression's parameters are used to define custom argument matching.

Namespace:  TypeMock.ArrangeActAssert
Assembly:  Typemock.ArrangeActAssert (in Typemock.ArrangeActAssert.dll) Version: 9.4.1.0 (9.4.1.0)
Syntax

public static INonVoidMatchingHandler<T1, TResult> WhenCalled<T1, TResult>(
	Func<T1, TResult> func
)

Parameters

func
Type: SystemFuncT1, TResult
A function in a form of a Lambda expression that expresses the method we want to set a behavior on. The parameters passed to the action will be used in the method to define custom arguments matching

Type Parameters

T1
TResult

Return Value

Type: INonVoidMatchingHandlerT1, TResult
A interface reference.
Remarks

Because of the nature of fluent interface, WhenCalled should be used with its proceeding methods.
Examples

Here is an example how to use WhenCalled() with AndArgumentsMatch() in order to return a value if an argument is inside a range of values:
[TestMethod]
[Isolated]
public void FakeAnInstance_StubIncrementMethod()
{
    RealLogger fake = Isolate.Fake.Instance<RealLogger>();

    // Change the return value of AddLines() if the number of lines is between 1 and 5
    Isolate.WhenCalled((int i) => fake.AddLines(i))
        .AndArgumentsMatch(i => i <= 5 && i >=1)
        .WillReturn(10);

    Assert.AreEqual(10, fake.AddLines(3));
}
See Also

Reference