title: Unit Testing Z Entity Framework Plus Extensions
body: <p>When using Z.EntityFramework.Plus extensions, I cannot find a way to mock/substitute what the context returns when any of the plus extensions, not just Future(), are being used. Everything I try throws a NullReferenceException within the z extensions future library. </p>
  
  <p>Repository Example:</p>
  
  <pre><code>public Task&lt;DocumentDomain&gt; GetDocuments(int id)
  {
    var futureQuery1 = _context.ReportTypes.Where(x =&gt; x.IsReadOnly).Future();
    var futureQuery2 = _context.Reports.Where(x =&gt; x.CreateDate &lt; DateTime.Now.AddDays(-10)).Future();
    var futureQuery3 = _context.Person.DeferredFirstOrDefault(x =&gt; x.Id == id).FutureValue();
  
     return new DocumentDomain(futureQuery1.ToList(), futureQuery2.ToList(), futureQuery3.Value);
  }
  </code></pre>
  
  <p>Unit Test Repository:</p>
  
  <pre><code>    [Fact]
      public async Task ShouldGetDocumentsForPerson1()
      {
         _context = Substitute.For&lt;IMyDbContext&gt;();
         _context.ReportTypes = new FakeDbSet();
         _context.ReportTypes.AddRange(GetFakeReportTypes());
         // ...etc..arrange for Reports and Person
  
         var repo = new DocumentRepository(_context);
  
         // CRASHES HERE ON futureQuery1 at .Future()
         var domain = await repo.GetDocuments(1); // fake id
  
         Assert.IsTrue(domain.Documents.Count &gt; 0);
      }
  </code></pre>
  
  <p>Without using Futures it works fine. I've tried mocking out a few different ways but always get an error. Most of the time it's a "oops Z extensions encountered an error" exception. </p>
  
  <p>I'm thinking it's because Z extensions is expecting a real ObjectContext but not sure how to overcome this. Has anyone experienced similar issues? Does anyone know of any solutions? Thanks.</p>