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
Here's the test code:
    public  class MyBase
    {
        public double FirstNumber
        { get; set; }
        public MyBase()
        {
            FirstNumber = 10; }
    }

   public class SimpleView
    {
        public IList<MyBase> MyInt
        { get; set; }
    }


Here's the test code:
        [Test, Isolated]
        public void SimpleViewTest()
        {
            SimpleView sv = Isolate.Fake.Instance<SimpleView>(Members.ReturnRecursiveFakes);
            sv.MyInt.Add(Isolate.Fake.Instance<MyBase>(Members.ReturnRecursiveFakes));
            Isolate.WhenCalled(()=>sv.MyInt[0].FirstNumber).WillReturn(2.0);
            foreach (var VARIABLE in sv.MyInt)
            {
                
            }
            
        }


If you run it using TestDriven.Net runner, you will get a StackOverflowException and the runner will exit.
________
Fisting French
asked by nsoonhui (59.1k points)

2 Answers

0 votes
This is indeed a bug.
But even if the test code would work you'll have to remember that calling "Add" method won't do anything because sv was create using recursive fakes.
tip: in Isolator 5.2.0 Recursive Fakes is the default behavior.
Instead of using WillReturn use WillReturnCollectionValueOf that is intended for what you need:
        [Test, Isolated]
        public void SimpleViewTestOld()
        {
            SimpleView sv = Isolate.Fake.Instance<SimpleView>(Members.ReturnRecursiveFakes);

            var instance = Isolate.Fake.Instance<MyBase>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => instance.FirstNumber).WillReturn(2.0);
            Isolate.WhenCalled(() => sv.MyInt).WillReturnCollectionValuesOf(
                new List<MyBase>
                {
                    instance
                });

            foreach (var VARIABLE in sv.MyInt)
            {

            }
        }
answered by dhelper (11.9k points)
0 votes
This is indeed a bug.
But even if the test code would work you'll have to remember that calling "Add" method won't do anything because sv was create using recursive fakes.
tip: in Isolator 5.2.0 Recursive Fakes is the default behavior.
Instead of using WillReturn use WillReturnCollectionValueOf that is intended for what you need:
        [Test, Isolated]
        public void SimpleViewTestOld()
        {
            SimpleView sv = Isolate.Fake.Instance<SimpleView>(Members.ReturnRecursiveFakes);

            var instance = Isolate.Fake.Instance<MyBase>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => instance.FirstNumber).WillReturn(2.0);
            Isolate.WhenCalled(() => sv.MyInt).WillReturnCollectionValuesOf(
                new List<MyBase>
                {
                    instance
                });

            foreach (var VARIABLE in sv.MyInt)
            {

            }
        }


Thanks Dror, I realized that my code is not valid anyway, just that TestDriven.net shouldn't crash even when my code is invalid.

And your solution was the one that I adopted, thanks for your prompt response. :D
________
Ipad Guide
answered by nsoonhui (59.1k points)
...