mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-01 07:03:29 +02:00
Updated Request Matching JsonPartialWilcardMatcher (markdown)
@@ -1 +1,66 @@
|
|||||||
.
|
## JSON (JsonPartialWilcardMatcher)
|
||||||
|
Based on JsonPartialMatcher but with wildcard (`*`) support.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
Matcher value
|
||||||
|
`{"test":"*"}` matches input `{"test":"abc" }`, but also input `{"test":"test" }` is matched.
|
||||||
|
|
||||||
|
|
||||||
|
#### C# option 1
|
||||||
|
```csharp
|
||||||
|
var server = WireMockServer.Start();
|
||||||
|
server
|
||||||
|
.Given(Request
|
||||||
|
.Create()
|
||||||
|
.WithPath("/jsonpartialmatcher1")
|
||||||
|
.WithBody(new JsonPartialWilcardMatcher("{ \"test\": \"*\" }"))
|
||||||
|
.UsingPost())
|
||||||
|
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
||||||
|
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonpartialbodytest1"" }"));
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JSON Mapping option 1
|
||||||
|
``` js
|
||||||
|
{
|
||||||
|
"Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
|
||||||
|
"Request": {
|
||||||
|
"Path": {
|
||||||
|
"Matchers": [
|
||||||
|
{
|
||||||
|
"Name": "WilcardMatcher",
|
||||||
|
"Pattern": "/jsonpartialmatcher1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Methods": [
|
||||||
|
"post"
|
||||||
|
],
|
||||||
|
"Body": {
|
||||||
|
"Matcher": {
|
||||||
|
"Name": "JsonPartialWilcardMatcher",
|
||||||
|
"Pattern": "{ \"test\": \"*\" }"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"StatusCode": 200,
|
||||||
|
"Body": "{ \"result\": \"jsonpartialbodytest1\" }",
|
||||||
|
"UseTransformer": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
``` js
|
||||||
|
// matching
|
||||||
|
{ "test": "abc" }
|
||||||
|
|
||||||
|
// also matching
|
||||||
|
{ "test": "test" }
|
||||||
|
|
||||||
|
// and also matching
|
||||||
|
{ "test": "abc", "extra": "?" }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 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