开发者

moq file not found exception system.xml when accessing the mocked object

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 n开发者_开发百科icht 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.


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();
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜