typemocktypemock-isolator

Inject Mocking using TypeMock


I using Ioc pattern(Ninject) in my application. I want make a test case (using TypeMock) to testing Ioc pattern(Ninject). but I don't know how to mock object which creating using Ninject. Kindly let me know how can I inject mock or inject dependencies using TypeMock. Thanks


Solution

  • I'm not sure what you're testing but you might be interested in using Isolate.Swap

    Just create a fake object and then call Swap so that the next instance created shall be a fake one - no need for Ioc:

    var fakeObject = Isolate.Fake.Instace<MyObject>();
    Isolate.Swap.NextInstace<MyObject>().With(fakeObject);
    // Call code under test
    

    The first object of type MyObject created after this code will be a fake object.

    If you do want to use Ioc to inject your fake object you need to be able to set it to return the object created using Isolate.Fake.Instace.