-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
BooksTests.cs
83 lines (67 loc) · 2.24 KB
/
BooksTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using HappyCode.NetCoreBoilerplate.BooksModule.Dtos;
using HappyCode.NetCoreBoilerplate.BooksModule.IntegrationTests.Extensions;
using HappyCode.NetCoreBoilerplate.BooksModule.IntegrationTests.Infrastructure;
namespace HappyCode.NetCoreBoilerplate.Api.IntegrationTests
{
[Collection(nameof(TestServerClientCollection))]
public class BooksTests
{
private readonly HttpClient _client;
public BooksTests(TestServerClientFixture fixture)
{
_client = fixture.Client;
}
[Fact]
public Task GetAll_should_return_Ok_with_results()
{
//when
var result = _client.GetAsync("api/books");
//then
return VerifyResult(result);
}
[Fact]
public Task Get_should_return_NotFound_when_no_book()
{
//when
var result = _client.GetAsync($"api/books/{int.MaxValue}");
//then
return VerifyResult(result);
}
[Fact]
public Task Get_should_return_Ok_and_expected_result()
{
//when
var result = _client.GetAsync("api/books/1");
//then
return VerifyResult(result);
}
[Fact]
public Task Post_should_return_NoContent()
{
//given
var book = new BookDto { Title = "Some_test_title" };
//when
var result = _client.PostAsync("api/books", book.ToStringContent());
//then
return VerifyResult(result);
}
[Fact]
public Task Delete_should_return_NoContent()
{
//when
var result = _client.DeleteAsync("api/books/1");
//then
return VerifyResult(result);
}
[Fact]
public Task Delete_should_return_NotFound_when_no_book()
{
//when
var result = _client.DeleteAsync($"api/books/{int.MaxValue}");
//then
return VerifyResult(result);
}
private static Task VerifyResult(Task<HttpResponseMessage> result) =>
Verifier.Verify(result).UseDirectory("Verify");
}
}