我收到此代码的文件未找到异常:(System.IO.FileNotFoundException:Die Datei oder Assembly“System.Xml,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e”odereineAbhängigkeitavonwurde nicht gefunden。 Das System kann die angegebene Datei nicht finden。)
public interface ISocket { int Receive(byte[] buffer); } [Test] public void ShouldMock() { var Mock = new Mock<ISocket>(); ToBeTested Example = new ToBeTested ((ISocket)Mock.Object); }我找不到我的错误,在任何情况下我都没有引用过system.xml。 什么可能出错?
编辑:
我从来没有解决这个问题,我仍然坚持手工嘲笑。 我再次尝试设置一个使用moq但又失败的项目。 以下是一些具有相同运行时错误消息的其他代码:
[Test] public void shouldLoadContextBasedOn_Type_AfterGettingContextDictionary() { Type loadableType = typeof(Context_Empty); var mocklib= new Mock<IDictionary<Type, Type>>(); mocklib.SetupGet(lib => lib[loadableType]).Returns(loadableType); ContextLoader tested = new ContextLoader(); tested.setContextKnowledge(mocklib.Object); tested.loadContext(loadableType); IContextBase expected = new mockContext(); IContextBase actual = tested.getCurrentContext(); mocklib.VerifyGet( lib => lib[typeof(Context_Empty)]); Assert.AreEqual(expected.ToString(), actual.ToString()); }堆栈托盘显示moq在杀死自己之前正在寻找它的来源 - 是吗? 它实际上只有在d:\ Code \ moq \ src \ Source下安装源时才有效吗? 这似乎并不严谨。 (编辑:amd它不是 - nunit只是通知我,我找不到文件,所以与错误无关)
我有合适的套餐吗? 我选择了silverligth4,我正在使用我在那里找到的两个dll - 其他的都没有用,因为有些东西丢失了。
编辑:
为了说明问题更加尖锐。 hiere是另一段失败的代码:
[Test] public void mockDemo() { var crappy = new Mock<IDisposable>(); IDisposable instance = crappy.Object; //Runtime Error }这里是堆栈跟踪 - 手动重写,可能会发生打字错误
ContextLoader_Spec mockDemo() Mock1 get_Object() Mock1 OnGetObject() Mock1 InitialiseInstance() PexProtector Invoke() Mock1 <InitializeInstance>b_32() ProxyGenerator CreateInterfaceProxyWithoutTarget() DefaultProxyBuilder CreateInterfaceProxyTypeWithoutTarget() InterfaceProxyWithTargetGenerator GenerateCode() InterfaceProxyWithoutTargetGenerator GenerateType() InterfaceProxyWithTargetGenerator Init() InterfaceProxyWithTargetGenerator CreateFields()我不知道为什么会发生这种异常。
编辑:这似乎是一个已知问题与Silverver4编辑:与其他版本NET35 / NET40 / NET40Castle / Silverlight4重试 - 都显示相同的错误。
I am getting a file not found exception for this code: (System.IO.FileNotFoundException : Die Datei oder Assembly "System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.)
public interface ISocket { int Receive(byte[] buffer); } [Test] public void ShouldMock() { var Mock = new Mock<ISocket>(); ToBeTested Example = new ToBeTested ((ISocket)Mock.Object); }I can not find my error and in no case i ever referenced a system.xml. What could have gone wrong?
EDIT:
I did never solve this problem and i am still stuck with manual mocking. I tried once again to set up a project that uses moq but failed again. Here is some other code with the same runtime error message:
[Test] public void shouldLoadContextBasedOn_Type_AfterGettingContextDictionary() { Type loadableType = typeof(Context_Empty); var mocklib= new Mock<IDictionary<Type, Type>>(); mocklib.SetupGet(lib => lib[loadableType]).Returns(loadableType); ContextLoader tested = new ContextLoader(); tested.setContextKnowledge(mocklib.Object); tested.loadContext(loadableType); IContextBase expected = new mockContext(); IContextBase actual = tested.getCurrentContext(); mocklib.VerifyGet( lib => lib[typeof(Context_Empty)]); Assert.AreEqual(expected.ToString(), actual.ToString()); }The stacktray shows that moq is looking for its source before killing itself - is that it? Does it actually only work if i have the source installed under d:\Code\moq\src\Source ? This does not seem rigth. (EDIT: amd it wasnt - nunit just informed me that i can not find the files, so nothing to do with the error)
Do i have the right package? I chose silverligth4 and i am using both dlls i found in there - the others did not work because something was missing.
EDIT:
To illustrate the problem even sharper. hiere is another failing piece of code:
[Test] public void mockDemo() { var crappy = new Mock<IDisposable>(); IDisposable instance = crappy.Object; //Runtime Error }And here isthe stacktrace - manual rewritten, typingerror may occur
ContextLoader_Spec mockDemo() Mock1 get_Object() Mock1 OnGetObject() Mock1 InitialiseInstance() PexProtector Invoke() Mock1 <InitializeInstance>b_32() ProxyGenerator CreateInterfaceProxyWithoutTarget() DefaultProxyBuilder CreateInterfaceProxyTypeWithoutTarget() InterfaceProxyWithTargetGenerator GenerateCode() InterfaceProxyWithoutTargetGenerator GenerateType() InterfaceProxyWithTargetGenerator Init() InterfaceProxyWithTargetGenerator CreateFields()I dont know why this exception happens.
EDIT: This seems to be a known issue withSilverlight4 EDIT: Retried with the other versions NET35/NET40/NET40Castle/Silverlight4 - all show the same error.
最满意答案
切换到Rhino就像一个魅力。 Rhino可以单独下载,也可以在你的nunit testframework的lib文件夹中。
您所要做的就是将项目属性从.Net客户端配置文件切换到纯.Net配置文件,您就可以了。
这是一个Testsnippet,可以帮助您控制是否已经完成它。
using System; using NUnit.Framework; using Rhino.Mocks; namespace Test.selftest { [TestFixture] class Framework_Test { [Test] public void ShouldCompileAndExecuteASimpleNUnitTest() { Assert.IsTrue(true); } [Test] public void ShouldVerifyRhinoMock() { ICloneable mock = MockRepository.GenerateMock<ICloneable>(); mock.Expect(x => x.Clone()).Return(new Object()).Repeat.Times(1); mock.Clone(); mock.VerifyAllExpectations(); } } }Switching to Rhino works like a charm. Rhino can be downloadad seperately or is in the lib folder of your nunit testframework.
All you have to do is switch your project properties from the .Net Client profile to the pure .Net Profile and you are good to go.
Here is a Testsnippet that helps you control if you have done it.
using System; using NUnit.Framework; using Rhino.Mocks; namespace Test.selftest { [TestFixture] class Framework_Test { [Test] public void ShouldCompileAndExecuteASimpleNUnitTest() { Assert.IsTrue(true); } [Test] public void ShouldVerifyRhinoMock() { ICloneable mock = MockRepository.GenerateMock<ICloneable>(); mock.Expect(x => x.Clone()).Return(new Object()).Repeat.Times(1); mock.Clone(); mock.VerifyAllExpectations(); } } }更多推荐
发布评论