我正在尝试使用 JustMock 存根 NHibernate ICriteria。
具体来说,当使用对象数组调用 List<> 方法时,我试图对它进行存根:
var mockCriteria = Mock.Create<ICriteria>();
Mock.Arrange(() => mockCriteria.List<object[]>()).Returns(
new object[]
{
new object[] {"CompanyX", 1, 1, 1, 0},
new object[] {"CompanyX", 1, 1, 1, 0},
new object[] {"CompanyY", 2, 1, 1, 0}
});
当我执行第二行(排列)时,出现错误:
System.InvalidOperationExceptionSystem.Collections.IList List() is not a GenericMethodDefinition. MakeGenericMethod may only be called on a method for which MethodBase.IsGenericMethodDefinition is true.
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
at \x7\x5\x2.\x8\x2.\x3\x15\x2(Type \x8, MethodBase , BindingFlags \x1C\xF\x2) at \x6\x2.\x6\x2.Create(Object , MethodInfo \x6, Boolean \x6\x2) at \x7\x5\x2.\x11\x14\x2.\x11\x13\x2(\xF\x2 \x5\xF) at Telerik.JustMock.Mock.\x1F.\x15\x2(\x11\x14\x2 \x2) at \x7\x5\x2.\x5\x14\x2.\x1C[\x4\x14\x2,\x5\x2](\xF\x2 \xF\x2, Func`2 \x3\x14\x2) atThreshold.DeviceManagerGateway.UnitTests.Queries.DeviceNetworkStatusQueryFacts.RetrieveDevicesAsDeviceNetworkStats() in DeviceNetworkStatusQueryFacts.cs: line 24
ICriteria
同时具有 aList()
和 aList<T>()
方法,看起来编译器正在选择该List
方法的非泛型版本而不是泛型版本。假设我是正确的并且它选择了错误的List
方法版本,有人知道如何强制这样做吗?或者,如果这是一个不同的问题,谁能指出我如何解决这个问题?