Class ProtoHost
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
rootServiceProviderIServiceProvider
Properties
Configuration
public IConfiguration Configuration { get; }
Property Value
CurrentContext
Gets the current test execution context for this asynchronous control flow.
public static ProtoExecutionContext CurrentContext { get; }
Property Value
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
CurrentHost
Gets the host owning the current test, or the sole active host outside a test.
public static ProtoHost CurrentHost { get; }
Property Value
Trace
Gets immutable snapshots of the current run trace.
public IProtoTraceSource Trace { get; }
Property Value
Methods
CompleteTestAsync()
Completes the active test using the exact lifecycle components that completed setup.
public Task CompleteTestAsync()
Returns
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
resultProtoTestResult
Returns
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
traceIdActivityTraceId
Returns
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
Returns
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
cancellationTokenCancellationToken
Returns
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
testNamestringtestMethodMethodInfoattributesIEnumerable<ProtoAttribute>attachmentPublisherIProtoTestAttachmentPublisher
Returns
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
testNamestringtestIdstringtestMethodMethodInfoattributesIEnumerable<ProtoAttribute>attachmentPublisherIProtoTestAttachmentPublisher
Returns
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
cancellationTokenCancellationToken