Class FaultRuleSet
- Namespace
- Kuestenlogik.Bowire.Mock.Chaos
- Assembly
- Kuestenlogik.Bowire.Mock.dll
Per-method fault-injection rules (#170) — the structured successor to the global ChaosOptions knobs. A rule pairs a method matcher with a latency shape and a fault kind; the first enabled rule whose matcher hits a request handles it. Default off: an empty rule set injects nothing, and ChaosOptions keeps working unchanged next to this.
public sealed class FaultRuleSet
- Inheritance
-
FaultRuleSet
- Inherited Members
Remarks
Sidecar file shape (mock-faults.json, CLI --faults):
{
"rules": [
{ "method": "UserService/*", "kind": "error", "rate": 0.25, "errorStatusCode": 503 },
{ "method": "*/Download", "kind": "partial-response", "partialBytes": 512 },
{ "kind": "latency-only", "latency": { "distribution": "normal", "meanMs": 200, "stdDevMs": 50 } }
]
}
Constructors
FaultRuleSet()
public FaultRuleSet()
Properties
IsActive
True when at least one rule can fire.
[JsonIgnore]
public bool IsActive { get; }
Property Value
Rules
Rules in declaration order; first enabled match wins. Settable so the management endpoint can swap the live rule list on a running mock — reference assignment is atomic, in-flight requests keep the list they already picked up.
[JsonPropertyName("rules")]
public IReadOnlyList<FaultRule> Rules { get; set; }
Property Value
Methods
FirstMatch(string?, string?)
First enabled non-onMiss rule matching the step's service/method,
or null. onMiss rules never fire on a matched step — they're for
unmatched requests (see FirstMissMatch()).
public FaultRule? FirstMatch(string? service, string? method)
Parameters
Returns
FirstMissMatch()
First enabled onMiss rule (#411), applied to requests that matched no stub.
public FaultRule? FirstMissMatch()
Returns
LoadJson(string, bool)
Parse a mock-faults.json document. Throws
FormatException with a pointed message on structural
or semantic problems so CLI users see the offending rule early.
allowEmpty permits an empty rules array — the
management endpoint uses that to clear a running mock's rules,
while the CLI keeps rejecting a pointless sidecar file.
public static FaultRuleSet LoadJson(string json, bool allowEmpty = false)
Parameters
Returns
ToJson()
Serialize in the exact mock-faults.json shape
LoadJson(string, bool) accepts (kebab-case enums), indented for
the UI editor — so GET → edit → PUT round-trips byte-stable.
public string ToJson()