MSTest with Ninject, MVC3 and WCF

I have an ASP.Net MVC3 project that calls a WCF service to retrieve data. The WCF service, in turn, uses managers and repositories, etc. (In other library projects) to obtain the required data.

I applied Ninject both in a web project and in a WCF project. Since I used Nuget to install Ninject MVC3, he created a class in APP_START with a loader, webactivator, etc.

Now I want to write unit tests using the Microsoft testing environment, not NUnit, etc.

How do i get started? That is, what am I writing in unit test classes to use Ninject to provide mock interface implementations for web projects and wcf?

In the examples I saw, use the Moq extension, which seems complicated at first sight. I would rather go without Mok, if possible.

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

+4
source share
2 answers

You cannot use Ninject to instantiate classes that you want to test. Just create an instance of the controller or service that you want to test, and pass the mock object as a constructor parameter for each dependency.

+3
source

First, as @Remo Gloor says, you should definitely not use the DI container in your tests.

You can find AutoFixture to be useful in this space. This has some features of a car wash container (and you should also have a search for this term). Remember that there is nothing simple in that tests have magical coupling and wtuff, which are magically connected in tests - the less you rely on the graphics of magic and large objects in your tests, the better.

+1
source

All Articles