Class ProtoTestHostLifetime
Owns the single root ProtoHost for a test assembly and enforces one-time initialization. Shared by every test-framework adapter so host lifetime, guards, and shutdown ordering stay identical across frameworks.
public sealed class ProtoTestHostLifetime
- Inheritance
-
ProtoTestHostLifetime
- Inherited Members
- Extension Methods
Constructors
ProtoTestHostLifetime(string)
public ProtoTestHostLifetime(string initializationHint = "Initialize the ProtoTest assembly fixture before running tests.")
Parameters
initializationHintstringAdapter-specific guidance appended to the "not initialized" error message.
Properties
Host
Gets the initialized host.
public ProtoHost Host { get; }
Property Value
Exceptions
- InvalidOperationException
Thrown when accessed before initialization.
Methods
StartAsync(Action<IProtoHostBuilder>)
Builds and starts the host once. Throws if it has already been initialized or a start is in flight; a failed start leaves the lifetime retryable. A StopAsync() that arrives while this start is in flight still lets the start finish, then stops the host; this call then throws, so the caller does not observe a start that no longer has a host.
public Task StartAsync(Action<IProtoHostBuilder> configure)
Parameters
configureAction<IProtoHostBuilder>
Returns
Exceptions
- InvalidOperationException
The host was already initialized, a start is already in flight, or it was stopped while starting.
StopAsync()
Stops and disposes the host, clearing it so later access reports "not initialized". A stop during an in-flight start waits for that start to finish, then stops the host when one was published. The start is not cancelled: StartAsync(Action<IProtoHostBuilder>) has no cancellation token. This method does not return while the start is still in flight, and it does not leave a host published afterwards. A stop from inside the start itself throws instead of waiting: that wait cannot finish while the start is still inside the caller. A start that fails while this method is waiting leaves no host; this method then returns without running AfterRun, and the start's exception still goes to the StartAsync(Action<IProtoHostBuilder>) caller.
public Task StopAsync()
Returns
Exceptions
- InvalidOperationException
Thrown when called from inside the start it would wait for.