diff --git a/src/MockQueryable/MockQueryable.Core/MockQueryable.Core.csproj b/src/MockQueryable/MockQueryable.Core/MockQueryable.Core.csproj
index c863867..b79b422 100644
--- a/src/MockQueryable/MockQueryable.Core/MockQueryable.Core.csproj
+++ b/src/MockQueryable/MockQueryable.Core/MockQueryable.Core.csproj
@@ -13,10 +13,10 @@
https://github.com/romantitov/MockQueryable
Mock EntityFrameworkCore Queryable mock EF UnitTests EntityFrameworkCore
true
- .Net 6 supported
- 6.0.0
- 6.0.0.0
- 6.0.0.0
+ Fixed issue #58 ToListAsync() returns empty list after package update to 6.0.0
+ 6.0.1
+ 6.0.0.1
+ 6.0.0.1
LICENSE
logo.png
diff --git a/src/MockQueryable/MockQueryable.EntityFrameworkCore/MockQueryable.EntityFrameworkCore.csproj b/src/MockQueryable/MockQueryable.EntityFrameworkCore/MockQueryable.EntityFrameworkCore.csproj
index b98453e..5545067 100644
--- a/src/MockQueryable/MockQueryable.EntityFrameworkCore/MockQueryable.EntityFrameworkCore.csproj
+++ b/src/MockQueryable/MockQueryable.EntityFrameworkCore/MockQueryable.EntityFrameworkCore.csproj
@@ -14,10 +14,10 @@
https://github.com/romantitov/MockQueryable
Mock EntityFrameworkCore Queryable mock EF UnitTests EntityFrameworkCore
true
- .Net 6 supported
- 6.0.0
- 6.0.0.0
- 6.0.0.0
+ Fixed issue #58 ToListAsync() returns empty list after package update to 6.0.0
+ 6.0.1
+ 6.0.0.1
+ 6.0.0.1
LICENSE
logo.png
diff --git a/src/MockQueryable/MockQueryable.FakeItEasy/FakeItEasyExtensions.cs b/src/MockQueryable/MockQueryable.FakeItEasy/FakeItEasyExtensions.cs
index e71d291..17e9558 100644
--- a/src/MockQueryable/MockQueryable.FakeItEasy/FakeItEasyExtensions.cs
+++ b/src/MockQueryable/MockQueryable.FakeItEasy/FakeItEasyExtensions.cs
@@ -22,6 +22,10 @@ public static DbSet BuildMockDbSet(this IQueryable da
mock.ConfigureQueryableCalls(enumerable, data);
mock.ConfigureAsyncEnumerableCalls(enumerable);
mock.ConfigureDbSetCalls(data);
+ if (mock is IAsyncEnumerable asyncEnumerable)
+ {
+ A.CallTo(() => asyncEnumerable.GetAsyncEnumerator(A.Ignored)).Returns(enumerable.GetAsyncEnumerator());
+ }
return mock;
}
@@ -43,6 +47,7 @@ private static void ConfigureAsyncEnumerableCalls(
{
A.CallTo(() => mock.GetAsyncEnumerator(A.Ignored))
.Returns(enumerable.GetAsyncEnumerator());
+
}
private static void ConfigureDbSetCalls(this DbSet mock, IQueryable data)
diff --git a/src/MockQueryable/MockQueryable.FakeItEasy/MockQueryable.FakeItEasy.csproj b/src/MockQueryable/MockQueryable.FakeItEasy/MockQueryable.FakeItEasy.csproj
index 55e5253..d7aa29a 100644
--- a/src/MockQueryable/MockQueryable.FakeItEasy/MockQueryable.FakeItEasy.csproj
+++ b/src/MockQueryable/MockQueryable.FakeItEasy/MockQueryable.FakeItEasy.csproj
@@ -13,10 +13,10 @@
https://github.com/romantitov/MockQueryable
Mock EntityFrameworkCore Queryable mock EF EFCore UnitTests FakeItEasy
true
- .Net 6 supported
- 6.0.0
- 6.0.0.0
- 6.0.0.0
+ Fixed issue #58 ToListAsync() returns empty list after package update to 6.0.0
+ 6.0.1
+ 6.0.0.1
+ 6.0.0.1
LICENSE
logo.png
diff --git a/src/MockQueryable/MockQueryable.Moq/MockQueryable.Moq.csproj b/src/MockQueryable/MockQueryable.Moq/MockQueryable.Moq.csproj
index a811012..6ba3620 100644
--- a/src/MockQueryable/MockQueryable.Moq/MockQueryable.Moq.csproj
+++ b/src/MockQueryable/MockQueryable.Moq/MockQueryable.Moq.csproj
@@ -13,10 +13,10 @@
https://github.com/romantitov/MockQueryable
Mock EntityFrameworkCore Queryable mock EF EFCore UnitTests EntityFrameworkCore Moq
true
- .Net 6 supported
- 6.0.0
- 6.0.0.0
- 6.0.0.0
+ Fixed issue #58 ToListAsync() returns empty list after package update to 6.0.0
+ 6.0.1
+ 6.0.0.1
+ 6.0.0.1
LICENSE
logo.png
diff --git a/src/MockQueryable/MockQueryable.Moq/MoqExtensions.cs b/src/MockQueryable/MockQueryable.Moq/MoqExtensions.cs
index 52af16b..a877d11 100644
--- a/src/MockQueryable/MockQueryable.Moq/MoqExtensions.cs
+++ b/src/MockQueryable/MockQueryable.Moq/MoqExtensions.cs
@@ -21,6 +21,9 @@ public static Mock> BuildMockDbSet(this IQueryable(data);
mock.ConfigureAsyncEnumerableCalls(enumerable);
mock.As>().ConfigureQueryableCalls(enumerable, data);
+ mock.As>().Setup(x => x.GetAsyncEnumerator(It.IsAny())).Returns(enumerable.GetAsyncEnumerator());
+ mock.Setup(m => m.AsQueryable()).Returns(enumerable);
+
mock.ConfigureDbSetCalls(data);
return mock;
}
@@ -41,6 +44,7 @@ private static void ConfigureQueryableCalls(
mock.Setup(m => m.Expression).Returns(data?.Expression);
mock.Setup(m => m.ElementType).Returns(data?.ElementType);
mock.Setup(m => m.GetEnumerator()).Returns(() => data?.GetEnumerator());
+
}
private static void ConfigureAsyncEnumerableCalls(
@@ -49,6 +53,7 @@ private static void ConfigureAsyncEnumerableCalls(
{
mock.Setup(d => d.GetAsyncEnumerator(It.IsAny()))
.Returns(() => enumerable.GetAsyncEnumerator());
+
}
private static async IAsyncEnumerable CreateAsyncMock(IEnumerable data)
diff --git a/src/MockQueryable/MockQueryable.NSubstitute/MockQueryable.NSubstitute.csproj b/src/MockQueryable/MockQueryable.NSubstitute/MockQueryable.NSubstitute.csproj
index 9c8aba8..89df584 100644
--- a/src/MockQueryable/MockQueryable.NSubstitute/MockQueryable.NSubstitute.csproj
+++ b/src/MockQueryable/MockQueryable.NSubstitute/MockQueryable.NSubstitute.csproj
@@ -13,10 +13,10 @@
https://github.com/romantitov/MockQueryable
Mock EntityFrameworkCore Queryable mock EF EFCore UnitTests EntityFrameworkCore NSubstitute
true
- .Net 6 supported
- 6.0.0
- 6.0.0.0
- 6.0.0.0
+ Fixed issue #58 ToListAsync() returns empty list after package update to 6.0.0
+ 6.0.1
+ 6.0.0.1
+ 6.0.0.1
LICENSE
logo.png
diff --git a/src/MockQueryable/MockQueryable.NSubstitute/NSubstituteExtensions.cs b/src/MockQueryable/MockQueryable.NSubstitute/NSubstituteExtensions.cs
index 1d35ac6..810b845 100644
--- a/src/MockQueryable/MockQueryable.NSubstitute/NSubstituteExtensions.cs
+++ b/src/MockQueryable/MockQueryable.NSubstitute/NSubstituteExtensions.cs
@@ -24,6 +24,11 @@ public static DbSet BuildMockDbSet(this IQueryable da
mock.ConfigureQueryableCalls(enumerable, data);
mock.ConfigureDbSetCalls(data);
+ if (mock is IAsyncEnumerable asyncEnumerable)
+ {
+ asyncEnumerable.GetAsyncEnumerator(Arg.Any()).Returns(args => enumerable.GetAsyncEnumerator());
+ }
+
return mock;
}
diff --git a/src/MockQueryable/MockQueryable.Sample/MyService.cs b/src/MockQueryable/MockQueryable.Sample/MyService.cs
index 21fa94f..50d782b 100644
--- a/src/MockQueryable/MockQueryable.Sample/MyService.cs
+++ b/src/MockQueryable/MockQueryable.Sample/MyService.cs
@@ -86,7 +86,7 @@ public interface IUserRepository
Task CreateUser(UserEntity user);
- List GetAll();
+ Task> GetAll();
IAsyncEnumerable GetAllAsync();
}
diff --git a/src/MockQueryable/MockQueryable.Sample/MyServiceFakeItEasyTests.cs b/src/MockQueryable/MockQueryable.Sample/MyServiceFakeItEasyTests.cs
index a33adcb..c65ad82 100644
--- a/src/MockQueryable/MockQueryable.Sample/MyServiceFakeItEasyTests.cs
+++ b/src/MockQueryable/MockQueryable.Sample/MyServiceFakeItEasyTests.cs
@@ -165,6 +165,19 @@ public async Task DbSetGetAllUserEntitiesAsync()
Assert.AreEqual(users.Count, result.Count);
}
+ [TestCase]
+ public async Task DbSetGetAllUserEntity()
+ {
+ //arrange
+ var users = CreateUserList();
+ var mock = users.AsQueryable().BuildMockDbSet();
+ var userRepository = new TestDbSetRepository(mock);
+ //act
+ var result = await userRepository.GetAll();
+ //assert
+ Assert.AreEqual(users.Count, result.Count);
+ }
+
private static List CreateUserList() => new List
{
new UserEntity
diff --git a/src/MockQueryable/MockQueryable.Sample/MyServiceMoqTests.cs b/src/MockQueryable/MockQueryable.Sample/MyServiceMoqTests.cs
index 3badfd5..fd74dfa 100644
--- a/src/MockQueryable/MockQueryable.Sample/MyServiceMoqTests.cs
+++ b/src/MockQueryable/MockQueryable.Sample/MyServiceMoqTests.cs
@@ -144,14 +144,14 @@ public async Task DbSetGetUserReports(DateTime from, DateTime to, int expectedCo
}
[TestCase]
- public void DbSetGetAllUserEntity()
+ public async Task DbSetGetAllUserEntity()
{
//arrange
var users = CreateUserList();
var mock = users.AsQueryable().BuildMockDbSet();
var userRepository = new TestDbSetRepository(mock.Object);
//act
- var result = userRepository.GetAll();
+ var result = await userRepository.GetAll();
//assert
Assert.AreEqual(users.Count, result.Count);
}
diff --git a/src/MockQueryable/MockQueryable.Sample/MyServiceNSubstituteTests.cs b/src/MockQueryable/MockQueryable.Sample/MyServiceNSubstituteTests.cs
index d6a4432..3039149 100644
--- a/src/MockQueryable/MockQueryable.Sample/MyServiceNSubstituteTests.cs
+++ b/src/MockQueryable/MockQueryable.Sample/MyServiceNSubstituteTests.cs
@@ -143,6 +143,20 @@ public async Task DbSetGetUserReports(DateTime from, DateTime to, int expectedCo
Assert.AreEqual(expectedCount, result.Count);
}
+
+ [TestCase]
+ public async Task DbSetGetAllUserEntity()
+ {
+ //arrange
+ var users = CreateUserList();
+ var mock = users.AsQueryable().BuildMockDbSet();
+ var userRepository = new TestDbSetRepository(mock);
+ //act
+ var result = await userRepository.GetAll();
+ //assert
+ Assert.AreEqual(users.Count, result.Count);
+ }
+
[TestCase]
public async Task DbSetGetAllUserEntitiesAsync()
{
diff --git a/src/MockQueryable/MockQueryable.Sample/TestDbSetRepository.cs b/src/MockQueryable/MockQueryable.Sample/TestDbSetRepository.cs
index efabb00..59266d0 100644
--- a/src/MockQueryable/MockQueryable.Sample/TestDbSetRepository.cs
+++ b/src/MockQueryable/MockQueryable.Sample/TestDbSetRepository.cs
@@ -23,8 +23,8 @@ public async Task CreateUser(UserEntity user)
await _dbSet.AddAsync(user);
}
- public List GetAll() {
- return _dbSet.AsQueryable().ToList();
+ public async Task> GetAll() {
+ return await _dbSet.ToListAsync();
}
public IAsyncEnumerable GetAllAsync()