INonPublicIndexerRecorderWhenGetCalled Method (Object)

Typemock Isolator Developer Guide
Sets specific behavior for a non-public index getter 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

IReturnValueHandler<Object> WhenGetCalled(
	Object fake
)

Parameters

fake
Type: SystemObject
The object to set indexer behavior for.

Return Value

Type: IReturnValueHandlerObject
An interface reference.
Remarks

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

Here is an example how to use Isolate.NonPublic.Indexer.WhenGetCalled() in order to set return value for an index call:
[TestMethod]
[Isolated]
public void ChangeIndexGetReturnValue()
{
    RealLogger fake = Isolate.Fake.Instance<LogContainer>();

    // Set the internal indexer to return a specific value
    Isolate.NonPublic.Indexer.WhenGetCalled(fake).WillReturn("hello");

    // The object under test uses the private index get result as part of a calculation
    string result = fake.GetStringAt(10);
    Assert.AreEqual("hello", result);
}

// Excerpt from class under test
public class LogContainer
{
    // method under test
    public string GetStringAt(int line)
    {
        return this[line];
    }

    private string fileName = ...

    // private indexer
    private string this[int line]
    {
        get { return ReadFromFile(fileName, line); }
    }

}
See Also

Reference