Class TestcontainerResource<TContainer>
- Namespace
- XBullet.EasyTesting.Testcontainers
- Assembly
- XBullet.EasyTesting.Testcontainers.dll
Owns a Testcontainers container for one scenario and publishes values after it is ready.
public sealed class TestcontainerResource<TContainer> : ITestScenarioEnvironmentResource, IAsyncDisposable where TContainer : class, IContainer
Type Parameters
TContainerThe concrete Testcontainers container type owned by this resource.
- Inheritance
-
TestcontainerResource<TContainer>
- Implements
- Inherited Members
Constructors
TestcontainerResource(TContainer, Func<TContainer, IReadOnlyDictionary<string, string?>>?, Action<TContainer, IServiceCollection>?, int)
Creates a scenario-owned container resource.
public TestcontainerResource(TContainer container, Func<TContainer, IReadOnlyDictionary<string, string?>>? configurationValues = null, Action<TContainer, IServiceCollection>? configureServices = null, int maximumDiagnosticCharacters = 20000)
Parameters
containerTContainerThe non-null, unstarted container whose ownership transfers to this resource immediately. It is disposed even if it is never started.
configurationValuesFunc<TContainer, IReadOnlyDictionary<string, string>>An optional callback invoked by ConfigureConfiguration(IConfigurationBuilder) after readiness. It must return a non-null dictionary with non-empty keys; null values are accepted. The callback must not dispose the container. The default publishes no values.
configureServicesAction<TContainer, IServiceCollection>An optional callback invoked by ConfigureServices(IServiceCollection) after the container is registered as a singleton. It may update services in place but must not retain the collection or dispose the container.
maximumDiagnosticCharactersintThe non-negative maximum trailing character count retained independently for standard output and standard error. The default is 20,000 characters; zero retains empty log strings.
Properties
Container
Gets the native Testcontainers container.
public TContainer Container { get; }
Property Value
- TContainer
The container owned by this resource. Callers may use it until resource disposal but must not dispose it separately.
Methods
CaptureDiagnosticsAsync(CancellationToken)
Captures container identity, state, ports, and bounded standard output and error.
public ValueTask<object?> CaptureDiagnosticsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token passed to log retrieval. The default token does not request cancellation. Cancellation is propagated; other log failures are represented in the returned diagnostics.
Returns
- ValueTask<object>
A value task whose result reports only
Started = falsebefore startup. After startup it includes identity, image, hostname, state, health, mapped ports, the trailing configured number of log characters, and any log-capture error. Logs and error text are not redacted and may contain sensitive data; published configuration values are excluded.
ConfigureConfiguration(IConfigurationBuilder)
Adds values resolved from the ready container to application configuration.
public void ConfigureConfiguration(IConfigurationBuilder configuration)
Parameters
configurationIConfigurationBuilderThe non-null mutable configuration builder to update in place. The published values are resolved on this call and may contain secrets; they are not included in resource diagnostics.
ConfigureServices(IServiceCollection)
Registers the native container and applies optional scenario service overrides.
public void ConfigureServices(IServiceCollection services)
Parameters
servicesIServiceCollectionThe non-null mutable scenario service collection. The container is added as a singleton before the optional service callback runs; the scenario retains container disposal ownership.
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.
StartAsync(CancellationToken)
Starts the container and waits for its configured readiness strategy.
public ValueTask StartAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token passed to Testcontainers startup and readiness operations. The default token does not request cancellation.
Returns
- ValueTask
A value task that completes when the container is ready. A successful start may occur only once; a failed or canceled start leaves the resource eligible for another attempt.