From 8c6c254130e74e0998e99170a110ea1ba848cb1c Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 26 Jun 2018 17:34:44 +0200 Subject: [PATCH] Updated Stubbing and Request Matching (markdown) --- Stubbing-and-Request-Matching.md | 55 +++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/Stubbing-and-Request-Matching.md b/Stubbing-and-Request-Matching.md index 86920b2..18560a8 100644 --- a/Stubbing-and-Request-Matching.md +++ b/Stubbing-and-Request-Matching.md @@ -52,22 +52,22 @@ WireMock supports matching of requests to stubs and verification queries using t * Request Body ### JSON (JsonMatcher) -Checks if a JSON object is DeepEqual. +Checks if a JSON object (or JSON as string) is DeepEqual. -#### C# +#### C# option 1 ```csharp var server = FluentMockServer.Start(); server .Given(Request .Create() - .WithPath("/jsonmatcher") + .WithPath("/jsonmatcher1") .WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }")) .UsingPost()) .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2") - .RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonbodytest"" }")); + .RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonbodytest1"" }")); ``` -#### JSON Mapping +#### JSON Mapping option 1 ``` js { "Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2", @@ -99,6 +99,51 @@ server } ``` +#### C# option 2 +```csharp +var server = FluentMockServer.Start(); +server + .Given(Request + .Create() + .WithPath("/jsonmatcher2") + .WithBody(new JsonMatcher({ x = 42, s = "s" })) + .UsingPost()) + .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2") + .RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonbodytest2"" }")); +``` + +#### JSON Mapping option 2 +``` js +{ + "Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2", + "Request": { + "Path": { + "Matchers": [ + { + "Name": "WildcardMatcher", + "Pattern": "/jsonbodytest2", + "IgnoreCase": false + } + ] + }, + "Methods": [ + "post" + ], + "Body": { + "Matcher": { + "Name": "JsonMatcher", + "Pattern": { "x": 42, "s": "s" } + } + } + }, + "Response": { + "StatusCode": 200, + "Body": "{ \"result\": \"jsonbodytest2\" }", + "UseTransformer": false + } +} +``` + ``` // matching { "x": 1, "s": "s" }