我有以下结构:
Solution
|
src
|
|-- ITConsole <- main app (ASP.NET MVC, DNX 4.5.1)
|
`-- ITConsoleTests <- What kind of project should this be?
MainApp正在使用DNX 4.5.1,但是如果我创建一个标准的NUnit单元测试应用程序,它只作为一个经典的.NET Framework类库可用,目标为.NET Framework 4.5.2,并不作为Web类库,无法与我的主应用程序一起工作。
因此,以防万一它可能作为一个经典的.NET framework Microsoft Unit Test framework项目(.NET程序集)工作,我尝试手动查找和添加引用(通过添加引用和浏览),以获得.NET依赖项来解决。我知道.NET程序集引用很遗憾地无法传递。所以如果UnitTest.dll引用MainApp.dll,而MainApp.dll依赖于ASP.NET MVC和其他所有依赖项,我必须自己完成。这就是我正在尝试做的事情。
我添加了一个对
C:\dev\Demo\ITConsole\artifacts\bin\ITConsole\Debug\dnx451\ITConsole.dll
的引用到我的单元测试项目中,以便我可以开始编译代码。单元测试类编译通过,但它们不运行,可能是因为试图添加对ASP.NET的引用而导致混乱。
现在,尽管我已经添加了对Common.Logging.Core和Common.Logging的引用,但当我在测试资源管理器上单击“运行全部”时,我收到以下错误:
Test Name: TestStudyLogReadDocument
Test FullName: ITConsoleTests.ITConsoleTestStudyLog.TestStudyLogReadDocument
Test Source: C:\dev\Demo\ITConsole\ITConsoleTests\ITConsoleTestStudyLog.cs : line 52
Test Outcome: Failed
Test Duration: 0:00:00.0712058
Result StackTrace:
at Couchbase.Configuration.Client.ClientConfiguration..ctor()
at ITConsole.Repository.StudyLogRepository..ctor() in C:\dev\Demo\ITConsole\src\ITConsole\Repository\StudyLogRepository.cs:line 39
at ITConsoleTests.ITConsoleTestStudyLog.SetupDb() in C:\dev\Demo\ITConsole\ITConsoleTests\ITConsoleTestStudyLog.cs:line 30
at ITConsoleTests.ITConsoleTestStudyLog.TestStudyLogReadDocument() in C:\dev\Demo\ITConsole\ITConsoleTests\ITConsoleTestStudyLog.cs:line 53
Result Message:
Test method ITConsoleTests.ITConsoleTestStudyLog.TestStudyLogReadDocument threw exception:
System.IO.FileLoadException: Could not load file or assembly 'Common.Logging.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
(在提出这个问题时...)ASP.NET 5 MVC预览模板都无法为您生成单元测试。您甚至可以对全新的ASP.NET Core应用程序进行单元测试吗?例如,如下屏幕截图所示,使用MSTEST在Visual Studio 2015中开始进行单元测试的常规方式不可用。