Try the below code:
public class GetPrjClass<T>
where T: class
{
private static string GetPrj()
{
throw new NotImplementedException();
}
public T RunPrj(string strAA)
{
var prjFile = GetPrj();
return null;
}
}
public class GetPrjClass2
{
private static string GetPrj()
{
throw new NotImplementedException();
}
public string RunPrj(string strAA)
{
return GetPrj();
}
}
public class UserInfo
{
public string Name
{ get; set; }
}
[TestFixture, Isolated]
public class ClearMocksTest
{
private GetPrjClass<UserInfo> PrjClass;
private GetPrjClass2 PrjClass2;
[SetUp]
public void Init()
{
PrjClass = Isolate.Fake.Instance < GetPrjClass<UserInfo>>(Members.CallOriginal);
PrjClass2 = Isolate.Fake.Instance<GetPrjClass2>(Members.CallOriginal);
}
[TestCase("a")]
[TestCase("b")]
public void OhPrjClass(string aa)
{
Isolate.NonPublic.WhenCalled(PrjClass.GetType(),
"GetPrj").WillReturn("");
PrjClass.RunPrj(aa);
}
[TestCase("a")]
[TestCase("b")]
public void OhPrjClass2(string aa)
{
Isolate.NonPublic.WhenCalled(PrjClass2.GetType(),
"GetPrj").WillReturn("");
PrjClass2.RunPrj(aa);
}
}
Run this code, and this is what you will get
TestCase 'OhPrjClass("b")' failed: System.NotImplementedException : The method or operation is not implemented.
C:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(15,0): at WinFormTest.GetPrjClass`1.GetPrj()
C:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(20,0): at WinFormTest.GetPrjClass`1.RunPrj(String strAA)
C:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(68,0): at WinFormTest.ClearMocksTest.OhPrjClass(String aa)
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:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(64,0): at WinFormTest.ClearMocksTest.OhPrjClass(String aa)
3 passed, 1 failed, 0 skipped, took 1.73 seconds.
It seems that the mocks and expectation for class with generics parameters are not cleared properly, but if the class does not have generics then it can clear properly.
________
DRUG TESTING KIT