1

I am trying to use the c# mock callback for setting a value to a parameter that is a ref.

My code is something like that:

    delegate void FooCallback(string p1, string p2, string p3, ref string p4, ref string p5, ref string p6, object p7);

    public void TestMethod()
    {
        var parm1 = string.Empty;
        var parm2 = string.Empty;
        var parm3 = string.Empty;
        var CallbackFunction = new FooCallback((string p1, string p2, string p3, ref string p4, ref string p5, ref string p6, object p7) => p5 = "value");
        SomeServiceMock.Setup(x =>x.Foo(It.IsAny<string>(),
                It.IsAny<string>(), It.IsAny<string>(), ref parm1, ref parm2, ref parm3,
                It.IsAny<object>())).Callback(CallbackFunction);
    }

But I get a compilation error saying that the Callback function can get only a parameter of type Action, and I can't just use Action because of the ref(or can I?) so how can I change the value of p5 when Foo is called?

I already tried everything from here

Avner Huri
  • 111
  • 2
  • 8

1 Answers1

0

I managed to solve the problem by upgrading my Moq package from 4.2 to 4.15

Avner Huri
  • 111
  • 2
  • 8