title: MSTest v2 and The source IQueryable doesn't implement IAsyncEnumerable with Entity Framework Core
body: <p>I am trying to create unit tests(MSTest v2) for a DAL library(EF core)</p>
  
  <p><strong>DataService</strong></p>
  
  <pre><code>    public IQueryable&lt;BalanceDTO&gt; GetCollection()
      {
          var entities = dbContext.Balance;
          var dtos = mapper.Map&lt;ICollection&lt;BalanceDTO&gt;&gt;(entities).ToList();
          dtos.ForEach(_d =&gt;
          {
              _d.MonthSort = _d.Date.Month;
              _d.MonthName = (new DateTimeFormatInfo()).GetMonthName(_d.MonthSort);
          });
          return dtos.AsQueryable();
      }
  
      public async Task&lt;IList&lt;BalanceDTO&gt;&gt; GetBalancesByYear(int year)
      {
          return await GetCollection().Where(_d =&gt; _d.Date.Year == year).OrderBy(_d =&gt; _d.MonthSort).ToListAsync();
      }
  </code></pre>
  
  <p><strong>Test</strong></p>
  
  <pre><code>    [TestMethod()]
      [DataTestMethod]
      [DataRow(2020, 2019)]
      public void GetBalancesByYearTest(int found, int notfound)
      {
          var _configuration = new ConfigurationBuilder()
              .SetBasePath(AssemblyProperties.AssemblyDirectory)
              .AddJsonFile("appsettings.json")
              .Build();
          var optionsBuilder = new DbContextOptionsBuilder&lt;AccountManagerContext&gt;();
          optionsBuilder.UseSqlServer(_configuration.GetConnectionString("AccountManagerLocalDB"));
  
          var balanceDataService = new BalanceDataService(optionsBuilder);
          var elementsFound = balanceDataService.GetBalancesByYear(found);
          var elementsNotFound = balanceDataService.GetBalancesByYear(notfound);
  
          Assert.IsNotNull(balanceDataService);
          Assert.IsTrue(elementsFound.Result.Count &gt; 0);
          Assert.IsTrue(elementsNotFound.Result.Count == 0);
      }
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>InvalidOperationException: The source IQueryable doesn't implement IAsyncEnumerable&lt;AccountManager.DAL.DTO.BalanceDTO&gt;. 
  Only sources that implement IAsyncEnumerable can be used for Entity Framework asynchronous operations.
  </code></pre>
  
  <p>I have found a couple of link but couldn't figure out how to resolve this.</p>
  
  <p><a href="https://stackoverflow.com/questions/48743165/toarrayasync-throws-the-source-iqueryable-doesnt-implement-iasyncenumerable">ToArrayAsync() throws &quot;The source IQueryable doesn&#39;t implement IAsyncEnumerable&quot;</a></p>
  
  <p><a href="https://stackoverflow.com/questions/57824737/how-to-overcome-the-iqueryable-doesnt-implement-iasyncqueryprovider-while-mocki/57825026">How to overcome the IQueryable doesn&#39;t implement IAsyncQueryProvider while Mocking the FromSql() method?</a></p>
  
  <p>Any idea about how to create tests for my DataService methods?</p>