MockAsyncEnumerable 3.0.0.3872
dotnet add package MockAsyncEnumerable --version 3.0.0.3872
NuGet\Install-Package MockAsyncEnumerable -Version 3.0.0.3872
<PackageReference Include="MockAsyncEnumerable" Version="3.0.0.3872" />
<PackageVersion Include="MockAsyncEnumerable" Version="3.0.0.3872" />
<PackageReference Include="MockAsyncEnumerable" />
paket add MockAsyncEnumerable --version 3.0.0.3872
#r "nuget: MockAsyncEnumerable, 3.0.0.3872"
#:package MockAsyncEnumerable@3.0.0.3872
#addin nuget:?package=MockAsyncEnumerable&version=3.0.0.3872
#tool nuget:?package=MockAsyncEnumerable&version=3.0.0.3872
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.
Root namespace:
RzR.Extensions.EntityMock(with sub-namespaces.Abstractions,.Extensions,.Faults,.Helpers).
Features
- Convert
IEnumerable<T>,IQueryable<T>, and arrays toIAsyncEnumerable<T>/IQueryable<T>; - Public APIs return the
IMockAsyncEnumerable<T>abstraction (combinesIAsyncEnumerable<T>+IQueryable<T>); - Builder pattern for fluent async enumerable construction;
- Factory methods for quick creation (
Empty,Single,Create); - Fault injection on the builder: artificial latency, throw-at-index, and time-based cancellation — useful for testing retry, timeout and cancellation logic;
- Full support for LINQ async operations (
Where,Select,OrderBy, etc.); - Comprehensive null guards and error handling;
- Proper cancellation token support (linked tokens for combined caller / internal cancellation);
- Optimized disposal patterns (
IAsyncDisposable); - Multi-target:
netstandard2.0,netstandard2.1,net5.0–net9.0.
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 RzR.Extensions.EntityMock.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 RzR.Extensions.EntityMock;
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 RzR.Extensions.EntityMock;
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();
Fault Injection (latency, exceptions, cancellation)
The builder can inject realistic failure modes so tests can exercise retry, timeout and cancellation paths in production code without changing it:
using RzR.Extensions.EntityMock;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
var slow = AsyncEnumerableFactory.Builder<User>()
.AddRange(users)
.WithDelay(TimeSpan.FromMilliseconds(50)) // per-item latency
.ThrowAfter(3, _ => new DbUpdateException("forced")) // throw at index 3
.CancelAfter(TimeSpan.FromSeconds(1)) // internal cancel
.Build();
// Caller-supplied cancellation token is honored alongside the internal one.
await foreach (var u in slow.WithCancellation(ct)) { /* ... */ }
Available builder fault APIs:
| Method | Description |
|---|---|
WithDelay(TimeSpan) |
Awaits the delay before every MoveNextAsync call |
ThrowAfter(int, Exception) |
Throws the supplied exception when the given index is reached |
ThrowAfter(int, Func<int, Exception>) |
Same, but the factory receives the triggering index |
CancelAfter(TimeSpan) |
Starts an internal CancellationTokenSource linked with the caller token |
Using EnumerableInvoker (deprecated)
!!!
EnumerableInvokeris marked[Obsolete]and will be removed in the next major version. PreferAsyncEnumerableFactory, theToMockAsyncEnumerable()extension methods, orAsyncEnumerableBuilder<T>.
using RzR.Extensions.EntityMock;
using Microsoft.EntityFrameworkCore;
var data = new List<User>
{
new User { Id = 1, Name = "Alice" },
new User { Id = 2, Name = "Bob" }
};
#pragma warning disable CS0618
var asyncEnumerable = EnumerableInvoker.Invoke(data);
#pragma warning restore CS0618
var result = await asyncEnumerable.FirstOrDefaultAsync(u => u.Name == "Alice");
API Reference
All factory / builder / extension methods now return
IMockAsyncEnumerable<T>(defined inRzR.Extensions.EntityMock.Abstractions), which extends bothIAsyncEnumerable<T>andIQueryable<T>.
Abstraction (RzR.Extensions.EntityMock.Abstractions)
| Type | Description |
|---|---|
IMockAsyncEnumerable<T> |
Public, stable surface — combines IAsyncEnumerable<T> + IQueryable<T> |
Extension Methods (RzR.Extensions.EntityMock.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) |
WithDelay(TimeSpan delay) |
Configures per-item async latency (fluent) |
ThrowAfter(int, Exception) |
Throws at the configured zero-based index (fluent) |
ThrowAfter(int, Func<int, Exception>) |
Same, with index-aware factory (fluent) |
CancelAfter(TimeSpan) |
Cancels iteration after the duration (fluent) |
Build() |
Snapshots items and creates the async enumerable |
Clear() |
Resets items and fault settings |
Classic Approach (EnumerableInvoker) — deprecated
| Method | Description |
|---|---|
Invoke<T>(IEnumerable<T>) |
[Obsolete] — use ToMockAsyncEnumerable() instead |
| 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 |
|---|---|---|
| 3.0.0.3872 | 38 | 4/24/2026 |
| 2.0.0.6582 | 167 | 3/13/2026 |
| 1.1.0 | 830 | 1/10/2025 |
| 1.0.3.6469 | 9,981 | 12/27/2023 |
| 1.0.2.1050 | 3,091 | 11/9/2023 |
| 1.0.1.1250 | 977 | 10/19/2023 |
| 1.0.0 | 2,628 | 4/28/2023 |