It may be useful to write an integration test for a controller. It is not clear how to instantiate a controller if its dependencies are managed by Ninject.
Please note it is not a unit test - I want to test a complete controller with all dependencies. I am using MVC 4, NInject 3 and MbUnit.
I tried to find an answer on SO but I could not so I am sharing my solution.
public class SearchControllerTest
{
private SearchController searchController;
[SetUp]
public void Setup()
{
IKernel kernel = new StandardKernel();
NinjectWebCommon.RegisterServices(kernel);
searchController = kernel.Get<SearchController>();
}
//Tests
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With