mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 18:59:02 +02:00
Updated Stubbing (markdown)
15
Stubbing.md
15
Stubbing.md
@@ -1,5 +1,4 @@
|
||||
# Stubbing
|
||||
|
||||
The core feature of WireMock is the ability to return predefined HTTP responses for requests matching criteria.
|
||||
|
||||
## Start a server
|
||||
@@ -17,7 +16,7 @@ The following code will configure a response with a status of 200 to be returned
|
||||
var server = FluentMockServer.Start();
|
||||
server
|
||||
.Given(
|
||||
Request.Create().WithUrl("/some/thing").UsingGet()
|
||||
Request.Create().WithPath("/some/thing").UsingGet()
|
||||
)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
@@ -34,7 +33,7 @@ A response body in binary format can be specified as a `byte[]` via an overloade
|
||||
var server = FluentMockServer.Start();
|
||||
server
|
||||
.Given(
|
||||
Request.Create().WithUrl("/some/thing").UsingGet()
|
||||
Request.Create().WithPath("/some/thing").UsingGet()
|
||||
)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
@@ -61,7 +60,7 @@ A JSON body will be considered to match a path expression if the expression retu
|
||||
var server = FluentMockServer.Start();
|
||||
server
|
||||
.Given(
|
||||
Request.Create().WithUrl("/some/thing").UsingGet()
|
||||
Request.Create().WithPath("/some/thing").UsingGet()
|
||||
.WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
)
|
||||
.RespondWith(Response.Create().WithBody("Hello"));
|
||||
@@ -85,7 +84,7 @@ WireMock delegates to [XPath2.Net](https://github.com/StefH/XPath2.Net), therefo
|
||||
var server = FluentMockServer.Start();
|
||||
server
|
||||
.Given(
|
||||
Request.Create().WithUrl("/some/thing").UsingGet()
|
||||
Request.Create().WithPath("/some/thing").UsingGet()
|
||||
.WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
|
||||
)
|
||||
.RespondWith(Response.WithBody("Hello"));
|
||||
@@ -109,7 +108,7 @@ Example:
|
||||
var server = FluentMockServer.Start();
|
||||
server
|
||||
.Given(
|
||||
Request.Create().WithUrl("/some/thing").UsingGet()
|
||||
Request.Create().WithPath("/some/thing").UsingGet()
|
||||
)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
@@ -150,7 +149,7 @@ var allRequests = server.RequestLogs;
|
||||
If you need to be more specific on the requests that have been send to the server, you can use the very same fluent API that allows to define routes:
|
||||
```csharp
|
||||
var customerReadRequests = server.SearchLogsFor(
|
||||
Request.Create().WithUrl("/api/customer*").UsingGet()
|
||||
Request.Create().WithPath("/api/customer*").UsingGet()
|
||||
);
|
||||
```
|
||||
|
||||
@@ -167,7 +166,7 @@ Delays can also be configured at route level:
|
||||
```csharp
|
||||
var server = FluentMockServer.Start();
|
||||
server
|
||||
.Given(Request.Create().WithUrl("/slow"))
|
||||
.Given(Request.Create().WithPath("/slow"))
|
||||
.RespondWith(
|
||||
Responses.Create()
|
||||
.WithStatusCode(200)
|
||||
|
||||
Reference in New Issue
Block a user