MockAsyncEnumerable 2.0.0.6582
dotnet add package MockAsyncEnumerable --version 2.0.0.6582
NuGet\Install-Package MockAsyncEnumerable -Version 2.0.0.6582
<PackageReference Include="MockAsyncEnumerable" Version="2.0.0.6582" />
<PackageVersion Include="MockAsyncEnumerable" Version="2.0.0.6582" />
<PackageReference Include="MockAsyncEnumerable" />
paket add MockAsyncEnumerable --version 2.0.0.6582
#r "nuget: MockAsyncEnumerable, 2.0.0.6582"
#:package MockAsyncEnumerable@2.0.0.6582
#addin nuget:?package=MockAsyncEnumerable&version=2.0.0.6582
#tool nuget:?package=MockAsyncEnumerable&version=2.0.0.6582
A simple implementation for transforming synchronous collections into async enumerables, enabling seamless testing of EF Core queries, paginated grids, and LINQ operations, or any action or dynamic aggregated query using EF Core (Microsoft.EntityFrameworkCore) through Expressions (System.Linq.Expressions) with IAsyncEnumerable<T>.
This library was born from the necessity to implement paged grid results in projects where data was provided by stored procedures or in-memory collections, while still needing to support async EF Core APIs like ToListAsync(), FirstOrDefaultAsync(), etc.
Features
- Convert
IEnumerable<T>,IQueryable<T>, and arrays toIAsyncEnumerable<T>; - Builder pattern for fluent async enumerable construction;
- Factory methods for quick creation (Empty, Single, Create);
- Full support for LINQ async operations (Where, Select, OrderBy, etc.);
- Comprehensive null guards and error handling;
- Proper cancellation token support;
- Optimized disposal patterns (IAsyncDisposable);
- Extensive test coverage;
- Compatible with EF Core testing scenarios;
Installation
In case you wish to use it in your project, u can install the package from <a href="https://www.nuget.org/packages/MockAsyncEnumerable" target="_blank">nuget.org</a> or specify what version you want:
Install-Package MockAsyncEnumerable
Or specify a version:
Install-Package MockAsyncEnumerable -Version x.x.x.x
Examples
Using Extension Methods
using MockAsyncEnumerable.Extensions;
using Microsoft.EntityFrameworkCore;
// Convert a list to async enumerable
var users = new List<User>
{
new User { Id = 1, Name = "Alice" },
new User { Id = 2, Name = "Bob" }
};
var asyncUsers = users.ToMockAsyncEnumerable();
var result = await asyncUsers.Where(u => u.Id > 1).ToListAsync();
Using Factory Methods
using MockAsyncEnumerable;
using Microsoft.EntityFrameworkCore;
// Create empty async enumerable
var empty = AsyncEnumerableFactory.Empty<User>();
// Create from single item
var single = AsyncEnumerableFactory.Single(new User { Id = 1, Name = "Alice" });
// Create from multiple items
var multiple = AsyncEnumerableFactory.Create(
new User { Id = 1, Name = "Alice" },
new User { Id = 2, Name = "Bob" }
);
var users = await multiple.ToListAsync();
Using Builder Pattern
using MockAsyncEnumerable;
using Microsoft.EntityFrameworkCore;
// Build an async enumerable fluently
var users = AsyncEnumerableFactory.Builder<User>()
.Add(new User { Id = 1, Name = "Alice" })
.Add(new User { Id = 2, Name = "Bob" })
.AddRange(moreUsers)
.Build();
var result = await users.ToListAsync();
Using EnumerableInvoker
using MockAsyncEnumerable;
using Microsoft.EntityFrameworkCore;
var data = new List<User>
{
new User { Id = 1, Name = "Alice" },
new User { Id = 2, Name = "Bob" }
};
var asyncEnumerable = EnumerableInvoker.Invoke(data);
var result = await asyncEnumerable.FirstOrDefaultAsync(u => u.Name == "Alice");
API Reference
Extension Methods (MockAsyncEnumerable.Extensions)
| Method | Description |
|---|---|
ToMockAsyncEnumerable<T>(this IEnumerable<T>) |
Converts any enumerable to async enumerable |
ToMockAsyncEnumerable<T>(this IQueryable<T>) |
Converts queryable to async enumerable |
ToMockAsyncEnumerable<T>(this T[]) |
Converts array to async enumerable |
Factory Methods (AsyncEnumerableFactory)
| Method | Description |
|---|---|
Empty<T>() |
Creates an empty async enumerable |
Single<T>(T item) |
Creates async enumerable with single item |
Create<T>(params T[] items) |
Creates async enumerable from items |
Builder<T>() |
Returns a new builder instance |
Builder Pattern (AsyncEnumerableBuilder<T>)
| Method | Description |
|---|---|
Add(T item) |
Adds a single item (fluent) |
AddRange(IEnumerable<T> items) |
Adds multiple items (fluent) |
Build() |
Creates the async enumerable |
Clear() |
Resets the builder |
Classic Approach (EnumerableInvoker)
| Method | Description |
|---|---|
Invoke<T>(IEnumerable<T>) |
Converts enumerable to async enumerable |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.EntityFrameworkCore (>= 3.1.32)
- System.Linq.Queryable (>= 4.3.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.1
- Microsoft.EntityFrameworkCore (>= 5.0.0)
- System.Linq.Queryable (>= 4.3.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net5.0
- Microsoft.EntityFrameworkCore (>= 5.0.17)
- System.Linq.Queryable (>= 4.3.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.0)
- System.Linq.Queryable (>= 4.3.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net7.0
- Microsoft.EntityFrameworkCore (>= 7.0.0)
- System.Linq.Queryable (>= 4.3.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- System.Linq.Queryable (>= 4.3.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- System.Linq.Queryable (>= 4.3.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MockAsyncEnumerable:
| Package | Downloads |
|---|---|
|
PagedListResult
An extension that offers the possibility to get/return data set as a list with pagination with filter, order, and search availability, loading the list with page size. Available methods: GetPaged/Async, GetPagedWithMainFiltersAsync, GetPagedWithFiltersAsync. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0.6582 | 85 | 3/13/2026 |
| 1.1.0 | 784 | 1/10/2025 |
| 1.0.3.6469 | 9,667 | 12/27/2023 |
| 1.0.2.1050 | 2,887 | 11/9/2023 |
| 1.0.1.1250 | 974 | 10/19/2023 |
| 1.0.0 | 2,625 | 4/28/2023 |