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 code:

    class ClassUnderTest3
    {
        public object GetData(bool find)
        {
            List<string> list = new List<string>();
            list.Add("a");
            if (find)
            {
                list.Find(c => true);
            }
            return null;
        }

        private static void StaticPrivate()
        {
        }

        internal static void StaticInternal()
        {
        }
    }

    [TestFixture]
    public class TestClass3
    {
        [Test]
        public void GetData_WithFind_StaticPrivate()
        {
            Isolate.NonPublic.WhenCalled<ClassUnderTest3>("StaticPrivate").IgnoreCall();
            var c = new ClassUnderTest3();
            c.GetData(false);
        }

        [Test]
        public void GetData_WithFind_StaticInternal()
        {
            Isolate.NonPublic.WhenCalled<ClassUnderTest3>("StaticInternal").IgnoreCall();
            var c = new ClassUnderTest3();
            c.GetData(false);
        }

        [Test]
        public void GetData_NoFind_StaticPrivate()
        {
            Isolate.NonPublic.WhenCalled<ClassUnderTest3>("StaticPrivate").IgnoreCall();
            var c = new ClassUnderTest3();
            c.GetData(true);
        }

        [Test]
        public void GetData_NoFind_StaticInternal()
        {
            Isolate.NonPublic.WhenCalled<ClassUnderTest3>("StaticInternal").IgnoreCall();
            var c = new ClassUnderTest3();
            c.GetData(true);
        }
    }


And here's output:

------ Test started: Assembly: TypeMockTest.dll ------

TestCase 'TypeMockTest.TestClass3.GetData_NoFind_StaticInternal'
failed: TypeMock.TypeMockException :
*** No method with name <GetData in type TypeMockTest.ClassUnderTest3 exists.
at cn.b(Type A_0, String A_1)
at cn.c(Type A_0, String A_1)
at ce.a(String A_0, Object[] A_1, Object A_2, Object A_3, String A_4, Type A_5)
at c8.a(String A_0, Object A_1, MethodBase A_2, Object[] A_3, Object A_4, String A_5, ce A_6)
at c8.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
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)
C:ProjectsNETTypeMockTestMyClass3.cs(19,0): at TypeMockTest.ClassUnderTest3.<GetData>b__0(String c)
at System.Collections.Generic.List`1.Find(Predicate`1 match)
C:ProjectsNETTypeMockTestMyClass3.cs(19,0): at TypeMockTest.ClassUnderTest3.GetData(Boolean find)
C:ProjectsNETTypeMockTestMyClass3.cs(65,0): at TypeMockTest.TestClass3.GetData_NoFind_StaticInternal()

TestCase 'TypeMockTest.TestClass3.GetData_NoFind_StaticPrivate'
failed: TypeMock.TypeMockException :
*** No method with name <GetData in type TypeMockTest.ClassUnderTest3 exists.
at cn.b(Type A_0, String A_1)
at cn.c(Type A_0, String A_1)
at ce.a(String A_0, Object[] A_1, Object A_2, Object A_3, String A_4, Type A_5)
at c8.a(String A_0, Object A_1, MethodBase A_2, Object[] A_3, Object A_4, String A_5, ce A_6)
at c8.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
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)
C:ProjectsNETTypeMockTestMyClass3.cs(19,0): at TypeMockTest.ClassUnderTest3.<GetData>b__0(String c)
at System.Collections.Generic.List`1.Find(Predicate`1 match)
C:ProjectsNETTypeMockTestMyClass3.cs(19,0): at TypeMockTest.ClassUnderTest3.GetData(Boolean find)
C:ProjectsNETTypeMockTestMyClass3.cs(57,0): at TypeMockTest.TestClass3.GetData_NoFind_StaticPrivate()


2 passed, 2 failed, 0 skipped, took 1,37 seconds (NUnit 2.5).


As you can see, TypeMock throws exception only when a Find method with a predicate is invoked. Weird! Only happens in newest Isolator version.
asked by vagif (19.4k points)

7 Answers

0 votes
Vagif,

Thank you for the repro - I'll investigate this issue and update on this thread
answered by dhelper (11.9k points)
0 votes
I think I'm running into this same issue, and I have a little additional information that might help track it down. In my case at least, this appears to be related to lambda and linq expressions combined with a static method.

My code and errors are at the bottom. Notice that the non-static calls all work with Isolate.NonPublic with and without Linq (tests 1-3). Test 4 also works (static without linq/lambda). Tests 5 and 6 both fail with a very similar error message to the original post.

I'm using Isolator 5.4.5, VS2008 and the VS Unit Testing framework.

Code:
    public class Processing
    {
        public void BeginWithLinq()
        {
            int[] numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] subset = (from int i in numbers
                            where i <5> n % 2 == 1);
            More();
        }
        public void BeginWithoutLinq()
        {
            More();
        }
        private void More()
        {}
    }
    public static class ProcessingStatic
    {
        public static void BeginWithLinq()
        {
            int[] numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] subset = (from int i in numbers
                            where i <5> n % 2 == 1);
            More();
        }
        public static void BeginWithoutLinq()
        {
            More();
        }
        private static void More()
        {}
    }
        [TestMethod]
        public void TestMethod1()
        {
            Processing p = Isolate.Fake.Instance<Processing>();
            Isolate.NonPublic.WhenCalled(p, "More").IgnoreCall();
            
            p.BeginWithLinq();
        }
        [TestMethod]
        public void TestMethod2()
        {
            Processing p = Isolate.Fake.Instance<Processing>();
            Isolate.NonPublic.WhenCalled(p, "More").IgnoreCall();
            p.BeginWithoutLinq();
        }
        [TestMethod]
        public void TestMethod3()
        {
            Processing p = Isolate.Fake.Instance<Processing>();
            Isolate.NonPublic.WhenCalled(p, "More").IgnoreCall();
            p.BeginWithLambda();
        }
        [TestMethod]
        public void TestMethod4()
        {
            Isolate.NonPublic.WhenCalled(typeof(ProcessingStatic), "More").IgnoreCall();
            ProcessingStatic.BeginWithoutLinq();
        }
        [TestMethod]
        public void TestMethod5()
        {
            Isolate.NonPublic.WhenCalled(typeof(ProcessingStatic), "More").IgnoreCall();
            ProcessingStatic.BeginWithLinq();
        }
        [TestMethod]
        public void TestMethod6()
        {
            Isolate.NonPublic.WhenCalled(typeof(ProcessingStatic), "More").IgnoreCall();
            ProcessingStatic.BeginWithLambda();
        }


TestMethod5 Results:
Test method TypeMockReproTest.UnitTest1.TestMethod5 threw exception: TypeMock.TypeMockException:
*** No method with name <BeginWithLinq in type TypeMockRepro.ProcessingStatic exists..
TestMethod5 Stack Trace:
at cn.b(Type A_0, String A_1)
at cn.c(Type A_0, String A_1)
at ce.a(String A_0, Object[] A_1, Object A_2, Object A_3, String A_4, Type A_5)
at c8.a(String A_0, Object A_1, MethodBase A_2, Object[] A_3, Object A_4, String A_5, ce A_6)
at c8.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at TypeMockRepro.ProcessingStatic.&lt;BeginWithLinq&gt;b__0(Int32 i) in C:ViperSPCRSrcUnit TestsTypeMockReproClass1.cs:line 49
at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at TypeMockRepro.ProcessingStatic.BeginWithLinq() in C:ViperSPCRSrcUnit TestsTypeMockReproClass1.cs:line 48
at TypeMockReproTest.UnitTest1.TestMethod5() in C:ViperSPCRSrcUnit TestsTypeMockReproTestUnitTest1.cs:line 103
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)
at TypeMockReproTest.UnitTest1.TestMethod5() in C:ViperSPCRSrcUnit TestsTypeMockReproTestUnitTest1.cs:line 101

TestMethod6 Results:
Test method TypeMockReproTest.UnitTest1.TestMethod6 threw exception: TypeMock.TypeMockException:
*** No method with name &lt;BeginWithLambda in type TypeMockRepro.ProcessingStatic exists..
TestMethod6 StackTrace:
at cn.b(Type A_0, String A_1)
at cn.c(Type A_0, String A_1)
at ce.a(String A_0, Object[] A_1, Object A_2, Object A_3, String A_4, Type A_5)
at c8.a(String A_0, Object A_1, MethodBase A_2, Object[] A_3, Object A_4, String A_5, ce A_6)
at c8.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at TypeMockRepro.ProcessingStatic.&lt;BeginWithLambda&gt;b__2(Int32 n) in C:ViperSPCRSrcUnit TestsTypeMockReproClass1.cs:line 60
at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source, Func`2 predicate)
at TypeMockRepro.ProcessingStatic.BeginWithLambda() in C:ViperSPCRSrcUnit TestsTypeMockReproClass1.cs:line 60
at TypeMockReproTest.UnitTest1.TestMethod6() in C:ViperSPCRSrcUnit TestsTypeMockReproTestUnitTest1.cs:line 111
at TypeMock.MockManager.a(String A_0, String A_1, Obj
answered by dcarroll (140 points)
0 votes
This issue is fixed in the upcoming version of Typemock Isolator, in the meantime I'll send you a patch
answered by dhelper (11.9k points)
0 votes
This issue is fixed in the upcoming version of Typemock Isolator, in the meantime I'll send you a patch


I also need the patch. How can I obtain it from you? TIA
answered by dblack (8.4k points)
0 votes
Hi Dave,

I sent you the patch please let me know if it helps.
answered by ohad (35.4k points)
0 votes
Hi Dave,

I sent you the patch please let me know if it helps.



Hi Ohad,

I only received one email from you with a link. Does this 5.4.6 patch include fixes for *both* of the following?

1. Isolate.NonPublic is broken in 5.4.5 - https://www.typemock.com/community/viewt ... highlight=

AND

2. Inherited virtual properties are broken in Isolator 5.4.5 -
https://www.typemock.com/community/viewt ... highlight=
answered by dblack (8.4k points)
0 votes
Hi,

The installer I sent you is the latest build that includes fixes for both of the problems.
answered by ohad (35.4k points)
...