我有以下代码尝试存根ISession.Query<UnitModel>()
。
var unitList = new List<UnitModel>()
{
new UnitModel(){Name = "meters", Symbol="m"},
new UnitModel(){Name="grams", Symbol="g"}
};
MockRepository.GenerateMock<ISession>().Stub(x => x.Query<UnitModel>()).Return(unitList.AsQueryable<UnitModel>());
运行时,这会引发异常:
System.InvalidOperationException : Type 'System.Linq.EnumerableQuery`1[[MIB.DomainModels.UnitModel, MIB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' doesn't match the return type 'NHibernate.Engine.ISessionImplementor' for method 'ISession.GetSessionImplementation();'
我在这里做错了什么?我应该如何处理存根ISession.Query<UnitModel>()
?
NHibernate 3.3.0.4000
编辑:
UnitModel
类:
public class UnitModel
{
public virtual string Name { get; set; }
public virtual string Symbol { get; set; }
}