Class MockHandler

Namespace
Kuestenlogik.Bowire.Mock
Assembly
Kuestenlogik.Bowire.Mock.dll

Per-pipeline handler that owns the currently-active recording and replays matching unary steps. Created once by UseBowireMock and shared across every request on the pipeline — the recording reference is swapped atomically by the file watcher on hot-reload.

public sealed class MockHandler
Inheritance
MockHandler
Inherited Members

Constructors

MockHandler(BowireRecording, MockOptions, ILogger, string?)

public MockHandler(BowireRecording recording, MockOptions options, ILogger logger, string? recordingPath = null)

Parameters

recording BowireRecording
options MockOptions
logger ILogger
recordingPath string

Properties

Buckets

The mock's data buckets (#1096); null when the configuration declares no CRUD route.

public MockBucketStore? Buckets { get; }

Property Value

MockBucketStore

CrudRoutes

The mock's CRUD routes (#1100); null when the configuration declares none.

public MockCrudRoutes? CrudRoutes { get; }

Property Value

MockCrudRoutes

MockConfigPath

The file the configuration was read from, for ReloadDataAsync(CancellationToken); null when there is none.

public string? MockConfigPath { get; }

Property Value

string

Methods

AddStub(BowireRecordingStep)

Append a stub (assigning an id when it has none). Returns the stored stub.

public BowireRecordingStep AddStub(BowireRecordingStep stub)

Parameters

stub BowireRecordingStep

Returns

BowireRecordingStep

BaselineStubs()

#561: the original baseline stubs (as loaded / last hot-reloaded). The runtime config-apply path recomputes the stub set from this each time, so re-applying an edited config never compounds on a prior apply.

public IReadOnlyList<BowireRecordingStep> BaselineStubs()

Returns

IReadOnlyList<BowireRecordingStep>

GetScenarioStates()

Current state of every scenario declared in the recording (name → state).

public IReadOnlyDictionary<string, string> GetScenarioStates()

Returns

IReadOnlyDictionary<string, string>

GetStub(string)

Find a stub by id, or null.

public BowireRecordingStep? GetStub(string id)

Parameters

id string

Returns

BowireRecordingStep

HandleAsync(HttpContext, Func<Task>)

public Task HandleAsync(HttpContext ctx, Func<Task> next)

Parameters

ctx HttpContext
next Func<Task>

Returns

Task

ListStubs()

Snapshot of the current stubs (recording steps).

public IReadOnlyList<BowireRecordingStep> ListStubs()

Returns

IReadOnlyList<BowireRecordingStep>

ReloadDataAsync(CancellationToken)

#1100: read the configuration file again and take its buckets and CRUD routes, as ReplaceData(MockConfiguration) does: a bucket whose definition is unchanged keeps its data, a route that was switched off stays off. Field overrides and rules are part of the recording the mock was started with and change on a restart. False when the mock has no configuration file; IOException, JsonException or ArgumentException, changing nothing, when it cannot be read or does not add up.

public Task<bool> ReloadDataAsync(CancellationToken ct)

Parameters

ct CancellationToken

Returns

Task<bool>

RemoveStub(string)

Remove the stub with the given id. False when absent.

public bool RemoveStub(string id)

Parameters

id string

Returns

bool

ReplaceData(MockConfiguration)

#1097: take the buckets and CRUD routes of a configuration applied to the running mock, and (#1101) the latency and faults of its routes. A bucket whose definition is unchanged keeps its data; a configuration without CRUD routes removes them. Throws ArgumentException, changing nothing, when the routes, buckets and route faults do not add up.

public void ReplaceData(MockConfiguration config)

Parameters

config MockConfiguration

ReplaceRecording(BowireRecording)

Swap the in-memory recording. Called by RecordingWatcher when the source file changes. Resets the stateful cursor because the new file defines a fresh step sequence — carrying the old index over would almost certainly land on a different step than the user meant.

public void ReplaceRecording(BowireRecording next)

Parameters

next BowireRecording

ReplaceStubs(IEnumerable<BowireRecordingStep>)

#561: swap the entire live stub set in one shot. The baseline is left untouched, so ResetStubs() still restores the original.

public void ReplaceStubs(IEnumerable<BowireRecordingStep> stubs)

Parameters

stubs IEnumerable<BowireRecordingStep>

ResetScenarios()

Reset every scenario back to its initial state (Started).

public void ResetScenarios()

ResetStubs()

Restore the stubs to the baseline recording (as loaded / last hot-reloaded).

public void ResetStubs()

SetScenarioState(string, string)

Force a scenario to a state. False when no stub declares that scenario name.

public bool SetScenarioState(string name, string state)

Parameters

name string
state string

Returns

bool

UpdateStub(string, BowireRecordingStep)

Replace the stub with the given id (id preserved). False when absent.

public bool UpdateStub(string id, BowireRecordingStep stub)

Parameters

id string
stub BowireRecordingStep

Returns

bool

ValidateData(MockConfiguration)

#1097: check that a configuration's CRUD routes, buckets and (#1101) route faults add up, the way a mock would take them. Throws ArgumentException naming what does not.

public static void ValidateData(MockConfiguration config)

Parameters

config MockConfiguration