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

I'm getting the following exception using TypeMock 3.7.1 and .Net 2.0 when I try to use natural mocks with my code which uses generics:
Test method TestProject1.MyClassTest.method1Test threw exception: System.Reflection.AmbiguousMatchException: Ambiguous match found..

Here's a small testcase to reproduce it. The code being tested is:
public interface intC<T>
{
    void blah(T myInt);
}
public class classB<T>
{
    public intC<T> Selected(IEnumerable foo)
    {
        return null;
    }
    public intC<T> Selected(intC<T> bar)
    {
        return null;
    }
}
public class classA<T>
{
    public classB<T> B
    {
        get
        {
            return null;
        }
    }
}
public class MyClass
{
    public static void method1()
    {
        classA<int> a = new classA<int>();
        a.B.Selected((IEnumerable) null).blah(4);
    }
}


And here is the unit test code:
[TestMethod()]
public void method1Test()
{
    classA<int> a = new classA<int>();
    using (RecordExpectations recorder = RecorderManager.StartRecording())
    {
        a.B.Selected((IEnumerable) null).blah(4);
    }
    MyClass.method1();
}


Also, if you change classA to be static you then get a NullReferenceException from TypeMock when creating the natural mock. That might actually be a different bug.
asked by tibor (1.8k points)

12 Answers

0 votes
Hi Ohad,

I tested the fix and it works great. My test now passes! Thanks for the quick turnaround on this.

Tibor
answered by tibor (1.8k points)
0 votes
Hi
The patch is available to all in 4.0.0 release
answered by ohad (35.4k points)
...