samedi 9 janvier 2016

Ninject dynamic module loading in Visual Studio 2015

My project it's an assembly, a .DLL done with C#. I don't have the front-end so, I can only test the program without run it. These tests are in a class into another project, and i can't modify this test class because it's provided "as is" from my professor and consists in my evaluation. (University purposes)

Into my assembly project i have a Factory like this:

public class BugTrackerFactory : IBugTrackerFactory
{
    public void BugTrackerInitialize(IPrincipal principal, string connectionString)
    {
        //code here
    }

    public IBugTracker LoadBugTracker(IPrincipal principal, string connectionString)
    {
        //code here
    }
}

public class BugModule : NinjectModule
{
    public BugModule() { }

    public override void Load()
    {
        this.Bind<IBugTrackerFactory>().To<BugTrackerFactory>();
    }
}

And these are the tests in another project:

public static class Configuration
{
    public const string ImplementationAssembly =
        @"C:\Users\matte\Documents\Visual Studio 2015\Projects\BugTrackingSystem\BugTrackingSystem\bin\Debug\BugTrackingSystem.dll"; //this is my path to assembly project

}

[TestFixture]
public abstract class TestRoot {
    protected static readonly IBugTrackerFactory Factory;
    .....
    .....
    //all code initializations for testing purpose


    static TestRoot() {
        var kernel = new StandardKernel();
        try {
            kernel.Load(Configuration.ImplementationAssembly);
            Factory = kernel.Get<IBugTrackerFactory>();
        } catch (Exception e) {
            Debug.WriteLine(e);
        }
    }

    ...
    ...
    //all the tests

With this configuration I always get the following error when trying to launch the tests with Nunit:

    One or more child tests had errors
Exception doesn't have a stacktrace

Ninject.ActivationException: Error activating IBugTrackerFactory
No matching bindings are available, and the type is not self-bindable.
Activation path:
  1) Request for IBugTrackerFactory

Suggestions:
  1) Ensure that you have defined a binding for IBugTrackerFactory.
  2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
  3) Ensure you have not accidentally created more than one kernel.
  4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
  5) If you are using automatic module loading, ensure the search path and filters are correct.

   in Ninject.KernelBase.Resolve(IRequest request)
   in Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
   in BugTrackerTests.TestRoot..cctor() in C:\Users\matte\Documents\Visual Studio 2015\Projects\BugTrackerTests\BugTrackerTests\BasicTests.cs:riga 37

I really don't know what to do, someone here can help me? Thank you

Aucun commentaire:

Enregistrer un commentaire