mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-12 21:35:55 +01:00
Updated Request Matching (markdown)
@@ -94,8 +94,7 @@ server
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "WildcardMatcher",
|
||||
"Pattern": "/jsonbodytest",
|
||||
"IgnoreCase": false
|
||||
"Pattern": "/jsonmatcher1"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -139,8 +138,7 @@ server
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "WildcardMatcher",
|
||||
"Pattern": "/jsonbodytest2",
|
||||
"IgnoreCase": false
|
||||
"Pattern": "/jsonmatcher2"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -167,10 +165,61 @@ server
|
||||
{ "x": 42, "s": "s" }
|
||||
|
||||
// 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)
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user