954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

unit testing using moq - verify does'n work

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 iRectangleMock = new Mock();

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

surajrai
Newbie Poster
16 posts since May 2010
Reputation Points: 10
Solved Threads: 1
 

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

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: