Class TestScenarioScope<TEntryPoint>

Namespace
XBullet.EasyTesting.Hosting
Assembly
XBullet.EasyTesting.dll

Owns the isolated host and mutable test state used by one integration-test scenario.

public sealed class TestScenarioScope<TEntryPoint> : IAsyncDisposable where TEntryPoint : class

Type Parameters

TEntryPoint

The application entry-point type used by WebApplicationFactory<TEntryPoint>.

Inheritance
TestScenarioScope<TEntryPoint>
Implements
Inherited Members
Extension Methods

Remarks

Properties

AuthenticationEvents

Gets authentication events captured from real handlers in this scenario.

public TestAuthenticationEventRecorder AuthenticationEvents { get; }

Property Value

TestAuthenticationEventRecorder

The factory-owned event recorder shared with the configured authentication handlers. The caller must not dispose it.

Diagnostics

Gets diagnostics captured for a failed scenario, when available.

public TestScenarioDiagnostics? Diagnostics { get; }

Property Value

TestScenarioDiagnostics

The captured diagnostics after a scenario failure, or null before a failure has been captured. The scope owns the diagnostic object.

ScenarioId

Gets the unique identifier for this scenario.

public string ScenarioId { get; }

Property Value

string

A non-empty identifier that remains stable for the lifetime of this scope.

Services

Gets services from the scenario-specific host.

public IServiceProvider Services { get; }

Property Value

IServiceProvider

The root service provider owned by this scope's host. The caller must not dispose it.

Methods

Client()

Starts a fluent client definition for the isolated scenario host.

public TestClientBuilder<TEntryPoint> Client()

Returns

TestClientBuilder<TEntryPoint>

A new mutable client builder. Clients produced by the builder are owned by the caller.

CreateAnonymousClient(WebApplicationFactoryClientOptions?)

Creates an anonymous client from the isolated scenario host.

public HttpClient CreateAnonymousClient(WebApplicationFactoryClientOptions? options = null)

Parameters

options WebApplicationFactoryClientOptions

Client options to apply. When null, the host's default client options are used. The options object is read but not owned or mutated by this method.

Returns

HttpClient

A new anonymous client connected to the scenario host. The caller owns and must dispose the client.

CreateAuthenticatedClient(TestUser?, WebApplicationFactoryClientOptions?)

Creates an authenticated client from the isolated scenario host.

public HttpClient CreateAuthenticatedClient(TestUser? user = null, WebApplicationFactoryClientOptions? options = null)

Parameters

user TestUser

The simulated identity sent by the client. When null, a default authenticated test user is created. The supplied user is read but not owned or mutated.

options WebApplicationFactoryClientOptions

Client options to apply. When null, the host's default client options are used. The options object is read but not owned or mutated by this method.

Returns

HttpClient

A new authenticated client connected to the scenario host. The caller owns and must dispose the client.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

GetEnvironmentResource<TResource>(string)

Gets a named external dependency created for this scenario.

public TResource GetEnvironmentResource<TResource>(string name) where TResource : class, ITestScenarioEnvironmentResource

Parameters

name string

The non-empty registered resource name. Matching is case-insensitive.

Returns

TResource

The scenario-owned resource registered under name. The caller must not dispose it.

Type Parameters

TResource

The expected concrete environment-resource type.

Exceptions

KeyNotFoundException

No environment resource is registered with name.

InvalidOperationException

The named resource is not assignable to TResource.

JwtAuthority(string?)

Gets a configured local JWT authority, optionally by authentication scheme.

public TestJwtAuthority JwtAuthority(string? authenticationScheme = null)

Parameters

authenticationScheme string

The exact registered authentication scheme to select. When null, the default local JWT authority is returned.

Returns

TestJwtAuthority

The factory-owned authority for the selected scheme. The caller must not dispose it.

Scenario()

Starts a fluent arrange, client, and HTTP request definition in this scope.

public TestScenarioBuilder<TEntryPoint> Scenario()

Returns

TestScenarioBuilder<TEntryPoint>

A new mutable scenario builder associated with this scope's isolated host.