I'm trying to figure out how to test my Ninject library. I mean, my library uses an Ninject kernel in order to resolve all their dependencies. This is the main class of my library:
public class Core : ICore {
private Ninject.IKernel compositionRoot;
public Core()
{
this.state = KernelState.initializing;
this.backends = new Dictionary<Core.Identity.DomainIdentity, Backend.Infrastructure.IBackend>();
this.BuildIoC(compositionRoot);
this.configuration = this.compositionRoot.Get<Core.Configuration.ICoreConfiguration>();
this.serviceHost = this.compositionRoot.Get<System.ServiceModel.ServiceHost>();
}
where BuildIoC()
is:
internal void BuildIoC(Ninject.IKernel compositionRoot = null)
{
this.compositionRoot = compositionRoot ?? new Ninject.StandardKernel(
new IoC.Modules.BackendModule(),
new IoC.Modules.PluginsModule(),
new IoC.Modules.ConfigurationModule(),
new IoC.Modules.ServiceModule(this));
}
Currently, I need to build some tests on this class. So:
- I'd like to "mock"
configuration
andserviceHost
fields. How could I get this? - What does
NSubstituteMockingKernel
stand exactly for? I don't quite figure out what's that for.
Up to now, I've not been able to achieve anything elegant. I don't know what mock, ninject kernel, modules, classes?
For example, serviceHost
is an implementation of a webservice. I'd like Core
class loads a mocked configuration
object... How would I proceed in order to get this?
A library should use an IoC framework?