Class ScopedTest<TEntryPoint, TFactory>
- Namespace
- XBullet.EasyTesting.Hosting
- Assembly
- XBullet.EasyTesting.dll
Provides a factory and an isolated scope runner for integration-test classes.
public abstract class ScopedTest<TEntryPoint, TFactory> where TEntryPoint : class where TFactory : AuthenticatedWebApplicationFactory<TEntryPoint>
Type Parameters
TEntryPointThe application entry-point type used by the factory.
TFactoryThe concrete factory type, including any test-project-specific helpers.
- Inheritance
-
ScopedTest<TEntryPoint, TFactory>
- Inherited Members
- Extension Methods
Remarks
This base is independent of test frameworks. The caller owns the factory, and each
RunAsync call creates and cleans up a fresh scenario scope using the factory's existing
runner. No scope is stored on the test class between calls.
Constructors
ScopedTest(TFactory, CancellationToken)
Creates a test base that borrows a factory and a test cancellation token.
protected ScopedTest(TFactory factory, CancellationToken cancellationToken = default)
Parameters
factoryTFactoryThe non-null caller-owned factory. This base never disposes it.
cancellationTokenCancellationTokenThe token used by every scope run on this instance. Pass the test framework's current test token when available. The default token does not request cancellation.
Exceptions
- ArgumentNullException
factoryis null.
Properties
Factory
Gets the factory and its test-project-specific helpers.
protected TFactory Factory { get; }
Property Value
- TFactory
The borrowed factory supplied to the constructor. The caller owns and disposes it.
TestCancellationToken
Gets the token passed to scope creation and test callbacks.
protected CancellationToken TestCancellationToken { get; }
Property Value
- CancellationToken
The token supplied to the constructor, or a non-cancelable token when omitted.
Methods
RunAsync(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task>)
Runs a test in a fresh scope using factory-level configuration.
protected Task RunAsync(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task> test)
Parameters
testFunc<TestScenarioScope<TEntryPoint>, CancellationToken, Task>The non-null callback borrowing the new scope and test cancellation token.
Returns
- Task
A task that completes after the callback and scope cleanup finish.
Exceptions
- ArgumentNullException
testis null.
RunAsync(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task>, Action<TestScenarioScopeBuilder>?)
Runs a test in a fresh isolated scope and captures failure diagnostics before cleanup.
protected Task RunAsync(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task> test, Action<TestScenarioScopeBuilder>? configure)
Parameters
testFunc<TestScenarioScope<TEntryPoint>, CancellationToken, Task>The non-null callback invoked once with the new scope and TestCancellationToken. The scope is borrowed for the callback's lifetime and must not escape it.
configureAction<TestScenarioScopeBuilder>Configures the new scope's service, configuration, and resource overrides. When null, factory-level configuration is used.
Returns
- Task
A task that completes after the callback and scope cleanup finish.
Remarks
Runs through the factory's scenario gate. On failure or cancellation, diagnostics and cleanup use a non-cancelable token, and the original test exception is preserved.
Exceptions
- ArgumentNullException
testis null.
RunAsync<TResult>(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task<TResult>>)
Runs a test function in a fresh scope using factory-level configuration.
protected Task<TResult> RunAsync<TResult>(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task<TResult>> test)
Parameters
testFunc<TestScenarioScope<TEntryPoint>, CancellationToken, Task<TResult>>The non-null callback borrowing the new scope and test cancellation token.
Returns
- Task<TResult>
The callback's value after scope cleanup finishes.
Type Parameters
TResultThe detached value produced by the test function.
Exceptions
- ArgumentNullException
testis null.
RunAsync<TResult>(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task<TResult>>, Action<TestScenarioScopeBuilder>?)
Runs a test function in a fresh isolated scope and returns its value after cleanup.
protected Task<TResult> RunAsync<TResult>(Func<TestScenarioScope<TEntryPoint>, CancellationToken, Task<TResult>> test, Action<TestScenarioScopeBuilder>? configure)
Parameters
testFunc<TestScenarioScope<TEntryPoint>, CancellationToken, Task<TResult>>The non-null callback invoked once with the new scope and TestCancellationToken. Return detached data; the scope and its services or resources are disposed before this method completes.
configureAction<TestScenarioScopeBuilder>Configures the new scope's service, configuration, and resource overrides. When null, factory-level configuration is used.
Returns
- Task<TResult>
The callback's value after scope cleanup finishes.
Type Parameters
TResultThe value produced by the test function.
Remarks
Uses the same gate, failure diagnostics, cancellation, and cleanup behavior as the non-result overload.
Exceptions
- ArgumentNullException
testis null.