unit testing - How do I correctly instantiate a new controller when using Ninject? -


i created demo web api application utilizes ninject. application works fine can run it, navigate defined route, , data i'm expecting. want begin adding unit tests test apicontroller.

how instantiate new apicontroller? i'm using var sut = new dogscontroller(); results in error, "... not contain constructor take 0 arguments". it's correct don't have constructor takes 0 arguments ninject should taking care of me, correct? how resolve this?

you have wired ninject web api application, not unit test project. result, ninject not creating dependencies controller, or controller explicitly creating (in web api application, framework creates controller).

you wire ninject unit test project, not correct thing do. should creating controller in tests known state, should either passing in known dependencies, or passing in form of mock dependencies.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -