gpt4 book ai didi

c# - 如何模拟/ stub Nhibernate QueryOver 调用?

转载 作者:太空狗 更新时间:2023-10-29 20:31:47 25 4
gpt4 key购买 nike

如何对返回包含数据的 QueryOver 对象的调用进行 stub ?

        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(?????????);
}

最佳答案

就像 Phill 说的 sqlite 会更容易。尽管如此,这应该可行

var queryover = MockRepository.GenerateMock<IQueryOver<Customer>>();
queryover.Stub(...).Return(...);

data.Stub(x => x.CustomersAsQueryOver).Return(queryover);

关于c# - 如何模拟/ stub Nhibernate QueryOver 调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6783874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com