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
WillReturnCollectionValuesOf returns stack overflow when messing with based class and inherited class.

Here's the production code:
    public interface IViewTest<T> where T: SimpleClass
    {
         IList<T> SelectedMember { get; } 
    }

    public class MyPresenter<T> where T: SimpleClass
    {
        public IViewTest<T> MyView
        {
            get;
            private set;
        }

        public void JustLoop()
        {
            foreach (SimpleClass sc in MyView.SelectedMember)
            {
            }
        }
    }

    public class DerivedSimpleClass: SimpleClass
    {

    }
    public abstract class SimpleClass
    {
        public string ID
        {
            get;
            set;
        }

        public string Node
        {

            get
            {
                throw new NotImplementedException();
            }
        }
    }


Here's the test code:
        [Test, Isolated]
        public void JustLoopTest()
        {
            MyPresenter<DerivedSimpleClass> presenter = Isolate.Fake.Instance<MyPresenter<DerivedSimpleClass>>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => presenter.MyView).WillReturn(Isolate.Fake.Instance<IViewTest<DerivedSimpleClass>>(Members.ReturnRecursiveFakes));
            Isolate.WhenCalled(() => presenter.MyView.SelectedMember).WillReturnCollectionValuesOf(new List<SimpleClass>
                {
                    Isolate.Fake.Instance<DerivedSimpleClass>(Members.ReturnRecursiveFakes)
                });
            Isolate.WhenCalled(() => presenter.JustLoop()).CallOriginal();
            presenter.JustLoop();

        }


Stack Overflow exception gets thrown on the line
           foreach (SimpleClass sc in MyView.SelectedMember)
            {
            }


Not sure whether it is related to the previous issue or not, hopefully you can have a test on this :)
________
marijuana news
asked by nsoonhui (59.1k points)

4 Answers

0 votes
Hi Soon Hui,

Thanks as always for a succinct and complete walkthrough of a bug recreation; I can indeed recreate the behavior you are experiencing. I am trying to track down the root cause and suggest a workaround.

Thanks,
Doron
Typemock support
answered by doron (16.5k points)
0 votes
This problem is not solved yet in TypeMock 5.1.2... when can I get a patch for this? Thanks.
________
vaporizer store
answered by nsoonhui (59.1k points)
0 votes
Hi,

Currently we are working on a fix for this issue - I will let you know when we have a patch that fixes it.
answered by dhelper (11.9k points)
0 votes
Hi Soon Hui,

Looking further into this it seems like you are trying to swap a collection of DerivedSimpleClass with a collection of SimpleClass:

Isolate.WhenCalled(() => presenter.MyView.SelectedMember).
   WillReturnCollectionValuesOf(new List<SimpleClass> 
   {
      Isolate.Fake.Instance<DerivedSimpleClass>(Members.ReturnRecursiveFakes) 
   }); 


SelectedMember is an IList<DerivedSimpleClass>, and you are trying to return a collection of the base class in its place - that sort of generalization is not valid, therefor the exception. The issue we need to fix is to catch the exception and provide a readable error message instead.

In order to fix the test you can do one of the following:
Isolate.WhenCalled(() => presenter.MyView.SelectedMember).WillReturn(new[]{Isolate.Fake.Instance<DerivedSimpleClass>(Members.ReturnRecursiveFakes)});

Isolate.WhenCalled(() => presenter.MyView.SelectedMember).WillReturn(new List<DerivedSimpleClass>(){Isolate.Fake.Instance<DerivedSimpleClass>(Members.ReturnRecursiveFakes)});


Thanks,
Doron
Typemock support
answered by doron (16.5k points)
...