开发者

MSTest with Ninject, MVC3 and WCF

I have an ASP.Net MVC3 project that calls a WCF service to get data. The WCF service in turn开发者_如何学Python uses managers and repositories etc. (in other class library projects) to get the required data.

I have applied Ninject on both the web project and the WCF project. Because I used Nuget to install Ninject MVC3, it has created a class in APP_START with bootstrapper, webactivator etc.

Now I want to write unit tests using Microsoft's testing framework, and not NUnit etc.

How do I get started? That is, what do I write in the unit test classes to use Ninject to provide mock implementations of interfaces to the web and wcf projects?

The examples I have seen, use Moq extension, which seems complex at first sight. I'd rather go without Moq if possible.

I would appreciate any links, examples, related responses, etc. Thanks


You shouldn't use Ninject to create instances of the classes you want to test. Just create an instance of the controller or service you want to test and pass a mock object as constructor parameter for each dependency.


Firstly, as @Remo Gloor says, you should definitely not be using a DI container in your tests.

You may find AutoFixture to be useful in this space. It has some automocking container capabilities (and you should also have a search about for that term). Remember that there's nothing simple about having lots of implicit mocking and wtuff being magically wired up in tests - the less you rely on magic and big object graphs in your tests the better.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜