开发者

Testing Ninject (or any IoC container) bindings?

I am using Ninject in my ASP开发者_如何学C.NET MVC 3 project and now have a complicated object graph.

I would like some unit tests to ensure that all my required types are bindable - at the moment the only way I'm finding out is via the ASPX error page.

I'm having trouble finding documentation on how to do this.

Is it as simple as writing

_kernel.Get<IService>(); 

and letting the exception fail the test? Or is there a cleverer way to do this using the MVC hooks for DI?


Additionally to ordinary unit tests, we have integration tests that test everything but UI and DB including the Ninject bindings. Therefore we setup everything as in production and rebind these parts to mocks. This will also test the Ninject bindings.

In case of MVC this means you have to create a kernel, load the same modules as in production and rebind the DB access. Then create an instance of the controller and call the actions you want to test and check if they behave as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜