Soenneker.Extensions.WebApplicationFactories 4.0.331

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Extensions.WebApplicationFactories --version 4.0.331
                    
NuGet\Install-Package Soenneker.Extensions.WebApplicationFactories -Version 4.0.331
                    
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="Soenneker.Extensions.WebApplicationFactories" Version="4.0.331" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.WebApplicationFactories" Version="4.0.331" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.WebApplicationFactories" />
                    
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 Soenneker.Extensions.WebApplicationFactories --version 4.0.331
                    
#r "nuget: Soenneker.Extensions.WebApplicationFactories, 4.0.331"
                    
#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 Soenneker.Extensions.WebApplicationFactories@4.0.331
                    
#: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=Soenneker.Extensions.WebApplicationFactories&version=4.0.331
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.WebApplicationFactories&version=4.0.331
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Extensions.WebApplicationFactories

Create an integration-test HttpClient configured for either a real bearer token or Soenneker's test-authentication headers.

Installation

dotnet add package Soenneker.Extensions.WebApplicationFactories

Use test authentication

using Soenneker.Extensions.WebApplicationFactories;

using HttpClient client = factory.CreateTestHttpClient(
    userId: "user-42",
    email: "ada@example.com",
    userRoles: ["Admin", "Support"]);

HttpResponseMessage response = await client.GetAsync("/api/account");

Without a JWT, the client sends:

Authorization: Test
AuthorizationUserId: user-42
AuthorizationEmail: ada@example.com
AuthorizationRoles: Admin,Support

Null and empty identity values are omitted. Roles are joined with commas in the supplied order. Header values use the runtime's validated header API, so values containing invalid newline characters are rejected rather than sent.

The application under test must explicitly register a test authentication handler that understands this scheme and these headers. These headers do not authenticate a client by themselves. Never enable a header-trusting test handler in a production environment.

Use a bearer token

using HttpClient client = factory.CreateTestHttpClient(jwt: accessToken);

When jwt has content, it takes precedence: the client sends Authorization: Bearer <token> and none of the custom identity headers. The helper does not create or validate the token.

Each call uses WebApplicationFactory<T>.CreateClient() and returns a new client owned by the caller. Dispose the client after the test. The factory still controls the in-memory test server and its configured client options.

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 (1)

Showing the top 1 NuGet packages that depend on Soenneker.Extensions.WebApplicationFactories:

Package Downloads
Soenneker.Tests.Integration

A TUnit base class for integration tests that use a shared WebApplicationFactory host.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.334 70 8/31/2026
4.0.332 63 8/31/2026
4.0.331 58 8/31/2026
4.0.330 46 8/30/2026
4.0.329 56 8/30/2026
4.0.328 86 8/30/2026
4.0.327 52 8/30/2026
4.0.326 75 8/30/2026
4.0.325 48 8/30/2026
4.0.323 75 8/29/2026
4.0.322 156 8/26/2026
4.0.321 120 8/25/2026
4.0.320 127 8/21/2026
4.0.319 129 8/21/2026
4.0.318 189 8/18/2026
4.0.317 118 8/18/2026
4.0.316 123 8/18/2026
4.0.315 136 8/12/2026
4.0.314 135 8/11/2026
4.0.313 169 8/8/2026
Loading failed

Update dependency Soenneker.Extensions.Enumerable.String to 4.0.1428 (#717)