Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Mock/Stub a Nhibernate QueryOver Call?

How can I stub a call that returns a QueryOver object that contains data?

        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(?????????);
        }
like image 590
mxmissile Avatar asked Jul 21 '11 23:07

mxmissile


1 Answers

just like Phill said sqlite would be easier. nevertheless this should work

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

data.Stub(x => x.CustomersAsQueryOver).Return(queryover);
like image 102
Firo Avatar answered Oct 03 '22 06:10

Firo