问题
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