0

I'm writing unit tests for a Website project in Visual Studio. The unit test project needs to reference a few classes that are in the Website project's App_Code.

In order to reference the classes, I am linking the relevant *.cs files.

Add > Existing Item > Add as Link

If it were a Web Application project not a Website project, then I would reference the assembly. The Website project doesn't appear to have an assembly, though, so my workaround is to link the required *.cs files instead.

Linking the files does work. It's non-ideal, though, because when we change the *.cs files in the Website project, they become out of date in the unit test's project (this seems to be a bug), and I subsequently need to remove and re-link them.

The answers at Unit Testing ASP.net Web Site Project code stored in App_Code indicates that moving the classes to a class library project.

Community
  • 1
  • 1
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
  • Can you move those classes to a class library? Then both the web site and the test project can use the same assembly. – Matt Johnson-Pint Mar 24 '15 at 16:04
  • I can ask the technical lead about that. If the lead disagrees, though, then I'm stuck with them in the App_Code folder. Disagreement is likely :-(. – Shaun Luttin Mar 24 '15 at 16:05
  • 2
    My advice - don't let office politics get in the way of good programming practices. :) – Matt Johnson-Pint Mar 24 '15 at 16:05
  • I can't reproduce the link error. Do you have the website and test project in the same solution? It may be setting the date modified of the CS files to NOW when fetching from your source control would fix your problem. An alternative approach would be a prebuild step on your test project to copy the source files from App_code into your test project. However, as @MattJohnson said, you should move the code out into a class library, particularly since websites projects seem to have been deprecated in vs2013: https://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx – forsvarir May 13 '15 at 13:48

0 Answers0