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
It seems that object returned from recursive fake operation is not recursive fake, by design?

Here's the production code
    public class Layer
    {
        public List<string> Names
        {
            get;
            set;
        }

    }

    public class BaseClass
    {
        public Layer GetLayers
        {
            get
            {
                Layer ly = new Layer();
                ly.Names = new List<string>();
                return ly;
            }
        }
    }

    public class WrapperClass
    {
        public BaseClass InstanceObj
        {
            get;
            private set;
        }
    }


And here's the test code, note that this test will fail
       [Test, Isolated]
        public void WrapperLayer()
        {
            WrapperClass wc = Isolate.Fake.Instance<WrapperClass>(Members.ReturnRecursiveFakes);
            Layer ly = wc.InstanceObj.GetLayers;
            Assert.IsNotNull(ly.Names);
        }


I do think that ly.Names should be a fake object instead of a null, though.
________
herbalaire
asked by nsoonhui (59.1k points)

4 Answers

0 votes
This test will also fail:
        [Test, Isolated]
        public void WrapperLayer()
        {
            WrapperClass wc = Isolate.Fake.Instance<WrapperClass>(Members.ReturnRecursiveFakes);
            Assert.IsNotNull(wc.InstanceObj.GetLayers.Names);
        }

________
growing marijuana
answered by nsoonhui (59.1k points)
0 votes
Hi,
As you probably know the Isolator cant handle classes from MSCorlib.
In this case "Names" returns a List<String> which cant be mocked
therefore i guess it returns a null instead.
answered by error (6.6k points)
0 votes
Error is correct (thanks!) - we don't (yet) support faking MSCorLib objects. The treatment for methods returning an object we can't fake is not to fake the method.

A workaround would be to refactor to return an IList<string> which can be faked and use a backing field instead of the auto-property.

Hope this helps,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
This should work (set the Names property to a real list)
[Test, Isolated]
public void WrapperLayer()
{
   WrapperClass wc = Isolate.Fake.Instance<WrapperClass>(Members.ReturnRecursiveFakes);
   wc.InstanceObj.GetLayers.Names = new List<string>(){ "item1","item2"};

   Assert.IsNotNull(ly.Names);
}
answered by eli (5.7k points)
...