简体   繁体   中英

Why does this NUnit+Moq test fail?

I hope you know, because I don't see it. Bonus points for whoever figures out how one can achieve what this test is trying to achieve.

using NUnit.Framework;
using Moq;

[TestFixture]
public class MoqHuh
{
    public class A {}
    public class B : A {}

    public interface IHelper
    {
        void DoIt(A a);
    }

    [Test]
    public void Huh()
    {
        var mock = new Mock<IHelper>();
        mock.Expect(helper => helper.DoIt(It.IsAny<B>())).Verifiable();

        mock.Object.DoIt(new B());

        mock.VerifyAll();
    }
}

Turns out this was sort of pilot error. I incorrectly assumed Moq working fine on Mono. (which it looks like it does just fine). This issue only happens when compiled with mono's gmcs, not when compiled with Microsofts csc.

I have reported the appropriate bugs with the mono team, and will continue towards making sure the full Moq test suite passes when compiled with mono's gmcs.exe

Sorry for the noise.

Lucas

This test works fine.

Since there is no system under test, you are testing that moq works as expected.

Sorry for not being clear enough. What I am testing is indeed that the Mock behaves as I would expect. For me the test above fails. I'm very surprised to hear it passes for you. I'm running the test in VisualStudio 2008. I just upgraded to Moq 2.6, and the test still fails. What version of Moq do you use with which this test passes?

从主干(3.0 beta)的最新版本无法复制

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM