I'm having a bit of trouble doing some unit-testing using moq.
If I have a function like this:
public string GetName(IMapinfoWrapper wrapper)
{
return wrapper.Evaluate("My com command");
///"My comm command" is the same all the time.
}
Then I have a test that checks the return value of the GetName function:
[Test]
public void Test()
{
Mock<IMapinfoWrapper> mock = new Mock<IMapinfoWrapper>();
mock.Expect(mapinfo => mapinfo.Evaluate(It.IsAny<String>()))
.Returns("TableName");
Assert.AreEqual("TableName", GetName(mock.object));
}
So my question is should the mock be define like this:
mock.Expect(mapinfo => mapinfo.Evaluate(It.IsAny<String>()))
.Returns("TableName");
or like this:
mock.Expect(mapinfo => mapinfo.Evaluate("My com command")
.Returns("TableName");
My only problem with using the second way is that I feel like I'm tying the implementation of the method GetName to always use the "My com command" string internally.
Is this what I should be doing or am I doing this all wrong.?
I have only started doing unit-testing and mocking so I'm still not sure how everything should go together.