[英]How To Mock/Stub a Nhibernate QueryOver Call?
How can I stub a call that returns a QueryOver object that contains data?如何存根返回包含数据的 QueryOver object 的调用?
public interface IData
{
IQueryable<Customer> CustomersAsQueryable { get; }
IQueryOver<Customer> CustomersAsQueryOver { get; }
}
[Fact]
public void QueryOver_spike()
{
var customers = new List<Customer>
{
new Customer {Name = "this"},
new Customer {Name = "is"},
new Customer {Name = "fubar"}
};
var data = MockRepository.GenerateMock<IData>();
//this works
data.Stub(x => x.CustomersAsQueryable).Return(customers.AsQueryable());
//how can i stub this?
data.Stub(x => x.CustomersAsQueryOver).Return(?????????);
}
just like Phill said sqlite would be easier.就像菲尔说 sqlite 会更容易。 nevertheless this should work尽管如此,这应该有效
var queryover = MockRepository.GenerateMock<IQueryOver<Customer>>();
queryover.Stub(...).Return(...);
data.Stub(x => x.CustomersAsQueryOver).Return(queryover);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.