Alvecta.Foundation.Application.Ports.Testing 9.0.86

There is a newer version of this package available.
See the version list below for details.
dotnet add package Alvecta.Foundation.Application.Ports.Testing --version 9.0.86
                    
NuGet\Install-Package Alvecta.Foundation.Application.Ports.Testing -Version 9.0.86
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alvecta.Foundation.Application.Ports.Testing" Version="9.0.86" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Alvecta.Foundation.Application.Ports.Testing" Version="9.0.86" />
                    
Directory.Packages.props
<PackageReference Include="Alvecta.Foundation.Application.Ports.Testing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Alvecta.Foundation.Application.Ports.Testing --version 9.0.86
                    
#r "nuget: Alvecta.Foundation.Application.Ports.Testing, 9.0.86"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Alvecta.Foundation.Application.Ports.Testing@9.0.86
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Alvecta.Foundation.Application.Ports.Testing&version=9.0.86
                    
Install as a Cake Addin
#tool nuget:?package=Alvecta.Foundation.Application.Ports.Testing&version=9.0.86
                    
Install as a Cake Tool

Alvecta.Foundation.Application.Ports.Testing

Test support for code written against Alvecta.Foundation.Application.Ports: fakes of the persistence ports. Reference it from a test project only; the Alvecta architecture tests fail a product project that references a *.Testing package.

What it provides

  • InMemoryQueryableRepository<TEntity, TKey>(entities, keySelector) — an IQueryableRepository<TEntity, TKey> over a test's in-memory entities. Query is the entities as an in-memory queryable, read anew on every call; Where, ByKey, GetSingleAsync and ExistsAsync are built on Query the way the EF-backed QueryableRepository builds them, and ByKey looks the key up with the same KeyPredicate (from Application.Ports), so a value-object key matches by value. GetSingleAsync throws InvalidOperationException for an unknown key, like EF's SingleAsync.
  • FixedTenantIdProvider<TTenantId>(tenantId) — an ITenantIdProvider<TTenantId> with a fixed current tenant, never in cross-tenant mode: what a host's request-scoped provider resolves per request, without the request. A multi-tenant context built with it (in an integration test over SqliteTestDatabase from Alvecta.Foundation.Infrastructure.EF.Testing, say) reads and writes that tenant's rows only.

It replaces the SetupReads Moq helper of the 6.3 packages (removed in 7.0): the package no longer references Moq.

Usage

dotnet add package Alvecta.Foundation.Application.Ports.Testing

Import the namespace once for the whole test project, in GlobalUsings.cs:

global using Alvecta.Foundation.Application.Ports.Testing;

or in the test projects' Directory.Build.props:

<ItemGroup>
  <Using Include="Alvecta.Foundation.Application.Ports.Testing" />
</ItemGroup>

Then hand the query session the fake, built from the test's data and the entity's key:

var orders = new InMemoryQueryableRepository<OrderView, OrderId>([pending, shipped], o => o.Id);
querySession.Setup(s => s.Orders).Returns(orders);

orders.ByKey(pending.Id);                           // pending
orders.Where(o => o.Status == OrderStatus.Shipped); // shipped

Limitations

  • In-memory LINQ is not EF. A query EF cannot translate (.Value on a value object inside Where, the keyed *By set operators) still passes against the fake; only integration tests catch it. Nor does the fake reproduce EF-side guards such as a QuerySchema entity failing to materialize: GetSingleAsync returns the entity as given.
  • Async terminals. Query services that run FirstOrDefaultAsync and the like through Alvecta.Utils.Queryable's QueryableAsyncExtensions still need a synchronous IQueryableAsyncHelper registered in the test project: SynchronousQueryableAsyncHelper from Alvecta.Utils.Queryable.Testing, through QueryableAsyncExtensions.UseAsyncHelper, typically in a [ModuleInitializer]. The fake replaces the repository, not that helper.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.6.96 0 11/25/2026
9.6.95 0 11/25/2026
9.6.94 48 11/24/2026
9.6.93 50 11/24/2026
9.5.92 59 11/24/2026
9.4.91 101 11/20/2026
9.3.90 95 11/13/2026
9.2.89 104 11/12/2026
9.1.88 97 11/11/2026
9.0.87 90 11/4/2026
9.0.86 84 11/4/2026
9.0.85 93 11/4/2026
9.0.84 96 11/4/2026
9.0.83 109 10/29/2026
9.0.82 104 10/29/2026
8.1.81 100 10/29/2026
8.0.80 101 10/28/2026
8.0.79 96 10/28/2026
8.0.78 111 10/28/2026
8.0.77 100 10/28/2026
Loading failed