From 9d6df1c7c84002f5d7bfae9182b55c0089a7752f Mon Sep 17 00:00:00 2001 From: Alastair Crabtree Date: Sat, 12 May 2018 01:19:01 +0100 Subject: [PATCH] docs: improve sample app matcher to show use of reject on match --- .../MainApp.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/WireMock.Net.ConsoleApplication/MainApp.cs b/examples/WireMock.Net.ConsoleApplication/MainApp.cs index fc208efc..30cea771 100644 --- a/examples/WireMock.Net.ConsoleApplication/MainApp.cs +++ b/examples/WireMock.Net.ConsoleApplication/MainApp.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using Newtonsoft.Json; using WireMock.Matchers; using WireMock.RequestBuilders; @@ -152,12 +153,25 @@ namespace WireMock.Net.ConsoleApplication server .Given(Request.Create() - .WithPath("/reject") + .WithPath("/needs-a-key") .UsingGet() - .WithHeader("x", "1", MatchBehaviour.RejectOnMatch) + .WithHeader("api-key", "*", MatchBehaviour.AcceptOnMatch) .UsingAnyMethod()) .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 .Given(Request.Create().WithPath("/nobody").UsingGet())