tags:

views:

347

answers:

1

Hello.

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 out in the way that it returns given collection in exchange certain expression. I feel I have some misunderstanding of IQueryable...

+6  A: 

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() );
tgmdbm