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 Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!
0 votes
I'm having difficulty writing DoInstead() on a protected method found in a base class. The design is much like the following:

public class A
{
    protected Method(obj o)
    {
    }
}

public class B : A
{
}


I'd like to write a new implementation of non-public B.Method(), so I tried this:

var fakeB = Isolate.Fake.Instance<B>(Members.CallOriginal);
Isolate.NonPublic.WhenCalled(fakeB, "Method").WithGenericArguments(typeof(object)).DoInstead((o) =>
{
});


I got an error about B.Method() not being found. Is this scneario supported?
asked by (18.2k points)

1 Answer

0 votes
Hi Jeff,

I think the error you get is because you add .WithGenericArguments - since it doesn't apply in this case.

Try the following:

var fakeB = Isolate.Fake.Instance<B>(Members.CallOriginal);
Isolate.NonPublic.WhenCalled(fakeB, "Method").DoInstead((o) =>
{
});
answered by (1.9k points)
...