Question
I've ran into a problem while trying to test following IRepository based on NHibernate:
public class NHibernateRepository<T>: Disposable, IRepository<T>
where T : IdentifiableObject
{
...
public IQueryable<T> Query()
{
return NHibernateSession.Linq<T>();
}
}
How on the Hell to mock returning IQueryable<T>
out in the way that it returns given collection in exchange certain expression. I feel I have some misunderstanding of IQueryable<T>
...
Solution
In Moq
it would be:
mockRepository.Expect( r => r.Query() ).Returns( myEnumerable.AsQueriable() );
In RhinoMocks
it would be:
Expect.Call( repository.Query() ).Return( myEnumerable.AsQueriable() );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow