Hi,
I think that this may be a known issue but I haven't seen any posts or documentation that presents a workaround.
The following code is a simple example that illustrates the problem that I am having while trying to test overloaded generic methods.
public interface ITest { }
public class Foo { }
public class MyCUT
{
public Foo Send(Foo foo)
{
return null;
}
public T Send<T>(string name, T obj) where T : ITest
{
return default(T);
}
}
[TestFixture]
public class MyTestFixture
{
[Test]
[Isolated]
public void Send()
{
MyCUT mc = Isolate.Fake.Instance<MyCUT>();
ITest test = Isolate.Fake.Instance<ITest>();
Isolate.WhenCalled(() => mc.Send<ITest>(default(string), test)).WillReturn(null);
mc.Send<ITest>("test", test);
}
}
If I run the above test I get the following exception:
failed: System.InvalidCastException : Unable to cast object of type 'UnitTests.Foo' to type 'UnitTests.ITest'.
C:UnitTestsTestFixture.cs(21,0): at UnitTests.MyCUT.Send[T](String name, T obj)
C:UnitTestsTestFixture.cs(36,0): at UnitTests.MyTestFixture.<>c__DisplayClass1.<Send>b__0()
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)
C:UnitTestsTestFixture.cs(0,0): at UnitTests.MyTestFixture.Send()
If this is a known defect or limitation please provided me with a workaround. If I am just doing something wrong (I hope) then please point that out.
Cheers,
Darin