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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I have the following classes:
public class MyBase
{
    public virtual int DoMe()
    {
       return 10;
    }
}

public class MyDerived:MyBase
{
    public override int DoMe()
    {
       int meBased =base.DoMe(); //u need to find a way to mock this statement;
      return meBased+1;
    }
}


Given a mock instance of MyDerived, the question is how can I mock the base class of MyDerived? This is because in my derived method, I need to take the value returned from the base class and perform additional manipulation. How to mock whatever so that the following test passes:
public void DoMe100()
{
    MyDerived myDerived = Isolate.Fake.Instance<MyDerived>(Members.CallOriginal);
//mock anything to make sure the test passes here
   Assert.AreEqual(100, myDerived. DoMe()); 
}

________
YAMAHA DSP-1
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Unfortunately this feature is not yet implemented in AAA API.
Instead you can use older API to set behavior on base class:
[Test]
public void BaseClassMockTest()
{
    Mock mock = MockManager.Mock(typeof (MyDerived));
    mock.CallBase.ExpectAndReturn("DoMe", 99);

   var myDerived = new MyDerived();
   Assert.AreEqual(100, myDerived.DoMe()); 
}
answered by dhelper (11.9k points)
...