Hi,
I'm not sure if this is really a bug, might as well be a misunderstanding, but it seems quite strange to me.
When I try to use MockObject() on an abstract class that contains a protected abstract method, I get this failure message:
TestCase 'Sandbox.MyAbstractClassTestFixture.AbstractMethod' failed: System.TypeLoadException : Method AbstractMethod in type MockMyAbstractClass from assembly AbstractMethod does not have an implementation.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(TypeToken handle, Module module)
at System.Reflection.Emit.TypeBuilder.CreateType()
at TypeMock.s.b(Type A_0)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.MockObject(Type type, Object[] args)
c:mydocsisual studio projectssandboxmyabstractclasstestfixture.cs(15,0): at Sandbox.MyAbstractClassTestFixture.AbstractMethod()
Example code:
public abstract class MyAbstractClass
{
protected abstract void AbstractMethod();
}
[TestFixture]
public class MyAbstractClassTestFixture
{
[Test]
public void ConcreteMethod()
{
MockManager.Init();
MockObject mockObj = MockManager.MockObject(typeof(MyAbstractClass));
MyAbstractClass mac = (MyAbstractClass)mockObj.Object;
MockManager.Verify();
}
}
Changing the access modifier of the abstract method to public makes the test pass.
If this is intended I'd really appreciate an explanation, since I just can't think of a reason I should not be allowed to mock protected abstract methods.