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
Parameters
- fieldName
- Type: SystemString
The name of the field to be mocked
Return Value
Type: IMockControlA mock object that is assigned to the field.
Exceptions
Exception | Condition |
---|---|
TypeMockException | If constructor is not mocked, field is not found or field can't be mocked |
Examples
[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