Skip to content

Commit c81e005

Browse files
committedJan 23, 2022
update README.md
1 parent 1cdd496 commit c81e005

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed
 

‎README.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
11
# TestServer
2-
Yet another mock http server
2+
3+
`TestServer` is designed for unit test. It generates an `HttpClient` instance that you can inject to your service.
4+
5+
## Get Started
6+
7+
1. Install the package by nuget
8+
```bash
9+
dotnet add package Dubstep.TestUtilities.TestServer
10+
```
11+
2. Create a `TestServer` instance by `new TestServer()`
12+
3. Configure `RuleSet` of the `TestServer` instance
13+
4. Generate a HttpClient by `CreateClient()`
14+
15+
## Example
16+
```csharp
17+
public async Task ShouldGetResponse {
18+
// Arrange
19+
var server = new TestServer();
20+
var urlPattern = "\\?id=1";
21+
var okResponse = "[1,2,3]";
22+
server.CurrentRuleSet
23+
.AddRule()
24+
.WhenGet()
25+
.WhenUrlMatch(urlPattern)
26+
.SetOkResponse(okResponse);
27+
var client = server.CreateClient();
28+
29+
// Act
30+
var response = await client.GetAsync("/?id=1");
31+
32+
// Assert
33+
response.EnsureSuccessStatusCode();
34+
var message = await response.Content.ReadAsStringAsync();
35+
Assert.AreEqual(okResponse, message);
36+
}
37+
```
38+
39+
Check [the unit test cases](https://github.com/atwayne/TestServer/blob/master/test/TestServer.Tests/TestServerTests.cs) for more examples

0 commit comments

Comments
 (0)
Please sign in to comment.