I have this class called Table:
class Table { public string Name { get { return this.wrapper.Eval(//some command); //wrapper is pass in by the ctor and is a COM object. } } }
which is used in this class:
class Map { public Map MapTable(Table table) { return new Map(table.Name); } }
I want to test MapTable command, should I be mocking Table or should I mock the wrapper object that is used by the table object.
I was thinking something like this
Test() { Mock<ITable> mocktable = new Mock<ITable>(//pass in the wrapper object); mocktable.ExpectGet(n => n.Name).Returns('Hello World'); ITable table = mocktable.object; Map mymap = Map.MapTable(table); }
Would that be correct?
Beyond the fact that there is usually no one perfect testing solution, I’d first go for mocking the COM object: there should be a interface available and you’ll probably want to test everything ‘above’ it.
If the
Tablecontains non-trivial code (e.g. within theEval(); anything with conditionals; or e.g. parsing using aCulture) you might want to have a mock of it as you show in your example.