I created a .NET Core web app in VS2015 using the empty web app template. It targets the full framework 4.6.1. It is for a middleware which I am using across a number of other web apps. I followed the instructions here, and the middleware works when I integrate it with another web app.
Now I want to write some unit tests for it, so I created a unit test project (using the Test Project template) that is targetting the same framework. Then I referenced the project that has the middleware class I want to unit test. But when I try to use the middleware class in my unit test method, VS would complain and say it could not find it, even if I type with fully qualified namespace. In fact, Intellisense is not bringing up any class in the target project. And if I try to build the unit test project, it would return an error: The type or namespace name 'xxxxMiddleware' could not be found (are you missing a using directive or an assembly reference?)
. And when I go into my test unit's References and double-click the project that is the target of my unit test, VS pops the message The project cannot be viewed in the object browser because it is unavailable or not yet built. Please ensure that the project is available and built.
What am I doing wrong?
UPDATE
If I reference the .exe
for my target project, it manages to resolve my middleware class. Very odd! I may have to do that workaround for now until I get a better answer.
UPDATE 2
I spoke too soon. Adding the .exe
lets me compile my unit test project. But if I run the test, I get an error saying System.BadImageFormatException: Could not load file or assembly '{assembly for the target of my test}' or one of its dependencies. An attempt was made to load a program with an incorrect format.
. What a nightmare.