title: NHibernate queryable unit testing
body: <p>Trying to unit test NHibernate and unit of work pattern however have come up against a brick wall when trying to mock data access methods which return an IQueryable?</p>
  
  <p>This works:</p>
  
  <pre><code>var employee = Helper.GetEmployee();
  Repository.Stub(x =&gt; x.FindById&lt;Employee&gt;(employee.Id)).Return(employee);
  </code></pre>
  
  <p>This doesn't work:</p>
  
  <pre><code>var employee = Helper.GetEmployee();
  var employeeList = new List&lt;Employee&gt; { employee };
  Repository.Stub(x =&gt; x.All&lt;Employee&gt;().ToList()).Return(employeeList);
  </code></pre>
  
  <p>Basically, anything which returns > 1 employee I can't get mock to behave.</p>
  
  <p>Repository FindById method returns: </p>
  
  <pre><code>Session.Get&lt;TEntity&gt;(id);
  </code></pre>
  
  <p>Repository All method returns:</p>
  
  <pre><code>Session.Query&lt;TEntity&gt;();
  </code></pre>
  
  <p>When unit test runs of mocked repository All method, returns exception saying source can't be null?</p>
  
  <p>I'm stuck, any ideas?</p>
  
  <p>Thanks!
  Tim</p>