IMockControlMockField Method

Typemock Isolator Developer Guide
Create a Mock object and assign it to a given field.

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

IMockControl MockField(
	string fieldName
)

Parameters

fieldName
Type: SystemString
The name of the field to be mocked

Return Value

Type: IMockControl
A mock object that is assigned to the field.
Exceptions

ExceptionCondition
TypeMockExceptionIf constructor is not mocked, field is not found or field can't be mocked
Examples

Show how to mock a call on a public field. this works on private members as well
[Test]
[VerifyMocks]
public void MockInstanceField()
{
    // mock next instance creation of ClassWithField 
    Mock mock = MockManager.Mock(typeof(ClassWithField));
    // mock the "field" field and set the expectation on it
    Mock mockedField = mock.MockField("field");
    mockedField.ExpectAndReturn("ReturnFive", 6);

    ClassWithField target = new ClassWithField();
    int actual = target.field.ReturnFive();
    // ReturnFive call is mocked and should return 6
    Assert.AreEqual(6, actual);
}
See Also

Reference