I have two objects, object 1 is in C# and is what I am trying to test. However, it relies on object 2, which is C++ COM. Basically, the problem is a value that is coming from object 2 is wrong because of bad data, so I have code in the C# getter that calls through to the COM getter, and if it determines the data is wrong, it applies a few rules and updates the value in the COM object, and then returns. The code below is from the C# object, and this.Private is the COM object. The problem is
this.Private.Number = num;
does nothing.
public string Number
{
get
{
if (this.Private.Number.IndexOf("/") == -1)
{
string num = this.Private.Number;
// Apply some rules based on other stuff...
this.Private.Number = num;
}
return this.Private.Number;
}
}
So, my test looks like this:
[TestMethod]
public void TestNumber()
{
MockObject<TestObject> mock = MockManager.MockObject<TestObject>(); // The C# class with the method under test
MockObject<Private> mockPrivate = MockManager.MockObject<DOCUMENTLib>(); // The COM object
mockPrivate.ExpectGetAlways("Number", "12345");
mock.ExpectGetAlways("Private", mockPrivate.MockedInstance);
// Number should add the 01 to fix data issues
Assert.AreEqual("01/12345", mock.MockedInstance.Number);
}
Please don't ask why I am not using the AAA framework, that is not the point of this.