title: Mock unit test returns ArgumentNullException on AsNoTracking()
body: <p>I've setup the mock dbset which reads a bunch of json files and deserializes them to a mock dbset. I have added AsNoTracking to my variable for two reasons:
  1) I will be storing a new object in the db and do not need to track the object as that updates the entry.
  2) Performance.</p>
  
  <p>The code works fine however the mocking is not working since I've added the AsNoTracking() method to not store the result in the dbcontext cache. This is returning an ArgumentNullException now. If I remove AsNoTracking the test passes however I do not want to be forced to having to remove AsNoTracking simply for the passing of unit tests.</p>
  
  <p>When debugging my unit tests it throws an ArugmentNullException here:</p>
  
  <pre><code>var myObj = dbContext.MyTable.AsNoTracking().Where(b =&gt; b.Id == param.Id).Include(b =&gt; b.Column1).Include(b =&gt; b.Column2).Include(b =&gt; b.Colum3).FirstOrDefault();
  </code></pre>
  
  <p>However if run through a browser this works fine, data is returned correctly, the object is not null.</p>
  
  <pre><code>public Mock&lt;DbSet&lt;T&gt;&gt; GetMockDbSet&lt;T&gt;(string path) where T : class
          {
              var data = GetObjectList&lt;T&gt;(path).AsQueryable();
  
              var mockSet = new Mock&lt;DbSet&lt;T&gt;&gt;();
              mockSet.As&lt;IQueryable&lt;T&gt;&gt;().Setup(m =&gt; m.Provider).Returns(data.Provider);
              mockSet.As&lt;IQueryable&lt;T&gt;&gt;().Setup(m =&gt; m.Expression).Returns(data.Expression);
              mockSet.As&lt;IQueryable&lt;T&gt;&gt;().Setup(m =&gt; m.ElementType).Returns(data.ElementType);
              mockSet.As&lt;IQueryable&lt;T&gt;&gt;().Setup(m =&gt; m.GetEnumerator()).Returns(()=&gt;data.GetEnumerator());
  
              return mockSet;
  
          }
  </code></pre>
  
  <p>Is there anything I can do to the code above so that the result is not null if AsNoTracking() is added to var's where objects are being returned from a dbset.</p>