title: Mocking out nHibernate QueryOver with Moq
body: <p>The following line fails with a null reference, when testing:</p>
  
  <pre><code>var awards = _session.QueryOver&lt;Body&gt;().Where(x =&gt; x.BusinessId == (int)business).List();
  </code></pre>
  
  <p>My test is like so:</p>
  
  <pre><code>var mockQueryOver = new Mock&lt;IQueryOver&lt;Body, Body&gt;&gt;();
  mockQueryOver.Setup(q =&gt; q.List()).Returns(new List&lt;Body&gt; {_awardingBody});
  _mockSession.Setup(c =&gt; c.QueryOver&lt;Body&gt;()).Returns((mockQueryOver.Object));
  _mockCommandRunner = new Mock&lt;ICommandRunner&gt;();
  _generator = new CertificateGeneratorForOpenSSLCommandLine(_mockSession.Object, _mockCommandRunner.Object, _mockDirectory.Object, _mockFile.Object, _mockConfig.Object); 
  </code></pre>
  
  <p>To be honest I'm flailing around in the dark here - I'm relatively new to nHibernate and Moq, so I'm not very sure what to google to get the right information.</p>