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
IgnoreCall applied on a real object will will result in Weird Typemock exception.

Here's the production code
    class MoreBaseClass
    {
        public int Counter
        {
            get;
            set;
        }

        public int ReturnCount()
        {
            return Counter;
        }
    }
    class  NoThink
    {


        public MoreBaseClass DoWhat(int issd)
        {
            return new MoreBaseClass();
           
        }
    }
    class DontCloneMe
    {
        public NoThink DrawComp
        { get; private set; }
 

        public List<int> ePHandle
        {
            get;
            private set;
        }


        public DontCloneMe(NoThink drawComp)
        {
            DrawComp = drawComp;
            ePHandle = new List<int>();
           
        }


        public void DrawDotEntity(object er1)
        {
    
        }


        public void FreeHandle()
        {
            ePHandle.ForEach(handle =>  DrawComp.DoWhat(handle));
            ePHandle.Clear();
        
        }


    }


Here's the test code
        [Test, Isolated]
        public void Ftes1()
        {
            DontCloneMe mtt = new DontCloneMe(Isolate.Fake.Instance<NoThink>(Members.ReturnRecursiveFakes));
            Isolate.WhenCalled(()=>mtt.DrawDotEntity(null)).IgnoreCall();
        }


And here's the exception
 No method with name FreeHandle>b__0 in type Test.TypeMockTesting.CloneTest exists.
   at cz.b(Type A_0, String A_1)
   at cz.c(Type A_0, String A_1)
   at TypeMock.Mock.a(String A_0, Object A_1, Boolean A_2, Boolean A_3, Int32 A_4, Type[] A_5)
   at TypeMock.Mock.a(String A_0, Object A_1, Boolean A_2, Boolean A_3, Type[] A_4)
   at TypeMock.Mock.AlwaysCallOriginal(String method, Type[] genericTypes)
   at TypeMock.MockManager.b(Mock A_0, BindingFlags A_1)
   at TypeMock.MockManager.b(Object A_0, String A_1)
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Object p1)

________
RL250
asked by nsoonhui (59.1k points)

2 Answers

0 votes
Hi Soon,

I can confirm this is indeed a bug. We are (ironically enough) not handling the anonymous lambda in DontCloneMe correctly when faking behavior for that object, which leads to the weird exception message you see. This happens even though the lambda or the method it's declared in do not participate in the test.

We will work to resolve this for an upcoming version release. I will send you a patch for this behavior once we support it.

Thanks,
Doron
answered by doron (17.2k points)
0 votes
I think I have a similar ( but simpler reproduction steps here), discovered when unit testing another part of my code :

    public static class WhereAreWe
    {
        public  static void RemoveThing()
        {
            CallException();
            List<double> tList = new List<double>();
            tList.RemoveAll(dup => dup == 0);


        }

        public static void CallException()
        {
            
        }
    }


        [Test, Isolated]
        public void TestWhereArewe()
        {
            Isolate.WhenCalled(()=>WhereAreWe.CallException()).IgnoreCall();
            WhereAreWe.RemoveThing();
        }


It seems that the moment lambda expression is used the TypeMock will have a difficult time mocking the calls. :( :( :( :(
________
synthetic weed
answered by nsoonhui (59.1k points)
...