tags:

views:

704

answers:

4

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

This test works fine.

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

Simon Laroche
A: 

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?

Lucas Meijer
I'm using NUnit 2.4.8 and Moq.2.6.1014.1
Nathan W
The plot thickens. In a completely empty project the test passes for me as well. But when including it in an assembly with multiple other tests, it fails. <puts on sherlock holmes hat>
Lucas Meijer
Can you run the test by itself(in the assembly with multiple tests) and still it passes?
Nathan W
A: 

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

kzu
+3  A: 

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

Lucas Meijer