如何模拟/存根Nhibernate QueryOver调用?

时间:2011-07-21 23:03:02

标签: c# nhibernate mocking rhino-mocks

如何存根返回包含数据的QueryOver对象的调用?

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

1 个答案:

答案 0 :(得分:4)

就像Phill说sqlite会更容易。然而,这应该工作

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

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