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
Hello,

We currently have some problems mocking a generic type. I have reproduced the problem in this small example.

Code under test:
    public class Z<T> where T : new() {
        public void Foo() {
            throw new NotImplementedException("mock this please");
        }
    }

    public class X {
    }

    public class Y {
        private Z<X> z = new Z<X>();
        public void Bar() {
            z.Foo();
        }
    }


Test:
        [TestMethod]
        public void TestMock() {
            Mock m = MockManager.Mock(typeof(Z<X>), Constructor.NotMocked);
            Y y = new Y();
            m.ExpectCall("Foo", 1);
            y.Bar();
            Assert.AreEqual(1, m.GetCallCount("Foo"));
        }


However GetCallCount throws a TypeMockException (see below).

I investigated it and found that:

MockManager.CalledCounter("TestLibrary.Z<TestLibrary.X>", "Foo");


throws the exact same exception, namely:

'MockManager.CalledCounter("TestLibrary.Z<TestLibrary.X>", "Foo")' threw an exception of type 'TypeMock.TypeMockException'
    base {System.Exception}: {"
*** Calls not collected for TestLibrary.Z<TestLibrary.X>, mock the type or set CollectAllCalls"}


However, if I call CalledCounter with the IL-mangled name for the type you get the expected result:

MockManager.CalledCounter("TestLibrary.Z`1", "Foo");
1


It appears to me that GetCallCount is using the "unmangled" name for looking up the value.

Please let me know if you need any additional information to investigate this.

I'm using TypeMock 3.7.1 Enterprise ed.

Thanks,
Brian
asked by brian.rasmussen (7.2k points)

6 Answers

0 votes
Hi Brian
It is a bug Thank you for your report.
I will send the you the fix.
answered by ohad (35.5k points)
0 votes
Hi Ohad,

Can you give me an estimate on when we can expect the bug fix?

Thanks,
Brian
answered by brian.rasmussen (7.2k points)
0 votes
Hi Brian
The fix includes changes in the API and that's the reason it takes more time to deliver the patch.
It is high priority task in our list so I assume that you will not have to wait long
answered by ohad (35.5k points)
0 votes
Any updates regarding a patch for this?

Thanks,
Brian
answered by brian.rasmussen (7.2k points)
0 votes
Hi Brian
The beta version of TypeMock.NET 4.0 is out today with the fix.
I'll send you the link to download offline.
answered by ohad (35.5k points)
0 votes
Hi
The patch is available to all in 4.0.0 release
answered by ohad (35.5k points)
...