Class AspireTestApplication<TAppHost>
- Namespace
- XBullet.EasyTesting.Aspire
- Assembly
- XBullet.EasyTesting.Aspire.dll
Owns a running closed-box Aspire distributed application.
public sealed class AspireTestApplication<TAppHost> : IAsyncDisposable where TAppHost : class
Type Parameters
TAppHostThe AppHost entry-point type used to create the distributed application.
- Inheritance
-
AspireTestApplication<TAppHost>
- Implements
- Inherited Members
Remarks
Dispose this instance to stop the application and release its testing builder. The native application exposed by Application is owned by this instance and must not be disposed separately.
Properties
Application
Gets the native running Aspire distributed application.
public DistributedApplication Application { get; }
Property Value
- DistributedApplication
The running application owned by this wrapper. Callers may use it but must not dispose it separately.
Diagnostics
Gets diagnostics captured by RunAsync(Func<AspireTestApplication<TAppHost>, CancellationToken, Task>, CancellationToken).
public AspireApplicationDiagnostics? Diagnostics { get; }
Property Value
- AspireApplicationDiagnostics
The failure diagnostics captured by
RunAsync, or null until a test failure has been captured. The snapshot can be retained after this application is disposed.
ResourceNames
Gets the names of resources in the AppHost model.
public IReadOnlyList<string> ResourceNames { get; }
Property Value
- IReadOnlyList<string>
A newly allocated snapshot of resource names in AppHost model order. The caller owns the returned list and may retain it.
Methods
CaptureDiagnosticsAsync(CancellationToken)
Captures current resource states and bounded recent logs.
public ValueTask<AspireApplicationDiagnostics> CaptureDiagnosticsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token that cancels log enumeration. The default token does not request cancellation.
Returns
- ValueTask<AspireApplicationDiagnostics>
A value task whose result is a new diagnostics snapshot that the caller may retain. It includes at most the configured number of recent log lines per resource; zero disables log capture. Connection strings and endpoint values are excluded, but log content is not redacted.
CreateHttpClient(string)
Creates an HTTP client for a resource's preferred HTTP endpoint.
public HttpClient CreateHttpClient(string resourceName)
Parameters
resourceNamestringThe name of a configured resource with a preferred HTTP endpoint. Aspire validates the name and endpoint availability.
Returns
- HttpClient
A new HTTP client that the caller owns and must dispose.
CreateHttpClient(string, string)
Creates an HTTP client for a named resource endpoint.
public HttpClient CreateHttpClient(string resourceName, string endpointName)
Parameters
resourceNamestringThe name of a configured resource. Aspire validates the name and endpoint availability.
endpointNamestringThe non-empty name of the endpoint to use.
Returns
- HttpClient
A new HTTP client that the caller owns and must dispose.
DisposeAsync()
Stops the application and releases the native application and testing builder.
public ValueTask DisposeAsync()
Returns
- ValueTask
A value task that completes after both owned resources have been given a chance to dispose. Repeated calls have no effect; multiple cleanup failures are reported as an aggregate exception.
GetConnectionStringAsync(string, CancellationToken)
Gets a resource connection string without exposing it in diagnostics.
public ValueTask<string?> GetConnectionStringAsync(string resourceName, CancellationToken cancellationToken = default)
Parameters
resourceNamestringThe name of the configured resource whose connection string should be resolved. Aspire validates the resource name.
cancellationTokenCancellationTokenA token that cancels connection-string resolution. The default token does not request cancellation.
Returns
- ValueTask<string>
A value task whose result is the configured connection string, or null when no connection string is available. The returned value can contain secrets; callers must protect it and must not assume that diagnostics redact copies they write to logs.
GetEndpoint(string)
Gets a resource's preferred endpoint.
public Uri GetEndpoint(string resourceName)
Parameters
resourceNamestringThe name of a configured resource with a preferred endpoint. Aspire validates the name and endpoint availability.
Returns
- Uri
The endpoint URI reported by Aspire. The immutable URI may be retained by the caller.
GetEndpoint(string, string)
Gets a named resource endpoint.
public Uri GetEndpoint(string resourceName, string endpointName)
Parameters
resourceNamestringThe name of a configured resource. Aspire validates the name and endpoint availability.
endpointNamestringThe non-empty name of the endpoint to retrieve.
Returns
- Uri
The endpoint URI reported by Aspire. The immutable URI may be retained by the caller.
WaitForResourceAsync(string, CancellationToken)
Waits until a named resource is healthy or becomes unavailable.
public Task WaitForResourceAsync(string resourceName, CancellationToken cancellationToken = default)
Parameters
resourceNamestringThe non-empty name of the configured resource to monitor.
cancellationTokenCancellationTokenA token that cancels the wait. The default token does not request cancellation.
Returns
- Task
A task that completes when the resource becomes healthy and faults if it becomes unavailable.