Moq: checking a method called with a specific delegate causes a "method argument length mismatch",

I have a class Athat calls a method on an interface B, passing one of its own methods to it as a kind of continuation, which Bshould be called when it has a result. In practice, this code works fine, but I can't figure out how to test it with Moq - when I try to do the obvious thing, it creates System.ArgumentException : method argument length mismatch. At first I thought that it could be my code, but it does not work the same way as in the following case:

public class A
{
    readonly B myB;

    public A (B b)
    {
        myB = b;
    }

    public void HandleC (C c)
    {
        // do something
    }

    public void DoFindC ()
    {
        myB.FindC (HandleC);
    }
}

public interface B
{
    // Finds a C and then passes it to handleC
    void FindC (Action<C> handleC);
}

public interface C
{
}

[TestFixture()]
public class ATest
{
    [Test()]
    public void TestDoFindC ()
    {
        Mock<B> bMock = new Mock<B> ();
        A a = new A(bMock.Object);
        a.DoFindC();

        bMock.Verify(b => b.FindC(a.HandleC));
    }
}

I guess there are some backstage magic with delegates that I don't understand yet, being relatively new to C #, but what's the right way to check this out?


:. Mono 2.6.7 MacOS 10.6.5 .NET 3.5.


: , Mono; https://bugzilla.novell.com/show_bug.cgi?id=656918.

0

Source: https://habr.com/ru/post/1661056/


All Articles