Moq'ing interface

While I was searching / reading this answer, I thought that I would also ask here.

I have a class that is a wrapper for the SDK. The class takes an ILoader and uses an ILoader to create an ISBAObject, which is passed to the ISmallBusinessInstance. I'm just trying to make fun of this behavior with Moq.

   [TestMethod]
    public void Test_Customer_GetByID()
    {
        var mock = new Mock<ILoader>();

        var sbainst = new Mock<ISbaObjects>();

        mock.Expect(x => x.GetSbaObjects("")).Returns(sbainst);


    }

Compiler Error: Error 1 The best overloaded method matching for "Moq.Language.IReturns.Returns (Microsoft.BusinessSolutions.SmallBusinessAccounting.Loader.ISbaObjects)" contains some invalid arguments

What's going on here? I expected that the Mock from ISbaObjects could be returned without problems.

+3
source share
2 answers

sbainst.Object, sbinst ISbaObjects - .

+8

,

[TestMethod]
public void Test_Customer_GetByID()
{
    var mock = new Mock<ILoader>();

    var sbainst = new Mock<ISbaObjects>();

    mock.Expect(x => x.GetSbaObjects("")).Returns(sbainst.Object);


}
+2

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


All Articles