Trying to unit test NHibernate and unit of work pattern however have come up against a brick wall when trying to mock data access methods which return an IQueryable?
This works:
var employee = Helper.GetEmployee();
Repository.Stub(x => x.FindById<Employee>(employee.Id)).Return(employee);
This doesn't work:
var employee = Helper.GetEmployee();
var employeeList = new List<Employee> { employee };
Repository.Stub(x => x.All<Employee>().ToList()).Return(employeeList);
Basically, anything which returns > 1 employee I can't get mock to behave.
Repository FindById method returns:
Session.Get<TEntity>(id);
Repository All method returns:
Session.Query<TEntity>();
When unit test runs of mocked repository All method, returns exception saying source can't be null?
I'm stuck, any ideas?
Thanks! Tim