Soenneker.Extensions.WebApplicationFactories
4.0.331
Prefix Reserved
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
<PackageReference Include="Soenneker.Extensions.WebApplicationFactories" Version="4.0.331" />
<PackageVersion Include="Soenneker.Extensions.WebApplicationFactories" Version="4.0.331" />
<PackageReference Include="Soenneker.Extensions.WebApplicationFactories" />
paket add Soenneker.Extensions.WebApplicationFactories --version 4.0.331
#r "nuget: Soenneker.Extensions.WebApplicationFactories, 4.0.331"
#:package Soenneker.Extensions.WebApplicationFactories@4.0.331
#addin nuget:?package=Soenneker.Extensions.WebApplicationFactories&version=4.0.331
#tool nuget:?package=Soenneker.Extensions.WebApplicationFactories&version=4.0.331
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 | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Mvc.Testing (>= 10.0.11)
- Soenneker.Enums.DeployEnvironment (>= 4.0.236)
- Soenneker.Extensions.Enumerable.String (>= 4.0.1428)
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 |
Update dependency Soenneker.Extensions.Enumerable.String to 4.0.1428 (#717)