Faking Instance Constructors

By default, Typemock Isolator fakes calls to the instance constructor. This means that any initialization done in the constructor is not performed.

The default behavior for constructor is as follows:

When using Members.CallOriginal(), the original constructor is called.

When using all other Members enums, the constructor is not called.

When to Use

When you use a fake object and want to call the real constructor.

Syntax

Use the Isolate.Fake.Instance<T>() overload that accepts the following arguments:

Argument

Description

Members behavior

Specify the default behavior for fake instance methods.

ConstructorWillBe

Specify whether you want to call the constructor (Called or Ignored).

params object [] constructorParameters

The parameters to be passed to the constructor.

Samples
Sample 1: Faking All Methods Except the Constructor

The following sample shows how to fake all methods except the constructor and pass the constructor-specific arguments as follows:

All methods except the constructor are faked

The constructor will be called with the arguments 5, "Typemock"

C#

Isolate.Fake.Instance<Derived>(Members.ReturnRecursiveFake, ConstructorWillBe.Called, 5, "Typemock");

VB

Isolate.Fake.Instance(Of Derived)(Members.ReturnRecursiveFakes, ConstructorWillBe.Called, 5, "Typemock")

Sample 2: Calling Original Methods and Ignoring the Constructor

The following sample shows how to use the second argument of Isolate.Fake.Instance() to call all original methods while ignoring the constructor as follows:

All original methods are called by using Members.CallOriginal

The constructor should be ignored by using ConstructorWillBe.Ignored

C#

Isolate.Fake.Instance<Derived>(Members.CallOriginal, ConstructorWillBe.Ignored);

VB

Isolate.Fake.Instance(Of Derived)(Members.CallOriginal, ConstructorWillBe.Ignored)