Lucas Meijer
Lucas Meijer

Reputation: 4484

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

Upvotes: 2

Views: 1266

Answers (4)

Lucas Meijer
Lucas Meijer

Reputation: 4484

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

Upvotes: 4

kzu
kzu

Reputation: 1871

This doesn't repro with the latest version from the trunk (3.0 beta)

Upvotes: 0

Lucas Meijer
Lucas Meijer

Reputation: 4484

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?

Upvotes: 0

Simon Laroche
Simon Laroche

Reputation: 542

This test works fine.

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

Upvotes: 0

Related Questions