Class AssemblyFixtureCoordinator
- Namespace
- TinyBDD
- Assembly
- TinyBDD.dll
Coordinates the lifecycle of assembly-wide fixtures across the entire test assembly.
public sealed class AssemblyFixtureCoordinator
- Inheritance
-
AssemblyFixtureCoordinator
- Inherited Members
Remarks
This coordinator discovers all AssemblySetupAttribute declarations, instantiates the corresponding AssemblyFixture types, and manages their setup and teardown lifecycle.
The coordinator ensures that:
- Fixtures are initialized exactly once before any tests run.
- Fixtures are torn down exactly once after all tests complete.
- Multiple fixtures execute in registration order.
- Fixture state is accessible via GetFixture<T>().
This is a framework-agnostic singleton that integrates with xUnit, NUnit, and MSTest via their respective assembly fixture mechanisms.
Properties
Instance
Gets the singleton instance of the coordinator.
public static AssemblyFixtureCoordinator Instance { get; }
Property Value
Methods
GetFixture<T>()
Retrieves a registered assembly fixture by type.
public static T GetFixture<T>() where T : AssemblyFixture
Returns
- T
The registered instance of the fixture.
Type Parameters
TThe type of assembly fixture to retrieve.
Remarks
This method provides convenient access to assembly fixtures from within tests.
Exceptions
- InvalidOperationException
Thrown if the fixture has not been registered or initialized.
InitializeAsync(Assembly, IBddReporter?, CancellationToken)
Discovers and initializes all assembly fixtures from the specified assembly.
public Task InitializeAsync(Assembly assembly, IBddReporter? reporter = null, CancellationToken ct = default)
Parameters
assemblyAssemblyThe assembly to scan for AssemblySetupAttribute declarations.
reporterIBddReporterOptional reporter for Gherkin-style logging.
ctCancellationTokenOptional cancellation token.
Returns
- Task
A task representing the asynchronous initialization operation.
Remarks
This method is idempotent - calling it multiple times has no effect after the first call.
TeardownAsync(CancellationToken)
Tears down all initialized assembly fixtures.
public Task TeardownAsync(CancellationToken ct = default)
Parameters
ctCancellationTokenOptional cancellation token.
Returns
- Task
A task representing the asynchronous teardown operation.
Remarks
Fixtures are torn down in reverse order of their initialization. This method is idempotent - calling it multiple times has no effect after the first call.