IIsolateNonPublicWhenCalled Method (Object, String)

Typemock Isolator Developer Guide
Sets behavior for a specific method on a an object

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

INonPublicMethodHandler WhenCalled(
	Object targetObject,
	string methodName
)

Parameters

targetObject
Type: SystemObject
The object to set method behavior on.
methodName
Type: SystemString
The name of a method to set behavior on.

Return Value

Type: INonPublicMethodHandler
An interface reference.
Remarks

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

Here is an example how to use WhenCalled in order to ignore (stub) a private call:
[TestMethod]
[Isolated]
public void StubPrivateMethod_DoNotWriteToDisk()
{
    RealLogger fake = Isolate.NonPublic.Fake.Instance(typeof(RealLogger));

    // Avoid performing actual write to disk by ignoring (stubbing) a private call
    Isolate.NonPublic.WhenCalled(fake, "WriteToDisk").IgnoreCall();

    // The private call is stubbed so no actual disk writes are performed
    fake.Log("Hello World");

    Assert.AreEqual(1, fake.LineCount);
}
See Also

Reference