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

schemaSources IReadOnlyList<IBowireMockSchemaSource>
liveSchemaHandlers IReadOnlyList<IBowireMockLiveSchemaHandler>
hostingExtensions IReadOnlyList<IBowireMockHostingExtension>

Properties

SchemaKinds

Schema kinds this manager can start (empty when no sources are wired).

public IReadOnlyCollection<string> SchemaKinds { get; }

Property Value

IReadOnlyCollection<string>

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

mockId string
stub BowireRecordingStep

Returns

BowireRecordingStep

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

mockId string
config MockConfiguration

Returns

bool

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

Get(string)

Look up a single mock by id. Returns null if not running.

public MockHostHandle? Get(string mockId)

Parameters

mockId string

Returns

MockHostHandle

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

mockId string

Returns

MockAuthRequirement

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

mockId string

Returns

FaultRuleSet

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

mockId string

Returns

MockRequestLog

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

mockId string

Returns

IReadOnlyDictionary<string, string>

GetStub(string, string)

Get a single stub by id.

public BowireRecordingStep? GetStub(string mockId, string stubId)

Parameters

mockId string
stubId string

Returns

BowireRecordingStep

GetStubs(string)

List the stubs (recording steps) of a running mock.

public IReadOnlyList<BowireRecordingStep>? GetStubs(string mockId)

Parameters

mockId string

Returns

IReadOnlyList<BowireRecordingStep>

IsSupportedSchemaKind(string?)

Is kind one of the schema kinds a schema mock accepts (case-insensitive)?

public static bool IsSupportedSchemaKind(string? kind)

Parameters

kind string

Returns

bool

List()

Snapshot of every running mock. Order undefined; UI sorts by StartedAtUtc.

public IReadOnlyCollection<MockHostHandle> List()

Returns

IReadOnlyCollection<MockHostHandle>

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

mockId string
stubId string

Returns

bool

ResetScenarios(string)

Reset all scenarios to Started. False when not running.

public bool ResetScenarios(string mockId)

Parameters

mockId string

Returns

bool

ResetStubs(string)

Restore a running mock's stubs to its baseline recording. False when not running.

public bool ResetStubs(string mockId)

Parameters

mockId string

Returns

bool

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

mockId string
name string
state string

Returns

bool

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

recordingJson string

Single recording document (NOT the {"recordings":[...]} envelope).

recordingId string

Stable 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.

label string

Display label (recording name or operator- supplied alias).

port int

Requested port. 0 = use the rolling allocator; any positive value pins the mock to that port (and fails the call if the port is busy).

ct CancellationToken

Cancellation.

Returns

Task<MockHostHandle>

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

schemaKind string

openapi, protobuf, or graphql.

schemaInline string

Inline schema text (OpenAPI YAML/JSON or GraphQL SDL). Mutex with schemaPath.

schemaPath string

Path to an existing schema file (any kind, incl. a binary protobuf FileDescriptorSet). Mutex with schemaInline.

label string

Display label.

port int

Requested port; 0 = rolling allocator.

ct CancellationToken

Cancellation.

Returns

Task<MockHostHandle>

StopAsync(string, CancellationToken)

public Task<bool> StopAsync(string mockId, CancellationToken ct)

Parameters

mockId string
ct CancellationToken

Returns

Task<bool>

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

mockId string
requirement MockAuthRequirement

Returns

bool

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

mockId string
faults FaultRuleSet

Returns

bool

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

mockId string
stubId string
stub BowireRecordingStep

Returns

bool