My setup is like this.

1. Define a new interface for mocking.

public interface IMockSession : ISession
{
   IQueryable<T> GetQueryable<T>();
}

2. Replace all calls to the Query<T> extension method with a call to a
custom method (I call it GetQuery<T>)


public static IQueryable<T> GetQuery<T>(this ISession session)
        {
            var mockSession = session as IMockSession;
            return mockSession != null ? mockSession.GetQueryable<T>() :
session;
        }

Now I can use Mock<IMockSession> in my unit tests, and e.g. intercept its
GetQueryable method to return what I want, usually an in memory collection.

It leaks unit testing code into production code, but that doesn't bother
me. If it did, I could use ac ompiler directive.

/G

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to