Rhinos Could not load file or assembly System.Core

[亡魂溺海] 提交于 2020-01-17 08:47:07

问题


I'm trying some mocking frameworks for c#.

I created an Windows Phone 8.1 project, then added an 8.1 Unit Test Project

Installed Rhinos with the nuget package installed. Trying to make an simple stub test:

public class MyTest
{
    public int value()
    {
        return 23;
    }
}

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {

        MyTest item;
        item = MockRepository.GenerateStub<MyTest>();
        item.Stub(x => x.value()).Return(240);
        Assert.Equals(239, item.value());
    }
}

But when I run the tests I get the following error:

Result Message: Test method UnitTestApp1.UnitTest1.TestMethod1 threw exception: 
System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
Result StackTrace:  
at Rhino.Mocks.MockRepository.GenerateStub[T](Object[] argumentsForConstructor)
   at UnitTestApp1.UnitTest1.TestMethod1()

Where is the problem?

Note: I'm starter with Visual Studio and Windows Phone development so please explain your answer


回答1:


The problem is because your Windows Phone 8.1 test project can't reference anything that isn't supported by Windows Phone 8.1/Windows Runtime; unfortunately, this includes your mocking framework.

The way I solve this problem is to move all of my unit testable code into a portable class library which I can then reference from the Windows Phone project. Then, create a normal unit test project which will have no problem referencing your portable class library and your mocking framework of choice.



来源:https://stackoverflow.com/questions/28645092/rhinos-could-not-load-file-or-assembly-system-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!