Lord Vermillion
Lord Vermillion

Reputation: 5424

Web API Unit Test NLog assembly error

I'm trying to add unit tests to an existing Web API 2 application.

In my test project i've added a reference to the .dll of my Web API from it's obj/release folder. The Web API uses NLog.

I initiate my controller i want to test

var controller = new OrderController();

Then I get the following exception when I run the test.

System.IO.FileNotFoundException: Could not load file or assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of its dependencies. The system cannot find the file specified

I don't know what I have to do with NLog as it's working fine in my Web API..

Any suggestions?

Upvotes: 1

Views: 321

Answers (1)

Nkosi
Nkosi

Reputation: 247323

Instead of referencing the web api dll directly, reference the project if they are in the same solution.

When the test project is running it copies the referenced dll over to its bin directory. If the web api project depends on the nlog dll however, it will not find it when the test runs. Have the test project reference the nlog dlls as well.

Upvotes: 1

Related Questions