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
Members.ReturnRecursiveFakes are not faking private members.

Here's my production code:
    public class AnObject
    {
        public void DoNothing()
        {

        }
    }

    public class AnWrapperObject
    {
        private AnObject objAn;
        public void CallDoNothing()
        {
            objAn.DoNothing();
        }
    }


here's my test code
    [TestFixture]
    public class TestClass
    {
        public void Test1()
        {
            AnWrapperObject wrappObj = Isolate.Fake.Instance<AnWrapperObject>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => wrappObj.CallDoNothing()).CallOriginal();
            wrappObj.CallDoNothing();
        }
    }


And here's the exception:
TestCase 'TestClass.Test1' failed: Object reference not set to an instance of an object.
   System.NullReferenceException: Object reference not set to an instance of an object.


If I changed the line
private AnObject objAn;


to
public AnObject objAn
{
get;
private set;
}

then there is no such problem.
________
medical marijuana
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi,

This is indeed a behavior that is not covered in AAA. After discussing this with the team it looks like this is something we want in recursive fakes - make their fields recursive fakes as well. We will work on making this work on an upcoming release. For the time being the workaround I can suggest is the same one you came up with - access a property instead of the field.

Thanks,
Doron
Typemock Development
answered by doron (17.2k points)
...