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 Value Description Members.MustSpecifyReturnValues All void calls are ignored. Unless using WhenCalled(Action) on methods that return values and properties, they will throw a . Members.ReturnNulls All 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.CallOriginal All methods are called. Use WhenCalled(Action) to change this behavior. Members.ReturnRecursiveFakes Default. 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 Value Description ConstructorWillBe.Ignored Constructor will not be executed when creating the fake object ConstructorWillBe.Called Execute 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: TA fake instance of Type T.
Exceptions
| Exception | Condition |
|---|---|
| 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
[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