访问模拟对象时,找不到moq文件异常system.xml(moq file not found exception system.xml when accessing the mocked objec

编程入门 行业动态 更新时间:2024-10-12 01:25:43
访问模拟对象时,找不到moq文件异常system.xml(moq file not found exception system.xml when accessing the mocked object)

我收到此代码的文件未找到异常:(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(); } } }

更多推荐

本文发布于:2023-08-07 10:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   异常   对象   文件   moq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!