Class BowireMockHostManager
- Namespace
- Kuestenlogik.Bowire.Mock.Management
- Assembly
- Kuestenlogik.Bowire.Mock.dll
Single owner of every UI-spun mock server. Replaces the v1.x
MockRegistry / v2.x BowireMockHostManager split — there's
now exactly one registry behind /api/mocks* (#223).
public sealed class BowireMockHostManager : IAsyncDisposable
- Inheritance
-
BowireMockHostManager
- Implements
- Inherited Members
Remarks
Lifecycle: singleton via AddBowireMockManagement();
disposed on host shutdown. Every StartAsync(string, string, string, int, CancellationToken) writes the
recording JSON to a temp file (the underlying MockServer
ingests via path), opens the host on a free local port, and tracks
the entry in a ConcurrentDictionary<TKey, TValue>.
StopAsync(string, CancellationToken) tears the server down + deletes the temp file.
Concurrency: List / Start / Stop / Get can interleave freely. The temp-file write is awaited before StartAsync(MockServerOptions, CancellationToken), so a successful start always has the file on disk.
Constructors
BowireMockHostManager()
Recording-only manager (the embedded default). No schema-mock start.
public BowireMockHostManager()
BowireMockHostManager(IReadOnlyList<IBowireMockSchemaSource>, IReadOnlyList<IBowireMockLiveSchemaHandler>, IReadOnlyList<IBowireMockHostingExtension>)
Manager wired with plugin-contributed schema sources, live handlers, and hosting extensions so StartFromSchemaAsync(string, string?, string?, string, int, CancellationToken) can spin up an OpenAPI / protobuf / GraphQL schema mock at CLI parity — the hosting extensions carry the gRPC reflection + REST schema-discovery endpoints a schema mock needs to be reachable. The standalone workbench host passes what it enumerated from the plugin loader.
public BowireMockHostManager(IReadOnlyList<IBowireMockSchemaSource> schemaSources, IReadOnlyList<IBowireMockLiveSchemaHandler> liveSchemaHandlers, IReadOnlyList<IBowireMockHostingExtension> hostingExtensions)
Parameters
schemaSourcesIReadOnlyList<IBowireMockSchemaSource>liveSchemaHandlersIReadOnlyList<IBowireMockLiveSchemaHandler>hostingExtensionsIReadOnlyList<IBowireMockHostingExtension>
Properties
SchemaKinds
Schema kinds this manager can start (empty when no sources are wired).
public IReadOnlyCollection<string> SchemaKinds { get; }
Property Value
Methods
AddStub(string, BowireRecordingStep)
Add a stub to a running mock. Null when the mock isn't running.
public BowireRecordingStep? AddStub(string mockId, BowireRecordingStep stub)
Parameters
mockIdstringstubBowireRecordingStep
Returns
ApplyConfig(string, MockConfiguration)
#561: re-apply a mock configuration to a RUNNING mock. Recomputes the stub set from the baseline — field overrides mutate the base responses, each conditional rule becomes a higher-priority match stub — and swaps it in live. Recomputing from the baseline means re-applying an edited config never compounds on a previous apply. False when not running.
public bool ApplyConfig(string mockId, MockConfiguration config)
Parameters
mockIdstringconfigMockConfiguration
Returns
DisposeAsync()
public ValueTask DisposeAsync()
Returns
Get(string)
Look up a single mock by id. Returns null if not running.
public MockHostHandle? Get(string mockId)
Parameters
mockIdstring
Returns
GetAuth(string)
Live auth requirement of a running mock (#562). Null when not running or auth isn't required.
public MockAuthRequirement? GetAuth(string mockId)
Parameters
mockIdstring
Returns
GetFaults(string)
Live fault-injection rules of a running mock (#170). Null when the mock id isn't in the registry.
public FaultRuleSet? GetFaults(string mockId)
Parameters
mockIdstring
Returns
GetRequestLog(string)
Access the request log for a running mock (#57 — Mocks panel request tail). Returns null when the mock id isn't in the registry.
public MockRequestLog? GetRequestLog(string mockId)
Parameters
mockIdstring
Returns
GetScenarioStates(string)
Current state of every scenario in a running mock (name → state). Null when not running.
public IReadOnlyDictionary<string, string>? GetScenarioStates(string mockId)
Parameters
mockIdstring
Returns
GetStub(string, string)
Get a single stub by id.
public BowireRecordingStep? GetStub(string mockId, string stubId)
Parameters
Returns
GetStubs(string)
List the stubs (recording steps) of a running mock.
public IReadOnlyList<BowireRecordingStep>? GetStubs(string mockId)
Parameters
mockIdstring
Returns
IsSupportedSchemaKind(string?)
Is kind one of the schema kinds a schema mock accepts (case-insensitive)?
public static bool IsSupportedSchemaKind(string? kind)
Parameters
kindstring
Returns
List()
Snapshot of every running mock. Order undefined; UI sorts by StartedAtUtc.
public IReadOnlyCollection<MockHostHandle> List()
Returns
RemoveStub(string, string)
Remove a stub by id. False when the mock or stub isn't found.
public bool RemoveStub(string mockId, string stubId)
Parameters
Returns
ResetScenarios(string)
Reset all scenarios to Started. False when not running.
public bool ResetScenarios(string mockId)
Parameters
mockIdstring
Returns
ResetStubs(string)
Restore a running mock's stubs to its baseline recording. False when not running.
public bool ResetStubs(string mockId)
Parameters
mockIdstring
Returns
SetScenarioState(string, string, string)
Force a scenario to a state. False when the mock isn't running or the scenario is unknown.
public bool SetScenarioState(string mockId, string name, string state)
Parameters
Returns
StartAsync(string, string, string, int, CancellationToken)
Boot a mock host for the supplied recording JSON.
public Task<MockHostHandle> StartAsync(string recordingJson, string recordingId, string label, int port, CancellationToken ct)
Parameters
recordingJsonstringSingle recording document (NOT the {"recordings":[...]} envelope).
recordingIdstringStable id of the source recording (so the workbench can correlate the running mock back to the recording that produced it). Empty when the start came from an embedded host that passed a recording payload directly.
labelstringDisplay label (recording name or operator- supplied alias).
portintRequested port. 0 = use the rolling allocator; any positive value pins the mock to that port (and fails the call if the port is busy).
ctCancellationTokenCancellation.
Returns
StartFromSchemaAsync(string, string?, string?, string, int, CancellationToken)
#560: boot a schema-only mock — the workbench equivalent of
bowire mock --schema / --grpc-schema / --graphql-schema. The
schema is supplied inline (schemaInline, written to
a temp file) or as an existing file path (schemaPath).
Requires the manager to have been wired with the matching
IBowireMockSchemaSource.
public Task<MockHostHandle> StartFromSchemaAsync(string schemaKind, string? schemaInline, string? schemaPath, string label, int port, CancellationToken ct)
Parameters
schemaKindstringopenapi,protobuf, orgraphql.schemaInlinestringInline schema text (OpenAPI YAML/JSON or GraphQL SDL). Mutex with
schemaPath.schemaPathstringPath to an existing schema file (any kind, incl. a binary protobuf FileDescriptorSet). Mutex with
schemaInline.labelstringDisplay label.
portintRequested port; 0 = rolling allocator.
ctCancellationTokenCancellation.
Returns
StopAsync(string, CancellationToken)
public Task<bool> StopAsync(string mockId, CancellationToken ct)
Parameters
mockIdstringctCancellationToken
Returns
TrySetAuth(string, MockAuthRequirement?)
Swap the auth requirement of a RUNNING mock (#562 — the UI toggle). False when not running.
public bool TrySetAuth(string mockId, MockAuthRequirement? requirement)
Parameters
mockIdstringrequirementMockAuthRequirement
Returns
TrySetFaults(string, FaultRuleSet)
Swap the fault rules of a RUNNING mock (#170 — the UI editor's apply path). Atomic reference swap; false when the mock id isn't in the registry.
public bool TrySetFaults(string mockId, FaultRuleSet faults)
Parameters
mockIdstringfaultsFaultRuleSet
Returns
UpdateStub(string, string, BowireRecordingStep)
Replace a stub by id. False when the mock or stub isn't found.
public bool UpdateStub(string mockId, string stubId, BowireRecordingStep stub)
Parameters
mockIdstringstubIdstringstubBowireRecordingStep