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