mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 15:23:47 +01:00
Updated Request Matching JsonPartialMatcher (markdown)
@@ -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.
|
||||
Reference in New Issue
Block a user