MockQueryable icon indicating copy to clipboard operation
MockQueryable copied to clipboard

ToListAsync() returns empty list on second call

Open ghhi opened this issue 3 years ago • 2 comments

Hello, I am running into an issue where the ToListAsync() returns an empty list the second time it is called.

The issue can be easily reproduced by modifying one of the unit tests of your project, adding a second call to the GetAll() function:

[TestCase]
public async Task DbSetGetAllUserEntity()
{
    //arrange
    var users = CreateUserList();
    var mock = users.AsQueryable().BuildMockDbSet();
    var userRepository = new TestDbSetRepository(mock.Object);
    //act
    var result = await userRepository.GetAll();
    result = await userRepository.GetAll();
    //assert
    Assert.AreEqual(users.Count, result.Count);
}

ghhi avatar Oct 21 '22 15:10 ghhi

toListAsync works only when we have Where with an equal condition examples: ` await userRepository .ToListAsync(); // 2 times call, return results only for 1 call

await userRepository.Where(u => u.Id == 1) .ToListAsync(); // 2 times call, returns results always, works as expected

await userRepository.Where(u => u.Id > 0) .ToListAsync(); // return results only for 1 call `

usuf13 avatar Feb 10 '23 20:02 usuf13

Hello. Thanks for you contribution. Sorry for the late answer. Unfortunately I'm very busy at the moment. If you provide a pull request with fix of the issue I would be happy to include it to the next release. Please don't forget to cover the case by additional tests to minimize possibility of regressions for the future. Thanks for the understanding.

romantitov avatar Jan 23 '24 18:01 romantitov

fixed in #74 Thanks @fischero19 Included to the release v7.0.1

romantitov avatar Mar 07 '24 09:03 romantitov