mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:08:28 +02:00
Updated Request Matching JsonPartialMatcher (markdown)
@@ -9,17 +9,17 @@ Matcher value
|
|||||||
```csharp
|
```csharp
|
||||||
var server = WireMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
server
|
server
|
||||||
.Given(Request
|
.Given(Request
|
||||||
.Create()
|
.Create()
|
||||||
.WithPath("/jsonpartialmatcher1")
|
.WithPath("/jsonpartialmatcher1")
|
||||||
.WithBody(new JsonPartialMatcher("{ \"test\": \"abc\" }"))
|
.WithBody(new JsonPartialMatcher("{ \"test\": \"abc\" }"))
|
||||||
.UsingPost())
|
.UsingPost())
|
||||||
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
||||||
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonpartialbodytest1"" }"));
|
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonpartialbodytest1"" }"));
|
||||||
```
|
```
|
||||||
|
|
||||||
#### JSON Mapping option 1
|
#### JSON Mapping option 1
|
||||||
``` js
|
``` json
|
||||||
{
|
{
|
||||||
"Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
|
"Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
|
||||||
"Request": {
|
"Request": {
|
||||||
@@ -59,4 +59,51 @@ server
|
|||||||
|
|
||||||
#### IgnoreCase
|
#### 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.
|
||||||
|
|
||||||
|
#### Use Regex
|
||||||
|
It's possible to add a property `Regex` with the value `true`, with this option set, PropertyValues are matched using a specified regular expression.
|
||||||
|
|
||||||
|
Example for C# when you want to match the `id` for any number.
|
||||||
|
```csharp
|
||||||
|
var server = WireMockServer.Start();
|
||||||
|
server
|
||||||
|
.Given(Request
|
||||||
|
.Create()
|
||||||
|
.WithPath("/jsonpartialmatcher1")
|
||||||
|
.WithBody(new JsonPartialMatcher("{ \"id\": \"^\\d+$\" }", false, false, true))
|
||||||
|
.UsingPost())
|
||||||
|
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
||||||
|
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonpartialbodytest1"" }"));
|
||||||
|
```
|
||||||
|
|
||||||
|
Or in JSON mapping:
|
||||||
|
``` json
|
||||||
|
{
|
||||||
|
"Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
|
||||||
|
"Request": {
|
||||||
|
"Methods": [
|
||||||
|
"post"
|
||||||
|
],
|
||||||
|
"Body": {
|
||||||
|
"Matcher": {
|
||||||
|
"Name": "JsonPartialWildcardMatcher",
|
||||||
|
"Regex": true, // <--- add this property
|
||||||
|
"Pattern": {
|
||||||
|
"applicationId": "*",
|
||||||
|
"currency": "EUR",
|
||||||
|
"price": "^\\d*$", // <--- use regex
|
||||||
|
"externalId": "*",
|
||||||
|
"transactionDescription": "*",
|
||||||
|
},
|
||||||
|
"IgnoreCase": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"StatusCode": 200,
|
||||||
|
"Body": "{ \"result\": \"jsonpartialbodytest1-with-regex\" }",
|
||||||
|
"UseTransformer": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user