mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-07-18 10:41:26 +02:00
WireMockServer
+7
-7
@@ -4,16 +4,16 @@ The core feature of WireMock is the ability to return predefined HTTP responses
|
|||||||
## Start a server
|
## Start a server
|
||||||
First thing first, to start a server it is as easy as calling a static method, and your done!
|
First thing first, to start a server it is as easy as calling a static method, and your done!
|
||||||
```csharp
|
```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*.
|
To know on which port your server is listening, just use server property *Port*.
|
||||||
|
|
||||||
## Basic stubbing
|
## 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.
|
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
|
```csharp
|
||||||
var server = FluentMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
server
|
server
|
||||||
.Given(
|
.Given(
|
||||||
Request.Create().WithPath("/some/thing").UsingGet()
|
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()`:
|
A response body in binary format can be specified as a `byte[]` via an overloaded `WithBody()`:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var server = FluentMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
server
|
server
|
||||||
.Given(
|
.Given(
|
||||||
Request.Create().WithPath("/some/thing").UsingGet()
|
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:
|
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
|
```csharp
|
||||||
var server = FluentMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
|
|
||||||
// Catch-all case
|
// Catch-all case
|
||||||
server
|
server
|
||||||
@@ -76,7 +76,7 @@ var customerReadRequests = server.SearchLogsFor(
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Simulating delays
|
## 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
|
```csharp
|
||||||
var server = FluentMockServer.Start();
|
var server = FluentMockServer.Start();
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ server.AddRequestProcessingDelay(TimeSpan.FromSeconds(30));
|
|||||||
|
|
||||||
Delays can also be configured at route level:
|
Delays can also be configured at route level:
|
||||||
```csharp
|
```csharp
|
||||||
var server = FluentMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath("/slow"))
|
.Given(Request.Create().WithPath("/slow"))
|
||||||
.RespondWith(
|
.RespondWith(
|
||||||
|
|||||||
Reference in New Issue
Block a user