TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Suraj Rai
NA
111
0
Unit testing using moq - verify does'n work
Feb 16 2012 12:15 AM
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(...
Reply
Answers (
0
)
How to crop an image that is zoomed(zoomed in/out)
CAD tool development using c#