Class Scenario<TEntryPoint>
- Namespace
- XBullet.EasyTesting.Hosting
- Assembly
- XBullet.EasyTesting.dll
Provides a single-use arrangement lifecycle for a test-project-specific domain scenario.
public abstract class Scenario<TEntryPoint> where TEntryPoint : class
Type Parameters
TEntryPointThe application entry-point type of the borrowed scenario scope.
- Inheritance
-
Scenario<TEntryPoint>
- Inherited Members
- Extension Methods
Remarks
The caller owns the scope and must keep it alive throughout arrangement and subsequent operations. Use ArrangeAsync(CancellationToken) for workflows with multiple operations, or Arrange() to attach arrangement to one HTTP request. Instances are mutable and must not be used concurrently.
Constructors
Scenario(TestScenarioScope<TEntryPoint>)
Creates a domain scenario associated with an existing isolated scope.
protected Scenario(TestScenarioScope<TEntryPoint> scope)
Parameters
scopeTestScenarioScope<TEntryPoint>The non-null caller-owned scope. This scenario never disposes it.
Exceptions
- ArgumentNullException
scopeis null.
Properties
Scope
Gets the isolated scope used by domain setup and operations.
protected TestScenarioScope<TEntryPoint> Scope { get; }
Property Value
- TestScenarioScope<TEntryPoint>
The borrowed scope supplied to the constructor. The caller owns and disposes it.
Methods
Arrange()
Freezes domain configuration and defers its arrangement until a request executes.
public TestScenarioBuilder<TEntryPoint> Arrange()
Returns
- TestScenarioBuilder<TEntryPoint>
A new single-use HTTP request builder. Its execution runs domain arrangement before sending the request. The caller owns the execution result and must dispose it.
Remarks
Calling this method consumes the scenario even if the returned builder is never executed. Use ArrangeAsync(CancellationToken) when arrangement should run without an HTTP request.
Exceptions
- InvalidOperationException
Arrangement has already been selected or started.
ArrangeAsync(CancellationToken)
Freezes domain configuration and runs arrangement once without sending a request.
public Task ArrangeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels arrangement. The token is checked before invoking the domain callback and then passed to it. Cancellation or failure still consumes this scenario; use a new instance to retry.
Returns
- Task
A task that completes after domain arrangement has finished.
Exceptions
- InvalidOperationException
Arrangement has already been selected or started.
ArrangeCoreAsync(CancellationToken)
Applies the domain's configured database state, stubs, or other arrangements.
protected abstract Task ArrangeCoreAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe arrangement token to pass to asynchronous setup operations.
Returns
- Task
A non-null task that completes after setup finishes.
Remarks
Invoked once after configuration is frozen, either by ArrangeAsync(CancellationToken) or during execution of the builder returned by Arrange(). This callback does not own the scope.
EnsureNotArranged()
Rejects domain configuration changes after arrangement has been selected or started.
protected void EnsureNotArranged()
Remarks
Call this from derived configuration methods before changing domain state.
Exceptions
- InvalidOperationException
Arrangement has already been selected or started.