chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
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.
asked by fgerlach (1.2k points)

2 Answers

0 votes
Hi,

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.

Changing the access modifier of the abstract method to public makes the test pass.

This is a bug :twisted: , I guess that we create (emit) only public methods.
We will fix it and post the fix.
answered by scott (32k points)
0 votes
This has been fixed
answered by scott (32k points)
...