vendredi 30 octobre 2015

Managing dependencies on c# Unit Test

I'm starting to make some tests with Unit Tests (not TDD, just writing some tests at this moment) using Visual Studio and a strange questions came in my mind after a error explore into my Test Project.

First of all, I created a Web Api 2 project, created my Model, Controllers and other stuff. I've separated my repository, configured dependency injection and the project was fully functional.

After that, I created my Unit Test project, add a reference to the previous Web Api project, created a mock for my repository, instantiate my controller, passed the mock as constructor injection, called the method and asserted the result. The code was functional but when I compile, it complains about the can't find the ApiController from System.Web.Http.

The tries were:

  • The first thing I've tried was, searching for the dependency in "Add Reference" context menu. I added but the version was different, so was not working.

  • The second thing worked, but was very ugly. Again entered in "Add Reference" context menu, browsed the directory from Web Api project and choosen the bin folder and selected all dlls. That worked, but was terrible, because once I version that test, will be broken because was referencing a path probably not available on the checkout computer.

  • The third try was copy the package.json from the Web Api project and paste on the Unit Test project and run on the NuGet console "Update-Packages -Reinstall". The third option worked, but I don't know if is the correct way to do that.

TL;DR;

How do you guys reference all DLLs dependencies on Unit Test project?

Aucun commentaire:

Enregistrer un commentaire