Mocking and IQueryable <T>

I had a problem trying to test the following NHibernate based IRepository:

public class NHibernateRepository<T>: Disposable, IRepository<T> where T : IdentifiableObject { ... public IQueryable<T> Query() { return NHibernateSession.Linq<T>(); } } 

How in hell to mock the return of IQueryable<T> in the form in which it returns this collection in exchange for a specific expression. I feel like I have some misunderstanding of IQueryable<T> ...

+4
source share
1 answer

In Moq it will be:

 mockRepository.Expect( r => r.Query() ).Returns( myEnumerable.AsQueriable() ); 

In RhinoMocks it will be:

 Expect.Call( repository.Query() ).Return( myEnumerable.AsQueriable() ); 
+7
source

Source: https://habr.com/ru/post/1276400/


All Articles