DbSet mock, no results while calling ToList secondly

后端 未结 4 1504
情深已故
情深已故 2020-12-15 06:29

I\'m trying to mock DbContext and DbSet. This works for my previous unit tests, but problem occurs while my code was calling ToList method on DbSet second time.

Firs

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 06:55

    If you put a "Where" clause before the .ToList() call, the data should remain present.

    var a1 = dbset.Where(m => m != null).ToList();
    
    var a2 = dbset.Where(m => m != null).ToList();
    

提交回复
热议问题