string Name { get; }
Source
Gets the ordinal persona name.
Framework-neutral assertion helpers for AppSurface auth results and ProblemDetails responses.
The helpers throw AppSurfaceTestAuthAssertionException
instead of depending on a specific test framework. They are intended for package smoke tests, consumer examples, and teams that want stable AppSurface auth diagnostics without pulling xUnit into production package references.
AppSurfaceAuthResult HasOutcome(AppSurfaceAuthResult result, AppSurfaceAuthOutcome expectedOutcome, AppSurfaceAuthReason? expectedReason = null)
Verifies an AppSurface auth result outcome and optional reason.
result
expectedOutcome
expectedReason
The inspected result for fluent test code.
JsonElement HasProblemDetails(JsonElement problem, AppSurfaceAuthOutcome expectedOutcome, AppSurfaceAuthReason expectedReason, int expectedStatus, string? expectedPolicyName = null)
Verifies AppSurface auth ProblemDetails extensions.
problem
expectedOutcome
appsurfaceAuthOutcome
extension value.expectedReason
appsurfaceAuthReason
extension value.expectedStatus
expectedPolicyName
appsurfacePolicyName
extension value.The inspected JSON element for fluent test code.
Decorates the host AppSurface policy evaluator with test-only persona diagnostics.
The inner evaluator remains responsible for real ASP.NET Core policy evaluation and AppSurface result mapping. This decorator pre-validates request-level persona selection from the private test transport and also converts late unknown-persona markers set by authentication handlers into setup failures after the inner evaluator runs.
Describes one authenticated persona that the AppSurface auth testing harness can place on a request.
Persona names are matched with ordinal comparison. The subject is added with the configured subject claim type, and additional claims are copied into the generated principal. Do not put secrets, bearer tokens, cookies, or provider credentials in persona claims; this type models the already-authenticated principal a real ASP.NET Core handler would have produced.
string Name { get; }
Source
Gets the ordinal persona name.
string SubjectId { get; }
Source
Gets the subject identifier added to the generated principal.
IReadOnlyList<Claim> Claims { get; }
Source
Gets additional claim snapshots copied into the generated principal.
Exception thrown by framework-neutral AppSurface auth testing assertion helpers.
Stable diagnostic codes emitted by the AppSurface auth testing harness.
Codes are safe to show in test output, troubleshooting documentation, and CI logs. They identify setup mistakes in the harness rather than production authentication decisions.
Configures the AppSurface auth testing harness.
Defaults are intentionally test-host oriented: the scheme name is stable, WebApplicationFactory quickstarts use the test scheme as the default, and production-like environments are blocked. Subject mapping is not changed unless SubjectClaimType
is set.
AppSurfaceTestAuthOptions AddPersona(string name, string subjectId, IEnumerable<Claim>? claims = null)
Adds a persona with the supplied subject and claims.
name
subjectId
claims
The current options instance for chaining.
AppSurfaceTestAuthOptions AddPersona(AppSurfaceTestPersona persona)
Adds a persona definition.
persona
The current options instance for chaining.
string SchemeName { get; set; }
Source
Gets or sets the ASP.NET Core authentication scheme registered for test personas.
AppSurfaceTestAuthSchemeMode SchemeMode { get; set; }
Source
Gets or sets how the test scheme is applied to the host authentication setup.
string? SubjectClaimType { get; set; }
Source
Gets or sets the subject claim type used by generated principals and AppSurface subject mapping.
When this value is null
, the harness leaves host AppSurface subject mapping alone and emits System.Security.Claims.ClaimTypes.NameIdentifier
, matching the first default Auth.AspNetCore
subject claim type.
bool AllowProductionEnvironmentForTestHost { get; set; }
Source
Gets or sets a value indicating whether the harness may run in a production-like environment.
Keep this false for normal tests. Set it only for production-like integration hosts that deliberately use test authentication and never receive real traffic.
IReadOnlyList<AppSurfaceTestPersona> Personas { get; }
Source
Gets the configured immutable persona definitions.
Default names used by the AppSurface auth testing harness.
Stores the immutable per-factory persona lookup used by AppSurface test auth helpers.
Names use ordinal comparison and must be unique after AppSurfaceTestPersona
trimming. Create the registry only after options are fully configured; later option changes are intentionally not observed by an existing registry.
AppSurfaceTestPersonaRegistry Create(AppSurfaceTestAuthOptions options)
Creates a registry from configured personas and validates duplicate ordinal names.
options
An immutable registry snapshot.
InvalidOperationException
AppSurfaceTestPersona Require(string personaName)
Gets a registered persona or throws a setup diagnostic for public helper failures.
personaName
The matching persona.
ArgumentException
personaName
is blank.InvalidOperationException
bool TryGet(string? personaName, out AppSurfaceTestPersona persona)
Attempts to get a persona by ordinal name without throwing for missing, blank, or null values.
personaName
persona
true
when the persona exists; otherwise false
.
Registers AppSurface test authentication services for ASP.NET Core integration tests.
IServiceCollection AddAppSurfaceTestAuth(this IServiceCollection services, Action<AppSurfaceTestAuthOptions>? configure = null)
Adds a test-only authentication scheme and immutable persona registry for AppSurface auth tests.
services
configure
The same service collection for chaining.
This method composes ForgeTrust.AppSurface.Auth.AspNetCore
so normal ASP.NET Core policy evaluation and AppSurface result mapping still run. It does not create production users, identity providers, cookies, tokens, or session freshness checks.
WebApplicationFactory helpers for AppSurface auth testing.
WebApplicationFactory<TEntryPoint> WithAppSurfaceTestAuth<TEntryPoint>(this WebApplicationFactory<TEntryPoint> factory, Action<AppSurfaceTestAuthOptions>? configure = null)
Returns a WebApplicationFactory configured with AppSurface test authentication.
TEntryPoint
factory
configure
A cloned factory with AppSurface test auth registered.
The cloned factory uses the Testing
environment and then registers the harness through AppSurfaceTestAuthServiceCollectionExtensions.AddAppSurfaceTestAuth
.
HttpClient CreateAppSurfaceClient<TEntryPoint>(this WebApplicationFactory<TEntryPoint> factory, string personaName, WebApplicationFactoryClientOptions? options = null)
Creates an HTTP client that selects a configured AppSurface test auth persona for every request.
TEntryPoint
factory
WithAppSurfaceTestAuth{TEntryPoint}
.personaName
options
A client whose default headers select the persona.
Holds the host policy evaluator registration that Auth.Testing decorates.
policyEvaluator
AddAppSurfaceTestAuth
installed test-only diagnostics. IAppSurfaceAspNetCorePolicyEvaluator PolicyEvaluator { get; }
Source
Gets the host evaluator that continues to own real policy evaluation and result mapping.
Request-level helpers for selecting AppSurface test auth personas.
HttpRequestMessage WithAppSurfaceTestPersona(this HttpRequestMessage request, string personaName)
Selects a configured AppSurface test auth persona for a single request.
request
personaName
The same request for chaining.
Prefer CreateAppSurfaceClient(...)
for whole-client persona selection. This helper is for tests that need several personas from one client. The harness still treats no selection as anonymous.
Selects how the AppSurface test authentication scheme is registered with ASP.NET Core.
These modes exist so a test harness cannot silently change host authentication behavior. Use DefaultScheme
for the quickest WebApplicationFactory path, NamedScheme
when policies opt in to a specific scheme, and NoDefault
when the test host must keep every existing default authentication setting untouched. The numeric values are explicit because this public enum may be persisted, serialized, or bound by applications. New values should be appended without changing the values documented here.