Rhinos 无法加载文件或程序集 System.Core [英] Rhinos Could not load file or assembly System.Core
问题描述
我正在尝试一些用于 c# 的模拟框架.
I'm trying some mocking frameworks for c#.
我创建了一个 Windows Phone 8.1 项目,然后添加了一个 8.1 单元测试项目
I created an Windows Phone 8.1 project, then added an 8.1 Unit Test Project
安装了 nuget 软件包的 Rhinos.尝试进行简单的存根测试:
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()
问题出在哪里?
注意:我是 Visual Studio 和 Windows Phone 开发的初学者,所以请解释你的答案
Note: I'm starter with Visual Studio and Windows Phone development so please explain your answer
推荐答案
问题是因为您的 Windows Phone 8.1 测试项目无法引用 Windows Phone 8.1/Windows Runtime 不支持的任何内容;不幸的是,这包括您的模拟框架.
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.
我解决这个问题的方法是将我所有的单元可测试代码移动到一个可移植的类库中,然后我可以从 Windows Phone 项目中引用它.然后,创建一个正常的单元测试项目,该项目在引用您的可移植类库和您选择的模拟框架时没有问题.
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.
这篇关于Rhinos 无法加载文件或程序集 System.Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!