I am trying to mock out or similar the Query extension method applied to an nhibernate-3 session. Similar to the following...
public IQueryable<Entity> GetEntities
{
return entities = Session.Query<Entity>();
}
Where the Query extension method returns an IQueryable collection.
I can clearly mock out the Session object by using Moq or Rhinos. But as of yet not found a suitable way to fake out or replace the extension method. In fact reading answers to several questions on stack overflow, it may not be possible.
see questions How to mock extension methods with Rhino Mock? Mocking Extension Methods with Moq and links within..
I came across the microsoft moles project and thought maybe I could use that to create a subsitute assembly by which I could test this one particular method. Using Pex its relatively quite easy to generate such an assembly however when I try to work a way of using this Assembly its not immediately clear of a way to factor this out.
Ideally I would like to just check to make sure that the query extension method is called by this method and a pre-empted result is returned..
Has anyone done anything similar, would like to hear peoples thoughts..
Ps. there is type mock but I don't have the funds to buy it :)