Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ninject / MVC4 - integration test of a controller

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.

like image 763
Maxim Eliseev Avatar asked Dec 21 '25 05:12

Maxim Eliseev


1 Answers

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
}
like image 107
Maxim Eliseev Avatar answered Dec 24 '25 04:12

Maxim Eliseev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!