title: How to mock Find() from EF via Moq
body: <p>My testable function uses <code>EF.Find()</code> so as I discovered I need to implement mock of find.</p>
  <p>The only code which seems to get compiled is <code>c#</code></p>
  <pre><code>testsContextMock.Setup(m =&gt; m.Find(It.IsAny&lt;Type&gt;(), It.IsAny&lt;object[]&gt;()))
  .Returns&lt;object[]&gt;(hashes =&gt; testsMock.Object.FirstOrDefault(u =&gt; u.hash == (string)hashes[0]))
  </code></pre>
  <p>Where <code>testsContextMock</code> is <code>Mock&lt;DbContext&gt;</code> object, and <code>testsMock</code> is <code>Mock&lt;DbSet&lt;MyEntity&gt;&gt;</code>.</p>
  <p>But after completion of this code I get this error</p>
  <pre><code>System.ArgumentException : Invalid callback. 
  Setup on method with 2 parameter(s) cannot invoke callback 
  with different number of parameters (1).
  </code></pre>
  <p>As Im assume this is happening cause in testable method signature of calling <code>Find()</code> is <code>DbSet&lt;MyEntity&gt;.Find(params object[] keyValues)</code> and signature of mocked method is <code>DbContext.Find(Type entityType, params object[] keyValues)</code>. And if Im trying to mock other overload it somehow fails with compiler error
  <code>Argument 1: cannot convert from 'object[]' to 'System.Type'</code></p>