I have been working on a wrapper for a COM object that can only take and return strings. The interface for the COM object looks like this:
interface IMapinfo
{
void Do(string cmd);
string Eval(string cmd);
}
Now I have made classes that wrap up basic functions like so:
public class Table
{
IMapinfo MI;
public string Name
{
//pass the command to the COM object and get back the name.
get{return MI.Eval("TableInfo(1,1")");}
}
}
Now I would like to do unit testing on these classes without having to create the real COM object every time,set up the world then run the tests. So I have been looking into using mock objects but I am a little bit confused on how I would use mocking in this situation.
I am planning on using Moq, so I have written this test like this:
[Test]
public void MockMapinfo()
{
Moq.Mock<Table> MockTable = new Moq.Mock<Table>();
MockTable.ExpectGet(n => n.Name)
.Returns("Water_Mains");
Table table = MockTable.Object;
var tablename = table.Name;
Assert.AreEqual("Water_Mains", tablename,string.Format("tablename is {0}",tablename));
Table d = new Table();
}
Is this the correct way to mock my COM object? How does this verity that the string getting sent to the eval function is correct? or am I doing it all wrong?