0

I have a method that returns void.

say:

Public void CreateRectangle(double z, double y, IRectangle rectObj)
{
    Vector3d recPos1 = new Vector3d()
    recPos1.X = 0;
    recPos1.Y = some double vale;

    Vector3d recPos2 = new Vector3d()
    recPos2.X = some double value;
    recPos2.Y = 0;

    rectObj.SetVectors(recPos1, recPos2);
}

now, in my unit test i just want to verify that SetVectors() method has been called on object rectObj.

I have written a moq unit test but it fails. My method looks like this:

[Test(Description = "")]
    public void TestCreateRectangle()
{

    double xPos = default(double);
        double yPos = default(double);

    myClass objMyClass = new myClass();
    Mock<IRectangle> iRectangleMock = new Mock<IRectangle>();

        Vector3d recPos1 = new Vector3d();
        recPos1.X = 9;
        recPos1.Y = 0;

        Vector3d recPos2 = new Vector3d();
        recPos2.X = 9;
        recPos2.Y = 0;

        iRectangleMock.Setup(x => x.SetVectors(recPos1, recPos2)).Verifiable();
        objMyClass.CreateRectangle(xPos, yPos, iRectangleMock.Object);

        iRectangleObjectMock.Verify(x => x.SetVectors(recPos1, recPos2));

}

error: it says - Expected invocation on the mock at least once, but was never performed: x => x.SetVectors(...

Thanks
Regard

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by thines01
0

Does it actually matter that SetVectors() is called or that the IRectangle has the expected (valid) values?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.