romantitov / MockQueryable

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

Fix ToListAsync() for mocked DbSet by using lazy-creation of AsyncEnumerator #74

Closed fischero19 closed 9 months ago

fischero19 commented 9 months ago

PR Details

This PR fixes ToListAsync() for mocked DbSets.

Description

In the original implementation, GetAsyncEnumerator() in BuildMockDbSet() was setup to return the current result of enumerable.GetAsyncEnumerator(). This leads to multiple issues when using ToListAsync():

This fix applies only for Moq and FakeItEasy, as the NSubsitute version already used lazy returns.

Related Issue

How Has This Been Tested

Checklist

romantitov commented 9 months ago

Hi @fischero19 thanks for the PR. I will include it into the next release. As I understand the change should fix #68 and #64

fischero19 commented 9 months ago

Hi @romantitov, thanks for maintaining this lib :). I did not explicitly test the two issues, but I also think they are fixed now.