mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 07:51:41 +02:00
Updated Request Matching (markdown)
@@ -94,8 +94,7 @@ server
|
|||||||
"Matchers": [
|
"Matchers": [
|
||||||
{
|
{
|
||||||
"Name": "WildcardMatcher",
|
"Name": "WildcardMatcher",
|
||||||
"Pattern": "/jsonbodytest",
|
"Pattern": "/jsonmatcher1"
|
||||||
"IgnoreCase": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -139,8 +138,7 @@ server
|
|||||||
"Matchers": [
|
"Matchers": [
|
||||||
{
|
{
|
||||||
"Name": "WildcardMatcher",
|
"Name": "WildcardMatcher",
|
||||||
"Pattern": "/jsonbodytest2",
|
"Pattern": "/jsonmatcher2"
|
||||||
"IgnoreCase": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -167,10 +165,61 @@ server
|
|||||||
{ "x": 42, "s": "s" }
|
{ "x": 42, "s": "s" }
|
||||||
|
|
||||||
// not matching
|
// not matching
|
||||||
{ "x": 42, "s": "x" }
|
{ "x": 42, "s": "?" }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### C# option 3
|
||||||
|
It's also possible to use set `IgnoreCase` to true, this means that the PropertNames and PropertyValues will be matced regarding any case.
|
||||||
|
```csharp
|
||||||
|
var server = FluentMockServer.Start();
|
||||||
|
server
|
||||||
|
.Given(Request
|
||||||
|
.Create()
|
||||||
|
.WithPath("/jsonmatcher3")
|
||||||
|
.WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"), true)
|
||||||
|
.UsingPost())
|
||||||
|
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
||||||
|
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonmatcher3 ok"" }"));
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JSON Mapping option 3
|
||||||
|
``` js
|
||||||
|
{
|
||||||
|
"Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
|
||||||
|
"Request": {
|
||||||
|
"Path": {
|
||||||
|
"Matchers": [
|
||||||
|
{
|
||||||
|
"Name": "WildcardMatcher",
|
||||||
|
"Pattern": "/jsonmatcher1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Methods": [
|
||||||
|
"post"
|
||||||
|
],
|
||||||
|
"Body": {
|
||||||
|
"Matcher": {
|
||||||
|
"Name": "JsonMatcher",
|
||||||
|
"IgnoreCase": true,
|
||||||
|
"Pattern": "{ \"x\": 42, \"s\": \"s\" }"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"StatusCode": 200,
|
||||||
|
"Body": "{ \"result\": \"jsonmatcher3 ok\" }",
|
||||||
|
"UseTransformer": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
// matching
|
||||||
|
{ "X": 42, "s": "S" }
|
||||||
|
```
|
||||||
|
|
||||||
### JSON Path (JsonPathMatcher)
|
### JSON Path (JsonPathMatcher)
|
||||||
Deems a match if the attribute value is valid JSON and matches the JSON Path expression supplied.
|
Deems a match if the attribute value is valid JSON and matches the JSON Path expression supplied.
|
||||||
A JSON body will be considered to match a path expression if the expression returns either a non-null single value (string, integer etc.), or a non-empty object or array.
|
A JSON body will be considered to match a path expression if the expression returns either a non-null single value (string, integer etc.), or a non-empty object or array.
|
||||||
|
|||||||
Reference in New Issue
Block a user