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
Here's the production code
    public class FSlab
    {
        public List<int> myInts
        { get; private set; }

        public double Depth
        {
            get
            {
                return 0;
            }
        }
        public FSlab(List<int> intList)
        {
            myInts = intList;
        }
    }

    public class FPad
    {
        public FSlab fSlab
        { get; private set; }
        public FPad(List<int> intList)
        {
            fSlab=new FSlab(intList);
        }
    }


And here's the test code:
        [Test]
        public void NullForNoReason()
        {


            var fp = new FPad(new List<int>());
            Isolate.WhenCalled(() => fp.fSlab.Depth).WillReturn(450);
            Assert.IsNotNull(fp.fSlab.myInts);

        }


You will find that the above test fails at Assert.IsNotNull.

But if I disable the Isolate.WhenCalled then I won't have such a problem.
________
Motorcycle Tires
asked by nsoonhui (59.1k points)

4 Answers

0 votes
Hi Soon Hui,

This seems like a bug :shock: - the live object handling (putting a real instance inside a WhenCalled) is turning objects along the chain to recursive fakes, and the property returning a List cannot be faked (because it's in mscorlib) so it returns null.

Changing the property type to IEnumerable<int> or ICollection<int> would solve this issue as a work around. I will log this bug to be fixed for an upcoming version.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Soon Hui,

Another work around I just thought of and you might want to try - extract the offending chain outside the WhenCalled() statement:
var fp = new FPad(new List<int>()); 
var slab = fp.Slab;
Isolate.WhenCalled(() => slab.Depth).WillReturn(450); 


Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
doron,

I think the problem here is even more subtle than you thought; I change the List to IEnumerable, and yet still the same problem occurs.

Here's the complete production code
    public class FSlab
    {
        public IEnumerable<int> myInts
        { get; private set; }

        public double Depth
        {
            get
            {
                return 0;
            }
        }
        public FSlab(List<int> intList)
        {
            myInts = intList;
        }
    }

    public class FPad
    {
        public FSlab fSlab
        { get; private set; }
        public FPad(List<int> intList)
        {
            fSlab=new FSlab(intList);
        }
    }

________
Relationship forum
answered by nsoonhui (59.1k points)
0 votes
Hi Soon Hui,

You're correct, it is a different bug. It builds the recursive fake incorrectly. This bug is exposed because of incorrect behavior set in the chain.

We'll let you know when this bug is fixed.

Best Regards,
Elisha
Typemock Support
answered by Elisha (12k points)
...