mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 01:08:49 +02:00
Updated Request Matchers (markdown)
@@ -113,88 +113,6 @@ server
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## CSharp Code (CSharpCodeMatcher)
|
|
||||||
*Advanced!* With this matcher you can use complex C# code to match an JObject or string value.
|
|
||||||
* You need to include the NuGet package [WireMock.Net.Matchers.CSharpCode](https://www.nuget.org/packages/WireMock.Net.Matchers.CSharpCode/)
|
|
||||||
* Note that this functionality will only work if enabled in the settings (`AllowCSharpCodeMatcher = true`).
|
|
||||||
* The argument-name from the string or JObject to match will be `it`.
|
|
||||||
|
|
||||||
#### C# option
|
|
||||||
```csharp
|
|
||||||
var server = WireMockServer.Start();
|
|
||||||
server
|
|
||||||
.Given(Request.Create().WithPath("/cs")
|
|
||||||
.WithParam("from", new CSharpCodeMatcher("return it == \"x\";")))
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithBody("cs match")
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### JSON Mapping option
|
|
||||||
``` js
|
|
||||||
{
|
|
||||||
"Guid": "67ae335b-5d79-42dc-8ca7-236280ab9211",
|
|
||||||
"Priority": 0,
|
|
||||||
"Request": {
|
|
||||||
"Path": {
|
|
||||||
"Matchers": [
|
|
||||||
{
|
|
||||||
"Name": "WildcardMatcher",
|
|
||||||
"Pattern": "/cs"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"Params": [
|
|
||||||
{
|
|
||||||
"Name": "from",
|
|
||||||
"Matchers": [
|
|
||||||
{
|
|
||||||
"Name": "CSharpCodeMatcher",
|
|
||||||
"Pattern": "return it == \"x\";"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Body": {}
|
|
||||||
},
|
|
||||||
"Response": {
|
|
||||||
"Body": "cs match"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## CSharp Code (CSharpCodeMatcher)
|
|
||||||
*Advanced!* With this matcher you can use complex C# code to match an JObject or string value.
|
|
||||||
* You need to include the NuGet package [WireMock.Net.Matchers.CSharpCode](https://www.nuget.org/packages/WireMock.Net.Matchers.CSharpCode/)
|
|
||||||
* Note that this functionality will only work if enabled in the settings (`AllowCSharpCodeMatcher = true`).
|
|
||||||
* The argument-name from the string or JObject to match will be `it`.
|
|
||||||
|
|
||||||
#### C# option
|
|
||||||
```csharp
|
|
||||||
var server = WireMockServer.Start();
|
|
||||||
server
|
|
||||||
.Given(Request.Create().WithPath("/cs")
|
|
||||||
.WithParam("from", new CSharpCodeMatcher("return it == \"x\";")))
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithBody("cs match")
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
### Jmes Path (JmesPathMatcher)
|
|
||||||
The JMESPath language is described in an ABNF grammar with a complete specification.
|
|
||||||
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.
|
|
||||||
|
|
||||||
#### C#
|
|
||||||
```csharp
|
|
||||||
var server = WireMockServer.Start();
|
|
||||||
server
|
|
||||||
.Given(
|
|
||||||
Request.Create().WithPath("/jmespath_example").UsingGet()
|
|
||||||
.WithBody(new JmesPathMatcher("things.name == 'RequiredThing"));
|
|
||||||
)
|
|
||||||
.RespondWith(Response.Create().WithBody("Hello"));
|
|
||||||
```
|
|
||||||
|
|
||||||
#### JSON Mapping
|
#### JSON Mapping
|
||||||
``` js
|
``` js
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user