|
8 | 8 | using System.Text.Json.Nodes; |
9 | 9 | using System.Threading.Tasks; |
10 | 10 |
|
11 | | -namespace exercise.tests.IntegrationTests |
12 | | -{ |
13 | | - internal class CohortTests |
14 | | - { |
15 | | - private WebApplicationFactory<Program> _factory; |
16 | | - private HttpClient _client; |
17 | | - |
18 | | - [SetUp] |
19 | | - public void SetUp() |
20 | | - { |
21 | | - // Arrange |
22 | | - _factory = new WebApplicationFactory<Program>(); |
23 | | - _client = _factory.CreateClient(); |
24 | | - } |
25 | | - |
26 | | - [TearDown] |
27 | | - public void TearDown() |
28 | | - { |
29 | | - _client.Dispose(); |
30 | | - _factory.Dispose(); |
31 | | - } |
32 | | - |
33 | | - [Test] |
34 | | - public async Task GetAllCohorts() |
35 | | - { |
36 | | - var response = await _client.GetAsync("/cohorts"); |
37 | | - var contentString = await response.Content.ReadAsStringAsync(); |
38 | | - var message = string.IsNullOrWhiteSpace(contentString) ? null : JsonNode.Parse(contentString); |
39 | | - |
40 | | - Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); |
41 | | - Assert.That(message, Is.Not.Null); |
42 | | - //Assert.That(message?["message"]?.GetValue<string>(), Is.EqualTo("success")); |
43 | | - |
44 | | - var data = message?["data"]?.AsArray(); |
45 | | - Assert.That(data, Is.Not.Null); |
46 | | - Assert.That(data!.Count, Is.GreaterThan(0)); |
47 | | - |
48 | | - var cohort = data!.First(); |
49 | | - Assert.That(cohort["id"]?.GetValue<int>(), Is.GreaterThan(0)); |
50 | | - Assert.That(cohort["title"].GetValue<string>, Is.Not.Null); |
51 | | - //Assert.That(cohort["courses"]["students"].GetValue<Array>, Is.Not.Null); |
52 | | - } |
53 | | - } |
54 | | -} |
| 11 | +namespace exercise.tests.IntegrationTests{} |
0 commit comments