mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-25 02:09:06 +02:00
Updated Stubbing and Request Matching (markdown)
@@ -52,22 +52,22 @@ WireMock supports matching of requests to stubs and verification queries using t
|
|||||||
* Request Body
|
* Request Body
|
||||||
|
|
||||||
### JSON (JsonMatcher)
|
### JSON (JsonMatcher)
|
||||||
Checks if a JSON object is DeepEqual.
|
Checks if a JSON object (or JSON as string) is DeepEqual.
|
||||||
|
|
||||||
#### C#
|
#### C# option 1
|
||||||
```csharp
|
```csharp
|
||||||
var server = FluentMockServer.Start();
|
var server = FluentMockServer.Start();
|
||||||
server
|
server
|
||||||
.Given(Request
|
.Given(Request
|
||||||
.Create()
|
.Create()
|
||||||
.WithPath("/jsonmatcher")
|
.WithPath("/jsonmatcher1")
|
||||||
.WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"))
|
.WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"))
|
||||||
.UsingPost())
|
.UsingPost())
|
||||||
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
|
||||||
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonbodytest"" }"));
|
.RespondWith(Response.Create().WithBody(@"{ ""result"": ""jsonbodytest1"" }"));
|
||||||
```
|
```
|
||||||
|
|
||||||
#### JSON Mapping
|
#### JSON Mapping option 1
|
||||||
``` js
|
``` js
|
||||||
{
|
{
|
||||||
"Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
|
"Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
|
||||||
@@ -99,6 +99,51 @@ server
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### C# option 2
|
||||||
|
```csharp
|
||||||
|
var server = FluentMockServer.Start();
|
||||||
|
server
|
||||||
|
.Given(Request
|
||||||
|
.Create()
|
||||||
|
.WithPath("/jsonmatcher2")
|
||||||
|
.WithBody(new JsonMatcher({ 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": "/jsonbodytest2",
|
||||||
|
"IgnoreCase": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Methods": [
|
||||||
|
"post"
|
||||||
|
],
|
||||||
|
"Body": {
|
||||||
|
"Matcher": {
|
||||||
|
"Name": "JsonMatcher",
|
||||||
|
"Pattern": { "x": 42, "s": "s" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"StatusCode": 200,
|
||||||
|
"Body": "{ \"result\": \"jsonbodytest2\" }",
|
||||||
|
"UseTransformer": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
// matching
|
// matching
|
||||||
{ "x": 1, "s": "s" }
|
{ "x": 1, "s": "s" }
|
||||||
|
|||||||
Reference in New Issue
Block a user