Class MockCrudRoutes

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

The REST routes over the mock's data buckets (#1096): a collection path and a record path under it, answering as a small backend would, so a POST followed by a GET returns what was just created.

public sealed class MockCrudRoutes
Inheritance
MockCrudRoutes
Inherited Members

Remarks

RequestAnswer
GET /path200, the records, filtered, sorted and paged (Kuestenlogik.Bowire.Mock.State.MockCollectionQuery), with X-Total-Count and X-Filtered-Count
POST /path201 and Location, the record with its id (one is given when missing); 409 when the id is taken
PUT /path200, the bucket replaced by the array sent
DELETE /path204, the bucket emptied
GET /path/{id}200, the record; 404 when there is none
PUT /path/{id}200, the record replaced, its id kept
PATCH /path/{id}200, the body merged in (JSON Merge Patch), its id kept
DELETE /path/{id}204, the record removed

An object bucket answers GET, PUT, PATCH and DELETE on /path itself. A method a path does not take gets 405 with Allow.

Constructors

MockCrudRoutes(MockBucketStore, IEnumerable<MockCrudRoute>)

The routes of a configuration over store.

public MockCrudRoutes(MockBucketStore store, IEnumerable<MockCrudRoute> routes)

Parameters

store MockBucketStore
routes IEnumerable<MockCrudRoute>

Properties

Any

Whether any route is configured.

public bool Any { get; }

Property Value

bool

Paths

The paths of the configured routes, normalised (#1101).

public IReadOnlyCollection<string> Paths { get; }

Property Value

IReadOnlyCollection<string>

Methods

Describe()

Every route with its bucket and whether it is on, in configuration order (#1100).

public IReadOnlyList<MockCrudRouteInfo> Describe()

Returns

IReadOnlyList<MockCrudRouteInfo>

RouteFor(string?)

The path of the route that answers a request to requestPath, its collection or one of its records; null when no route that is on covers it (#1101).

public string? RouteFor(string? requestPath)

Parameters

requestPath string

Returns

string

SetEnabled(string, bool)

Switch a route on or off while the mock runs (#1100). A route that is off answers nothing; its requests go on to the recording or schema. False when no route has that path.

public bool SetEnabled(string path, bool enabled)

Parameters

path string
enabled bool

Returns

bool

TryHandleAsync(HttpContext)

Answer the request if a route covers its path; false leaves it to the rest of the mock.

public Task<bool> TryHandleAsync(HttpContext ctx)

Parameters

ctx HttpContext

Returns

Task<bool>