I am trying to Mock some code that calls an extension method. This is legacy code that is not written to be testable, but I've been tasked with trying to create unit tests for it without having to change the code, as time/politics/etc will now allow for that.
Anyway, the code I'm trying to mock is in our applications data access framework. We use a (very old) version of NHibernate (hence legacy). We have a method that uses nHibernate to return an IQueryable interface for us to query. It looks like this:
public static IQueryable<TEntity> Linq()
{
ISession session = GetCurrentUnitOfWork();
return session.Query<TEntity>();
}
I can successfully rig the GetCurrentUnitOfWork method to return an mocked ISession, which, instead of going to the DB, returns Lists of objects.
The problem is that the Query method is not defined on ISession. It's an extension method of ISession. Since the framework code is compiled to call the extension method Query(), even if I define the exact same method on my mocked ISession, the extension method is still called.
So, does anybody have any ideas on how I can rig this code to call a mocked version of the Query method()?
Thanks in advance.