Search code examples
unit-testingtypemocktypemock-isolator

Fake classes using TypeMock


We are migrating from MOQ to Typemock. In MOQ we've a functionality of getting a proxy class from the interface, we want to achieve the same from typemock. Actually our requirement is something like this, we are using Ninject IoC/DI pattern in our application and wants to enjoy the benefits of it in unit testing.

We want to use Ninject kernel to register the interface with FakeClass or more appropriately ProxyClass. The syntax is somewhat this

kernel.Bind(interface).to(class)

and we want

kernel.Bind(interface).to(fakeclass)

In MOQ we do this like this

var mock=new Mock(interface)

and mock.Object() method gives us the fake class.

Thanks


Solution

  • To create a fake object, use the Isolate.Fake.Instance<T>() method:

    Interface fake = Isolate.Fake.Instance<Interface>();
    

    Then you can just use that fake instance:

    kernel.Bind(interface).to(fake);
    

    This was from this blog entry