mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-21 00:28:59 +01:00
WireMockServer
14
Stubbing.md
14
Stubbing.md
@@ -4,16 +4,16 @@ The core feature of WireMock is the ability to return predefined HTTP responses
|
||||
## Start a server
|
||||
First thing first, to start a server it is as easy as calling a static method, and your done!
|
||||
```csharp
|
||||
var server = FluentMockServer.Start();
|
||||
var server = WireMockServer.Start();
|
||||
```
|
||||
You can pass as an argument a port number but if you do not an available port will be chosen for you. Hence the above line of code start aserver bounded to locahost a random port.
|
||||
You can pass as an argument a port number but if you do not an available port will be chosen for you. Hence the above line of code start a server bounded to localhost a random port.
|
||||
To know on which port your server is listening, just use server property *Port*.
|
||||
|
||||
## Basic stubbing
|
||||
The following code will configure a response with a status of 200 to be returned when the relative URL exactly matches /some/thing (including query parameters). The body of the response will be “Hello world!” and a Content-Type header will be sent with a value of text-plain.
|
||||
|
||||
```csharp
|
||||
var server = FluentMockServer.Start();
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.Given(
|
||||
Request.Create().WithPath("/some/thing").UsingGet()
|
||||
@@ -30,7 +30,7 @@ HTTP methods currently supported are: GET, POST, PUT, DELETE, HEAD. You can spec
|
||||
A response body in binary format can be specified as a `byte[]` via an overloaded `WithBody()`:
|
||||
|
||||
```csharp
|
||||
var server = FluentMockServer.Start();
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.Given(
|
||||
Request.Create().WithPath("/some/thing").UsingGet()
|
||||
@@ -47,7 +47,7 @@ It is sometimes the case that you’ll want to declare two or more stub mappings
|
||||
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();
|
||||
var server = WireMockServer.Start();
|
||||
|
||||
// Catch-all case
|
||||
server
|
||||
@@ -76,7 +76,7 @@ var customerReadRequests = server.SearchLogsFor(
|
||||
```
|
||||
|
||||
## Simulating delays
|
||||
A server can be configured with a global delay that will be applied to all requests. To do so you need to call method FluentMockServer.AddRequestProcessingDelay() as below:
|
||||
A server can be configured with a global delay that will be applied to all requests. To do so you need to call method WireMockServer.AddRequestProcessingDelay() as below:
|
||||
```csharp
|
||||
var server = FluentMockServer.Start();
|
||||
|
||||
@@ -86,7 +86,7 @@ server.AddRequestProcessingDelay(TimeSpan.FromSeconds(30));
|
||||
|
||||
Delays can also be configured at route level:
|
||||
```csharp
|
||||
var server = FluentMockServer.Start();
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.Given(Request.Create().WithPath("/slow"))
|
||||
.RespondWith(
|
||||
|
||||
Reference in New Issue
Block a user