Class ProtoExecutionContext
Provides the public per-test façade for metadata, services, state, clients, attachments, and observations.
public sealed class ProtoExecutionContext : IAsyncDisposable
- Inheritance
-
ProtoExecutionContext
- Implements
- Inherited Members
- Extension Methods
Constructors
ProtoExecutionContext(string, IServiceScope, ProtoTestId, MethodInfo)
public ProtoExecutionContext(string testName, IServiceScope scope, ProtoTestId id, MethodInfo testMethod)
Parameters
testNamestringscopeIServiceScopeidProtoTestIdtestMethodMethodInfo
ProtoExecutionContext(string, IServiceScope, string, MethodInfo)
public ProtoExecutionContext(string testName, IServiceScope scope, string testId, MethodInfo testMethod)
Parameters
testNamestringscopeIServiceScopetestIdstringtestMethodMethodInfo
Properties
Attachments
Gets a snapshot of the artifacts registered for this test.
public IReadOnlyList<ProtoTestAttachment> Attachments { get; }
Property Value
Configuration
Retrieves the global configuration registered in the ProtoHost.
public IConfiguration Configuration { get; }
Property Value
Id
Numeric execution ID generated by the owning host. The string form preserves leading zeroes.
public ProtoTestId Id { get; }
Property Value
RecordedObservations
Gets a snapshot of observations recorded for this test.
public IReadOnlyCollection<ProtoObservation> RecordedObservations { get; }
Property Value
Resources
Gets a snapshot of the resources owned by this test, in registration order.
public IReadOnlyList<ProtoResourceSnapshot> Resources { get; }
Property Value
Services
public IServiceProvider Services { get; }
Property Value
TestId
public string TestId { get; }
Property Value
TestMethod
public MethodInfo TestMethod { get; }
Property Value
TestName
public string TestName { get; }
Property Value
TestNumber
public long TestNumber { get; }
Property Value
Trace
Records automatic execution diagnostics for ProtoTest integrations.
public IProtoTraceWriter Trace { get; }
Property Value
Methods
AddAttachment(ProtoTestAttachment)
public ProtoTestAttachment AddAttachment(ProtoTestAttachment attachment)
Parameters
attachmentProtoTestAttachment
Returns
AddAttachment(string, ReadOnlyMemory<byte>, string, string?)
public ProtoTestAttachment AddAttachment(string name, ReadOnlyMemory<byte> content, string mediaType = "application/octet-stream", string? description = null)
Parameters
namestringcontentReadOnlyMemory<byte>mediaTypestringdescriptionstring
Returns
AddAttachment(string, string, string, string?)
public ProtoTestAttachment AddAttachment(string name, string content, string mediaType = "text/plain", string? description = null)
Parameters
Returns
AddAttachmentFile(string, string?, string, string?)
public ProtoTestAttachment AddAttachmentFile(string filePath, string? name = null, string mediaType = "application/octet-stream", string? description = null)
Parameters
Returns
AddFinding(string, ProtoReportStatus, string?, string?, string?, IReadOnlyList<string>?, IReadOnlyDictionary<string, object>?)
Records a finding: something worth reporting that is deliberately not a test failure. Findings reach the run's reports and run gates, and are traced so they appear in ProtoTrace.
public ProtoReportItem AddFinding(string message, ProtoReportStatus status = ProtoReportStatus.Warning, string? identifier = null, string? category = null, string? targetName = null, IReadOnlyList<string>? tags = null, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
messagestringstatusProtoReportStatusidentifierstringcategorystringtargetNamestringtagsIReadOnlyList<string>metadataIReadOnlyDictionary<string, object>
Returns
Client<TClient>(string)
Retrieves a required named client.
public TClient Client<TClient>(string name = "Default") where TClient : class
Parameters
namestring
Returns
- TClient
Type Parameters
TClient
DisposeAsync()
Releases owned resources, disposes owned clients and the service scope. Disposal is idempotent and attempts every resource.
public ValueTask DisposeAsync()
Returns
RecordObservation(ProtoObservation)
Stores and dispatches an observation to every collector that accepts it.
public void RecordObservation(ProtoObservation observation)
Parameters
observationProtoObservation
RecordObservation(string, string, string, object?, IReadOnlyDictionary<string, object>?)
Convenience overload for recording an observation.
public void RecordObservation(string targetName, string kind, string identifier, object? data = null, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
targetNamestringkindstringidentifierstringdataobjectmetadataIReadOnlyDictionary<string, object>
RegisterClient<TClient>(TClient, string, bool)
Registers a named client for this test. The client is owned by the test and released in reverse
registration order when the test completes; pass disposeWithContext as
false for shared clients whose lifetime is managed elsewhere.
public void RegisterClient<TClient>(TClient client, string name = "Default", bool disposeWithContext = true) where TClient : class
Parameters
Type Parameters
TClient
RegisterResource(IProtoResource)
Registers a resource owned by this test. Owned resources are released in reverse registration order during teardown, after hooks and attributes and before clients are disposed. Resources registered here reach the run's report; framework-managed clients do not, unless their release fails.
public void RegisterResource(IProtoResource resource)
Parameters
resourceIProtoResource
RegisterResource(string, string, string, Func<ProtoResourceReleaseContext, ValueTask>)
Registers a resource described by a release callback.
public void RegisterResource(string id, string kind, string description, Func<ProtoResourceReleaseContext, ValueTask> release)
Parameters
RegisterResource<T>(T)
Registers a resource and returns it, so ownership can be expressed inline.
public T RegisterResource<T>(T resource) where T : class, IProtoResource
Parameters
resourceT
Returns
- T
Type Parameters
T
ReleaseResourceAsync(string)
Releases one owned resource before teardown. Returns false when the resource is unknown or was already released.
public ValueTask<bool> ReleaseResourceAsync(string id)
Parameters
idstring
Returns
Resolve<T>()
Retrieves required contextual state.
public T Resolve<T>() where T : class, IProtoContext
Returns
- T
Type Parameters
T
Service<T>()
public T Service<T>() where T : notnull
Returns
- T
Type Parameters
T
SetContext<T>(T)
Registers or replaces contextual state for this test.
public void SetContext<T>(T context) where T : class, IProtoContext
Parameters
contextT
Type Parameters
T
TryClient<TClient>(string)
Retrieves a named client when it is present.
public TClient? TryClient<TClient>(string name = "Default") where TClient : class
Parameters
namestring
Returns
- TClient
Type Parameters
TClient
TryResolve<T>()
Retrieves contextual state when it is present.
public T? TryResolve<T>() where T : class, IProtoContext
Returns
- T
Type Parameters
T
TryService<T>()
public T? TryService<T>()
Returns
- T
Type Parameters
T