title: How to mock an NhibernateSession Query that uses a Where clause and returns a List
body: <p>I cannot work out how to Rhino mock the following statement:</p>
  
  <pre><code>var jobs = nhibernateSession.Query&lt;Job&gt;()
  .Where(x =&gt; x.Trust.Id == 1)
  .ToList();
  </code></pre>
  
  <p>I have tried various permutations, but the current unsuccessful attempt is:</p>
  
  <pre><code>nhibernateSession.Expect(y =&gt; y.Query&lt;Job&gt;())
  .IgnoreArguments()
  .Return(new List&lt;Job&gt; { new Job() }.AsQueryable());
  </code></pre>
  
  <p>The error I get back is:</p>
  
  <pre><code>Source: Anonymously Hosted DynamicMethods Assembly
  Message: Object reference not set to an instance of an object.
  StackTrace:    at lambda_method(Closure , Job )
  at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
  at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
  at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
  </code></pre>
  
  <p>Thanks for any advice.</p>
  
  <p>Stu</p>