0

I have static method in static class which injects my dependencies:

 public static void InjectDependency(NinjectModule module);

I have static property to get instance of each object:

 public static IKernel AppKernel {get;set;}

If I'd like to create an instance, depending on my injeced NinjectModule-derived classes, I use following code:

 IInterface instance = MyStaticClass.AppKernel.Get<IInterface>();

But now I want to make my kernel return mock object, created with NSubstitute. How can do that?

klutch1991
  • 229
  • 2
  • 16

2 Answers2

1

See this Ninject MockingKernel, with this when you are testing you dont use the new StandardKernel(), you will use new NSubstituteMockingKernel()- in your case, but the MockingKernel has support to RhinoMocks, FakeItEasy ** and **Moq.

Joel R Michaliszen
  • 4,164
  • 1
  • 21
  • 28
0

You can just use the StandardKernel and bind the substitute:

var kernel = new StandardKernel();
// Set up kernel

var substitute = Substitute.For<ISubstitutedObject>();
kernel.Bind<ISubstitutedObject>().ToContstant(substitute);