mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-19 15:31:39 +02:00
docs: improve sample app matcher to show use of reject on match
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Net;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
@@ -152,12 +153,25 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.WithPath("/reject")
|
.WithPath("/needs-a-key")
|
||||||
.UsingGet()
|
.UsingGet()
|
||||||
.WithHeader("x", "1", MatchBehaviour.RejectOnMatch)
|
.WithHeader("api-key", "*", MatchBehaviour.AcceptOnMatch)
|
||||||
.UsingAnyMethod())
|
.UsingAnyMethod())
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithBody(@"{ ""result"": ""reject""}"));
|
.WithStatusCode(HttpStatusCode.OK)
|
||||||
|
.WithBody(@"{ ""result"": ""api-key found""}"));
|
||||||
|
|
||||||
|
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""}"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
||||||
|
|||||||
Reference in New Issue
Block a user