mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-21 17:10:26 +01: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
|
||||
|
||||
### 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
|
||||
var server = FluentMockServer.Start();
|
||||
server
|
||||
.Given(Request
|
||||
.Create()
|
||||
.WithPath("/jsonmatcher")
|
||||
.WithPath("/jsonmatcher1")
|
||||
.WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"))
|
||||
.UsingPost())
|
||||
.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
|
||||
{
|
||||
"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
|
||||
{ "x": 1, "s": "s" }
|
||||
|
||||
Reference in New Issue
Block a user