IFakerInstanceT Method (Members, ConstructorWillBe, BaseConstructorWillBe)

Typemock Isolator Developer Guide
Overloaded. Returns a fake instance of type T, and allows to set the behavior of how the fake object is created, the behavior of the constructor and the Base Constructor.

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

T Instance<T>(
	Members behavior,
	ConstructorWillBe constructorBehavior,
	BaseConstructorWillBe baseConstructorBehavior
)
where T : class

Parameters

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 .
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.
constructorBehavior
Type: TypeMock.ArrangeActAssertConstructorWillBe
Can be one of the following values:
ConstructorWillBe ValueDescription
ConstructorWillBe.IgnoredConstructor will not be executed when creating the fake object
ConstructorWillBe.CalledExecute Constructor when creating the fake object
baseConstructorBehavior
Type: TypeMock.ArrangeActAssertBaseConstructorWillBe
Can receive BaseConstructorWillBe.Ignored. Means that the constructor of the base class will not be called when creating the fake object. Applicable only when constructorBehavior is ConstructorWillBe.Called

Type Parameters

T
The type of the fake instance to be created.

Return Value

Type: T
A fake instance of Type T.
Exceptions

ExceptionCondition
TypeMockException Thrown if faking a base class constructor for a type that inherits directly from System.Object (or other mscorlib types)
TypeMockException Thrown if faking an interface - to fake an interface use an overload that does not define base class behavior
Remarks

Examples

The following test shows faking an instance without calling its base class' constructor
[TestMethod, Isolated]
public void FakeAnInstance_DoNotCallBaseCtor()
{
    // create a fake of RealLogger, calling the RealLogger constructor but not its base class c'tor
    var fake = Isolate.Fake.Instance<RealLogger>(Members.ReturnRecursiveFakes, 
                                                       ConstructorWillBe.Called, 
                                                       BaseConstructorWillBe.Ignored);
}
See Also

Reference