The provider for the source IQueryable doesn't implement IAsyncQueryProvider

后端 未结 4 1809
执念已碎
执念已碎 2020-12-02 01:50

I have some codes like below, I want to write unit tests my method. But I\'m stuck in async methods. Can you help me please ?

public class Panel
{
    publi         


        
4条回答
  •  -上瘾入骨i
    2020-12-02 02:17

    I get stuck on this issue today and this lib resolve it for me https://github.com/romantitov/MockQueryable completely, please refer:

    Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc.

    //1 - create a List with test items
    var users = new List()
    {
      new UserEntity{LastName = "ExistLastName", DateOfBirth = DateTime.Parse("01/20/2012")},
      ...
    };
    
    //2 - build mock by extension
    var mock = users.AsQueryable().BuildMock();
    
    //3 - setup the mock as Queryable for Moq
    _userRepository.Setup(x => x.GetQueryable()).Returns(mock.Object);
    
    //3 - setup the mock as Queryable for NSubstitute
    _userRepository.GetQueryable().Returns(mock);
    

提交回复
热议问题