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
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 JeffFerguson (3.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 yoel (1.9k points)
...