Class:
* BaseClass is an Abstract Class.
class DerivedClass : BaseClass
{
protected override void MethodA(List<ClassX> exceptionIds)
{
if(string.IsNullOrEmpty(this.PropertyX))
{
exceptionIds.Add(new ClassX("SignatureToMatch");
}
else
{
exceptionIds.Add(new ClassX("DifferentSignature");
}
base.MethodA(exceptionIds);
}
}
Test Class:
class DerivedClassTest
{
[TestMethod(), VerifyMocks()]
public void MethodATest()
{
MockObject mockObject = MockManager.MockObject<DerivedClass>();
DerivedClass target = (DerivedClass)mockObject.Object;
mockObject.ExpectGetAlways("PropertyX", string.Empty);
List<ClassX> exceptionIds = new List<ClassX>();
exceptionIds.Add(new ClassX("SignatureToMatch"));
mockObject.CallBase.ExpectCall("MethodA").Args(TypeMock.Check.IsSame(exceptionIds));
target.PublicAccessorMethodForMethodA();
}
}
*TypeMock.Check.IsEqual fails too, as both are different instances.
When I try to mock the base class with following code,
'mockObject.CallBase.ExpectCall("MethodA").When(exceptions);'
and I debug the test, I see that the call to base class mathod 'MethodA' is surrounded by a maroon rectangle, which usually is a sign for a codeblock to be mocked. But, in this case the execution flows as normal and the code block for BaseClass's 'MethodA' is not mocked. Also, in this case, arguments are not varified. in other words, call to the baseclass method is made (and not mocked) whether the passed argument is correct or not.
If arguments are not verified, i.e. 'mockObject.CallBase.ExpectCall("MethodA")' mocks the base class call successfully. After appending '.Args(TypeMock.Check.IsSame(exceptionIds));', test fails with the exception
TypeMock.VerifyException:
TypeMock Verification: Call to BaseClass.MethodA() Parameter: 1
passed object [System.Collections.Generic.List`1[ClassX]] is not the same as expected [System.Collections.Generic.List`1[ClassX]].
P.S.: I wonder whether we can mock BaseClass calls using NaturalMocks.
Note: I have found work around for this situation, but I might encounter such situation in future and wanted to report this to TypeMock.