romantitov / MockQueryable

Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc
MIT License
791 stars 77 forks source link

ToListAsync() returns empty list after package update to 6.0.0 #58

Closed VILLAN3LL3 closed 2 years ago

VILLAN3LL3 commented 2 years ago

After having updated the MockQueryable package to version 6.0.0 some of my unit tests fail because .ToListAsync() now returns an empty list. Example code:

DbSet<Sections> mockSections = sections.AsQueryable().BuildMockDbSet();
_dbContext.Sections.Returns(mockSections); 
List<Section> sections = await _dbContext.Sections.ToListAsync(cancellationToken); 

The last line returns an empty list with the new package version. Why?

The failed tests and the full test code can be found here

romantitov commented 2 years ago

Thank you @VILLAN3LL3 for your feedback. The issue fixed in the release v6.0.1.

NanoWar commented 2 years ago

With version 6.0.1 I'm running into a similar issue as mentioned in #23 . When I change the base collection after using ToListAsync on the mock, I also get System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

romantitov commented 2 years ago

Hello @NanoWar. Thank you for your feedback. Could you create a new issue for that and add an example of unit tests to reproduce the your issue.