Class ProtoTestScope

Namespace
ProtoTest.Core
Assembly
ProtoTest.Core.dll

One test's lifecycle as a scope: start it from a prepared test, run the framework's body, then let the scope complete the lifecycle. Teardown failures are recorded as findings by the lifecycle. By default the scope then fails the test: a body that passed is reported as failed, and a body that failed keeps that failure with the cleanup attached. A skipped or unknown body also fails when cleanup fails. Report records the finding and leaves the reported result alone, so every adapter shares one policy.

public sealed class ProtoTestScope : IAsyncDisposable
Inheritance
ProtoTestScope
Implements
Inherited Members
Extension Methods

Properties

Context

The started test's execution context.

public ProtoExecutionContext Context { get; }

Property Value

ProtoExecutionContext

Result

The result the framework reported; defaults to Unknown.

public ProtoTestResult Result { get; set; }

Property Value

ProtoTestResult

Methods

DisposeAsync()

Completes the lifecycle once. The scope owns its started test: completion must run on the async flow that started it and while that test is the active one, because completion reads the ambient context. Disposing off-flow, or under another test, would complete nothing (or someone else's test), so the scope records that as a finding on its own test and reports it instead of silently no-oping. A teardown failure is already recorded by the lifecycle. Unless cleanup failures are set to Report, disposing then throws ProtoCleanupException so the runner fails this test. A body that failed stays the primary error inside that exception.

public ValueTask DisposeAsync()

Returns

ValueTask

StartAsync(ProtoTestPreparation, ProtoHost, IProtoTestAttachmentPublisher?)

Starts the test lifecycle for a prepared test. The lifecycle call is made synchronously, so the ambient context it sets is visible to the caller's flow and the test body that awaits this task still sees it.

public static Task<ProtoTestScope> StartAsync(ProtoTestPreparation preparation, ProtoHost host, IProtoTestAttachmentPublisher? attachmentPublisher = null)

Parameters

preparation ProtoTestPreparation
host ProtoHost
attachmentPublisher IProtoTestAttachmentPublisher

Returns

Task<ProtoTestScope>

StartAsync(ProtoTestPreparation, ProtoHost, IProtoTestAttachmentPublisher?, CancellationToken)

Starts the test lifecycle with the runner's cancellation token, so setup I/O that can observe cancellation - the SQL connection open and transaction begin - does. A runner whose extension point exposes no token passes None and keeps the previous behavior.

public static Task<ProtoTestScope> StartAsync(ProtoTestPreparation preparation, ProtoHost host, IProtoTestAttachmentPublisher? attachmentPublisher, CancellationToken cancellationToken)

Parameters

preparation ProtoTestPreparation
host ProtoHost
attachmentPublisher IProtoTestAttachmentPublisher
cancellationToken CancellationToken

Returns

Task<ProtoTestScope>