INonPublicFakerNextInstance Method (Type, Members, ActionMethodCallContext)

Typemock Isolator Developer Guide
Overloaded. Fake a future instance of type.

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

Object NextInstance(
	Type type,
	Members behavior,
	Action<MethodCallContext> doInstead
)

Parameters

type
Type: SystemType
The type of the fake instance to be created.
behavior
Type: TypeMock.ArrangeActAssertMembers
Can be one of the following values:
Members ValueDescription
Members.MustSpecifyReturnValuesAll void calls are ignored. Unless using WhenCalled(Action) on methods that return values and properties, they will throw a TypeMockException.
Members.ReturnNullsAll void calls are ignored. Unless using WhenCalled(Action) on methods that return values and properties, they will return null values (or zero for value types).
Members.CallOriginalAll methods are called. Use WhenCalled(Action) to change this behavior.
Members.ReturnRecursiveFakesDefault. All void calls are ignored. When calling the fake's methods returning values or properties, they will return a fake value, which presents this behavior recursively. Any deep call will never return a Null value.
doInstead
Type: SystemActionMethodCallContext
The action to run at the start of the constructor.

Return Value

Type: Object
An object of type type which is used as a faking handle.
Examples

This example shows using NextInstance in order to fake a future instance:
[TestMethod]
[Isolated]
public void FakeAFutureInstance_StubIncrementMethod()
{
    bool flag = false;

    RealLogger fake = Isolate.NonPublic.Fake.NextInstance(typeof(RealLogger), Members.ReturnRecursiveFakes, context => flag = true);

    // This object is swapped with the fake
    RealLogger logger = new RealLogger();

    Assert.IsTrue(flag);
}
See Also

Reference