mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 13:00:33 +01:00
Page:
Request Matching
Pages
Admin API Reference
Compatibility WireMock.org
Conflict on Microsoft.CodeAnalysis.CSharp
Cors
Could not load file or assembly RestEase
Development Information
Faults
FluentAssertions
Home
KestrelServerOptions
Mapping
MimeKit and MimeKitLite
MyGet preview versions
Pact
Proxying
References
RegexExtended
Request Matcher FormUrlEncodedMatcher
Request Matchers
Request Matching CSharpCode
Request Matching GraphQLMatcher
Request Matching JsonMatcher
Request Matching JsonPartialMatcher
Request Matching JsonPartialWildcardMatcher
Request Matching JsonPathMatcher
Request Matching MimePartMatcher
Request Matching ProtoBuf
Request Matching Tips
Request Matching
Response Templating
Scenarios and States
Settings
Stubbing
Using HTTPS (SSL)
Using WireMock in UnitTests
Using WireMock.Net.Aspire
Using WireMock.Net.Testcontainers
Webhook
What Is WireMock.Net
WireMock as a (Azure) Web App
WireMock as a Windows Service
WireMock as a standalone process
WireMock as dotnet tool
WireMock commandline parameters
WireMock.Org
Xamarin Could not load file or assembly
Clone
This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
1️⃣ Request Matching
WireMock.Net supports matching of requests to stubs and verification queries using the following parts:
- Path
- URL
- HTTP Method
- Query parameters
- Headers
- Cookies
- Request Body
Generic information on matchers:
Most matchers have 2 extra properties:
- IgnoreCase = define that the matcher should match ignoring the case
- RejectOnMatch = define that when the matcher does match successfully, this should be counted as a invalid (non-matching) match
Example Matchings
Path
C# example
server
.Given(Request
.Create()
.WithPath("/test")
JSON example
{
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/path",
"IgnoreCase": true
}
]
}
}
}
Url
C# example
server
.Given(Request
.Create()
.WithUrl("https://localhost/test")
JSON example
{
"Request": {
"Url": {
"Matchers": [
{
"Name": "RegexMatcher",
"Pattern": "/clients[?]",
"IgnoreCase": true
}
]
}
}
}
Query Parameters
C# example
server
.Given(Request
.Create()
.WithParam("search", "abc")
JSON example
{
"Request": {
"Params": [
{
"Name": "search",
"Matchers": [
{
"Name": "ExactMatcher",
"Pattern": "abc"
}
]
}
]
}
}
Headers
C#
// todo
JSON
{
"Request": {
"Headers": [
{
"Name": "api-key",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "abc*"
"IgnoreCase": true
}
]
}
]
}
}
Note that when you want to match on a missing header, you need to use this mapping:
{
"Request": {
"Headers": [
{
"Name": "api-key",
"IgnoreCase": true,
"RejectOnMatch": true
}
]
}
This means that when the header-key api-key (ignoring the casing) is missing the header mapping will match because RejectOnMatch is true.
2️⃣ Matchers
Content moved to Request Matchers.
Pages
- Home
- What is WireMock.Net
- WireMock.Org
- References
- Settings
- Admin REST API
- Proxying
- Stubbing
- Webhook
- Request Matching
- Response Templating
- Unit Testing
- Using WireMock
- Advanced
- Errors