Using Isolator Design Modes

Isolator mocking works by default on any method. We call this Design.Pragmatic mode, and it is implicitly set by the Isolated attribute.

Sometimes, especially when using Test Driven Development (TDD), you might want to restrict Isolator to mock only virtual methods. You can do this by explicitly setting the Design property of the Isolated attribute to InterfaceOnly. You can set it in any level as you’d use the Isolated attribute: Method, class or assembly. Overriding is possible by explicitly setting Design.Pragmatic, and the closest explicit definition to the test is the one that is used.

For example, you can specify that the whole test fixture will use the InterfaceOnly design mode:

[csharp][TestFixture, Isolated(Design = DesignMode.InterfaceOnly)][/csharp]

And for a specific test, use the Pragmatic mode:

[csharp][Test, Isolated(Design = DesignMode.Pragmatic)][/csharp]

Behavior of Typemock APIs under Design.InterfaceOnly

The following APIs throw a DesignModeException when used under Design.InterfaceOnly:

  • Isolate.Fake.StaticMethods
  • Isolate.Fake.StaticConstructor
  • All Isolate.NonPublic APIs
  • All Isolate.Swap…. APIs

In addition, the following APIs throw a TypemockException within the conditions:





Throws exception when…



T has some or all virtual methods

Virtual methods can be faked and verified, other methods cannot. Default recursive fake behavior applies if the returned object can also be faked.

Sealed object

All methods are non-virtual



All argument types  of T’s constructors have some virtual methods

Arguments are faked as in 1. Object is created and returned.

All dependencies are sealed or have only non-virtual methods.



Virtual methods

Can set any behavior

Called on non-virtual methods



Virtual methods

Can verify the behavior

Called on non-virtual methods