Class ProtoHost

Namespace
ProtoTest.Core
Assembly
ProtoTest.Core.dll

Owns the ProtoTest service provider and exposes the public run and test lifecycle API. Lifecycle execution is delegated to focused internal components.

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

Constructors

ProtoHost(IServiceProvider)

public ProtoHost(IServiceProvider rootServiceProvider)

Parameters

rootServiceProvider IServiceProvider

Properties

Configuration

public IConfiguration Configuration { get; }

Property Value

IConfiguration

CurrentContext

Gets the current test execution context for this asynchronous control flow.

public static ProtoExecutionContext CurrentContext { get; }

Property Value

ProtoExecutionContext

CurrentContextOrNull

Gets the current test execution context, or null when none is active on this flow - the safe lookup for telemetry callbacks, which can run outside the test's context.

public static ProtoExecutionContext? CurrentContextOrNull { get; }

Property Value

ProtoExecutionContext

CurrentHost

Gets the host owning the current test, or the sole active host outside a test.

public static ProtoHost CurrentHost { get; }

Property Value

ProtoHost

Trace

Gets immutable snapshots of the current run trace.

public IProtoTraceSource Trace { get; }

Property Value

IProtoTraceSource

Methods

CompleteTestAsync()

Completes the active test using the exact lifecycle components that completed setup.

public Task CompleteTestAsync()

Returns

Task

Exceptions

InvalidOperationException

Thrown when no test is active on the current async flow, so a missing or leaked context is reported instead of being silently ignored.

CompleteTestAsync(ProtoTestResult)

Completes the active test and records the result reported by its framework adapter. Unlike the parameterless overload this stays a no-op when no test is active: adapters call it from teardown even when their framework skipped the test before the lifecycle started.

public Task CompleteTestAsync(ProtoTestResult result)

Parameters

result ProtoTestResult

Returns

Task

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.

FindTraceWriter(ActivityTraceId)

Finds the trace writer of the test an application span belongs to, matched by its W3C trace id. This is the safe lookup for application telemetry callbacks, which run outside the test's flow: CurrentContextOrNull is empty there and CurrentHost cannot be resolved.

public static IProtoTraceWriter? FindTraceWriter(ActivityTraceId traceId)

Parameters

traceId ActivityTraceId

Returns

IProtoTraceWriter

HasCapability(string, string?)

Returns whether the host is composed with a capability of the given kind (optionally a specific name). Integrations declare capabilities when they are configured, so this answers what the host can actually do rather than what it was asked to do.

public bool HasCapability(string kind, string? name = null)

Parameters

kind string
name string

Returns

bool

StartAsync(CancellationToken)

Executes all suite-level BeforeRun hooks in ascending order, then records the capabilities the host is composed of as run entities. The whole start path runs once: a repeat call after a successful start is a no-op, and a call while a start is in flight is rejected rather than recording or starting anything twice.

public Task StartAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

StartTestAsync(string, MethodInfo, IEnumerable<ProtoAttribute>?, IProtoTestAttachmentPublisher?)

Starts a test lifecycle with an ID generated by this host.

public Task<ProtoExecutionContext> StartTestAsync(string testName, MethodInfo testMethod, IEnumerable<ProtoAttribute>? attributes = null, IProtoTestAttachmentPublisher? attachmentPublisher = null)

Parameters

testName string
testMethod MethodInfo
attributes IEnumerable<ProtoAttribute>
attachmentPublisher IProtoTestAttachmentPublisher

Returns

Task<ProtoExecutionContext>

StartTestAsync(string, string, MethodInfo, IEnumerable<ProtoAttribute>?, IProtoTestAttachmentPublisher?)

Starts a test lifecycle with an explicit numeric ID.

public Task<ProtoExecutionContext> StartTestAsync(string testName, string testId, MethodInfo testMethod, IEnumerable<ProtoAttribute>? attributes = null, IProtoTestAttachmentPublisher? attachmentPublisher = null)

Parameters

testName string
testId string
testMethod MethodInfo
attributes IEnumerable<ProtoAttribute>
attachmentPublisher IProtoTestAttachmentPublisher

Returns

Task<ProtoExecutionContext>

StopAsync(CancellationToken)

Executes all suite-level AfterRun hooks in descending order. A stop rejected because a start is in flight changes nothing; a stop that ran and failed is remembered and rethrown on retry.

public Task StopAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task