mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 16:58:27 +02:00
Updated Request Matching JsonPartialMatcher (markdown)
@@ -12,10 +12,10 @@ server
|
|||||||
.Given(Request
|
.Given(Request
|
||||||
.Create()
|
.Create()
|
||||||
.WithPath("/jsonpartialmatcher1")
|
.WithPath("/jsonpartialmatcher1")
|
||||||
.WithBody(new JsonPartialMatcher("{ \"x\": 42, \"s\": \"s\" }"))
|
.WithBody(new JsonPartialMatcher("{ \"test\": \"abc\" }"))
|
||||||
.UsingPost())
|
.UsingPost())
|
||||||
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
||||||
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonbodytest1"" }"));
|
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonpartialbodytest1"" }"));
|
||||||
```
|
```
|
||||||
|
|
||||||
#### JSON Mapping option 1
|
#### JSON Mapping option 1
|
||||||
@@ -26,8 +26,8 @@ server
|
|||||||
"Path": {
|
"Path": {
|
||||||
"Matchers": [
|
"Matchers": [
|
||||||
{
|
{
|
||||||
"Name": "WildcardMatcher",
|
"Name": "JsonPartialMatcher",
|
||||||
"Pattern": "/jsonmatcher1"
|
"Pattern": "/jsonpartialmatcher1"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -37,57 +37,13 @@ server
|
|||||||
"Body": {
|
"Body": {
|
||||||
"Matcher": {
|
"Matcher": {
|
||||||
"Name": "JsonMatcher",
|
"Name": "JsonMatcher",
|
||||||
"Pattern": "{ \"x\": 42, \"s\": \"s\" }"
|
"Pattern": "{ \"test\": \"abc\" }"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Response": {
|
"Response": {
|
||||||
"StatusCode": 200,
|
"StatusCode": 200,
|
||||||
"Body": "{ \"result\": \"jsonbodytest\" }",
|
"Body": "{ \"result\": \"jsonpartialbodytest1\" }",
|
||||||
"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\" }",
|
|
||||||
"UseTransformer": false
|
"UseTransformer": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,12 +51,12 @@ server
|
|||||||
|
|
||||||
```
|
```
|
||||||
// matching
|
// matching
|
||||||
{ "x": 42, "s": "s" }
|
{ "test": "abc" }
|
||||||
|
|
||||||
// not matching
|
// also matching
|
||||||
{ "x": 42, "s": "?" }
|
{ "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.
|
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.
|
Same logic as the normal JsonMatcher.
|
||||||
Reference in New Issue
Block a user