mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-13 13:56:31 +01:00
prio
20
Stubbing.md
20
Stubbing.md
@@ -138,7 +138,25 @@ All of the standard helpers (template functions) provided by the C# Handlebars i
|
||||
`{{capitalize request.query.search}}`
|
||||
|
||||
## Stub priority
|
||||
*TODO*
|
||||
It is sometimes the case that you’ll want to declare two or more stub mappings that “overlap”, in that a given request would be a match for more than one of them. By default, WireMock.NET will use the most recently added matching stub to satisfy the request. However, in some cases it is useful to exert more control.
|
||||
|
||||
One example of this might be where you want to define a catch-all stub for any URL that doesn’t match any more specific cases. Adding a priority to a stub mapping facilitates this:
|
||||
|
||||
```csharp
|
||||
var server = FluentMockServer.Start();
|
||||
|
||||
// Catch-all case
|
||||
server
|
||||
.Given(Request.Create().WithPath("/api/*"))
|
||||
.AtPriority(100)
|
||||
.RespondWith(Responses.Create().WithStatusCode(401));
|
||||
|
||||
// Specific case
|
||||
server
|
||||
.Given(Request.Create().WithPath("/api/specific-resource"))
|
||||
.AtPriority(1)
|
||||
.RespondWith(Responses.Create().WithStatusCode(200));
|
||||
```
|
||||
|
||||
## Verify interactions
|
||||
The server keeps a log of the received requests. You can use this log to verify the interactions that have been done with the server during a test.
|
||||
|
||||
Reference in New Issue
Block a user