I have this abstract class, that I want to test. I want to ensure that when SomeMethod
is invoked, ValidateStronglyTypedData
is called.
public abstract class SomeAbstractClass<TDataType> where TDataType : class
{
public ResultType SomeMethod(string someParam)
{
TDataType tDataType = convert(someParam);
this.ValidateStronglyTypedData(tDataType);
}
protected abstract ResultType ValidateStronglyTypedData(TDataType stronglyTypedData);
}
I've got this:
// Arrange
var mockSomeAbstractClass = new Mock<SomeAbstractClass<TestJsonDataType>>();
var testData = "{ 'testProperty': 'test value' }";
mockSomeAbstractClass.Protected().Setup<ValidationResult>("ValidateStronglyTypedData", It.IsAny<TestJsonDataType>());
// Act
mockSomeAbstractClass.Object.ValidateData(testData);
// Assert
mockSomeAbstractClass.Protected().Verify("ValidateStronglyTypedData", Times.Once(), It.IsAny<TestJsonDataType>());
but at runtime it complains that it cannot find the method. Is it because the protected method is abstract? It fails on the setup with:
System.ArgumentException: 'Use ItExpr.IsNull rather than a null argument value, as it prevents proper method lookup.'
I have tried ItExpr
and still doesn't work. I am guessing it has to do with the class being generic.