Added docs for MatchBehaviour.RejectOnMatch

Alastair Crabtree
2018-05-16 20:33:06 +01:00
parent 91e7f26f82
commit 10be63c900

@@ -158,6 +158,24 @@ server
Url like /somebody and /someting
```
### Reversing the match behaviour with `MatchBehaviour.RejectOnMatch`
The default behaviour for Matchers is MatchBehaviour.AcceptOnMatch so that when the matcher processes a request that corresponds with the matcher, the stubbed response is returned. In some scenarios you might want to reverse this behaviour so that the stubbed response is returned with the absence of a match.
e.g. You want to return `401 Unauthorised` if the caller does not provide a header containing the API Key:
```csharp
server
.Given(Request.Create()
.WithPath("/needs-a-key")
.UsingGet()
.WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch)
.UsingAnyMethod())
.RespondWith(Response.Create()
.WithStatusCode(HttpStatusCode.Unauthorized)
.WithBody(@"{ ""result"": ""api-key missing""}"));
```
## Response Templating
Response headers and bodies can optionally be rendered using [Handlebars.Net](https://github.com/rexm/Handlebars.Net) templates.
This enables attributes of the request to be used in generating the response e.g. to pass the value of a request ID header as a response header or render an identifier from part of the URL in the response body. To use this functionality, add `.WithTransformer()` to the response builder.