Updated Request Matching JsonPartialMatcher (markdown)

Stef Heyenrath
2020-11-17 17:33:35 +01:00
parent c3204a6f11
commit aaec3e6bf9

@@ -12,10 +12,10 @@ server
.Given(Request
.Create()
.WithPath("/jsonpartialmatcher1")
.WithBody(new JsonPartialMatcher("{ \"x\": 42, \"s\": \"s\" }"))
.WithBody(new JsonPartialMatcher("{ \"test\": \"abc\" }"))
.UsingPost())
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonbodytest1"" }"));
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonpartialbodytest1"" }"));
```
#### JSON Mapping option 1
@@ -26,8 +26,8 @@ server
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/jsonmatcher1"
"Name": "JsonPartialMatcher",
"Pattern": "/jsonpartialmatcher1"
}
]
},
@@ -37,57 +37,13 @@ server
"Body": {
"Matcher": {
"Name": "JsonMatcher",
"Pattern": "{ \"x\": 42, \"s\": \"s\" }"
"Pattern": "{ \"test\": \"abc\" }"
}
}
},
"Response": {
"StatusCode": 200,
"Body": "{ \"result\": \"jsonbodytest\" }",
"UseTransformer": false
}
}
```
#### C# option 2
```csharp
var server = WireMockServer.Start();
server
.Given(Request
.Create()
.WithPath("/jsonmatcher2")
.WithBody(new JsonMatcher(new { 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": "/jsonmatcher2"
}
]
},
"Methods": [
"post"
],
"Body": {
"Matcher": {
"Name": "JsonMatcher",
"Pattern": { "x": 42, "s": "s" }
}
}
},
"Response": {
"StatusCode": 200,
"Body": "{ \"result\": \"jsonbodytest2\" }",
"Body": "{ \"result\": \"jsonpartialbodytest1\" }",
"UseTransformer": false
}
}
@@ -95,12 +51,12 @@ server
```
// matching
{ "x": 42, "s": "s" }
{ "test": "abc" }
// not matching
{ "x": 42, "s": "?" }
// also matching
{ "test": "abc", "extra": "?" }
```
#### C# option 3
#### IgnoreCase
It's also possible to use set `IgnoreCase` to true, this means that the PropertNames and PropertyValues will be matched regarding any case.
Same logic as the normal JsonMatcher.