title: MongoDB C# driver Mock method that returns IAsyncCursor
body: <p>I'm  creating some unit tests for my DAL that uses mongoDB c# driver. The thing is that I have this method that I want to test:</p>
  
  <pre><code>    public async virtual Task&lt;IEnumerable&lt;T&gt;&gt; GetAsync(Expression&lt;Func&lt;T, bool&gt;&gt; predicate)
      {
          return (await Collection.FindAsync(predicate)).ToList();
      }
  </code></pre>
  
  <p>and using <a href="https://www.nuget.org/packages/moq/" rel="noreferrer">Moq</a> I have mocked the collection like this:</p>
  
  <pre><code>var mockMongoCollectionAdapter = new Mock&lt;IMongoCollectionAdapter&lt;Entity&gt;&gt;();
  
  var expectedEntities = new List&lt;Entity&gt;
  {
      mockEntity1.Object,
      mockEntity2.Object
  };
  
  mockMongoCollectionAdapter.Setup(x =&gt; x.FindAsync(It.IsAny&lt;Expression&lt;Func&lt;Entity,bool&gt;&gt;&gt;(), null, default(CancellationToken))).ReturnsAsync(expectedEntities as IAsyncCursor&lt;Entity&gt;);
  </code></pre>
  
  <p>but as <code>expectedEntities as IAsyncCursor&lt;Entity&gt;</code> is null the test is not working.</p>
  
  <p>What is the best way to mock this method and handle the IAsyncCursor?</p>