|
| 1 | +namespace Example.Test.WebApi; |
| 2 | + |
| 3 | +public class Get |
| 4 | +{ |
| 5 | + [Test] |
| 6 | + public async Task Get_WhenAppointmentsAreObtained_ShouldReturnsHttpStatusCodeOk() |
| 7 | + { |
| 8 | + // Arrange |
| 9 | + using var factory = new WebApplicationFactory<Program>(); |
| 10 | + var client = factory.CreateClient(); |
| 11 | + int expectedAppointments = 3; |
| 12 | + |
| 13 | + // Act |
| 14 | + var httpResponse = await client.GetAsync("/Appointment"); |
| 15 | + var result = await httpResponse |
| 16 | + .Content |
| 17 | + .ReadFromJsonAsync<ListedResult<GetAppointmentResponse>>(); |
| 18 | + |
| 19 | + // Asserts |
| 20 | + httpResponse.StatusCode.Should().Be(HttpStatusCode.OK); |
| 21 | + result.IsSuccess.Should().BeTrue(); |
| 22 | + result.Data.Should().HaveCount(expectedAppointments); |
| 23 | + } |
| 24 | + |
| 25 | + [Test] |
| 26 | + public async Task Get_WhenAppointmentIsObtained_ShouldReturnsHttpStatusCodeOk() |
| 27 | + { |
| 28 | + // Arrange |
| 29 | + using var factory = new WebApplicationFactory<Program>(); |
| 30 | + var client = factory.CreateClient(); |
| 31 | + var requestUri = "/Appointment/5dace456-13d9-42c5-92ea-89869ac44b5c"; |
| 32 | + |
| 33 | + // Act |
| 34 | + var httpResponse = await client.GetAsync(requestUri); |
| 35 | + var result = await httpResponse |
| 36 | + .Content |
| 37 | + .ReadFromJsonAsync<Result<GetAppointmentResponse>>(); |
| 38 | + |
| 39 | + // Asserts |
| 40 | + httpResponse.StatusCode.Should().Be(HttpStatusCode.OK); |
| 41 | + result.IsSuccess.Should().BeTrue(); |
| 42 | + result.Data.Should().NotBeNull(); |
| 43 | + } |
| 44 | + |
| 45 | + [Test] |
| 46 | + public async Task Get_WhenAppointmentIsNotFound_ShouldReturnsHttpStatusCodeNotFound() |
| 47 | + { |
| 48 | + // Arrange |
| 49 | + using var factory = new WebApplicationFactory<Program>(); |
| 50 | + var client = factory.CreateClient(); |
| 51 | + var requestUri = "/Appointment/5dace456"; |
| 52 | + |
| 53 | + // Act |
| 54 | + var httpResponse = await client.GetAsync(requestUri); |
| 55 | + var result = await httpResponse |
| 56 | + .Content |
| 57 | + .ReadFromJsonAsync<Result<GetAppointmentResponse>>(); |
| 58 | + |
| 59 | + // Asserts |
| 60 | + httpResponse.StatusCode.Should().Be(HttpStatusCode.NotFound); |
| 61 | + result.IsSuccess.Should().BeFalse(); |
| 62 | + result.Data.Should().BeNull(); |
| 63 | + } |
| 64 | + |
| 65 | + [TestCase("/People")] |
| 66 | + [TestCase("/Person")] |
| 67 | + public async Task Get_WhenPersonsAreObtained_ShouldReturnsHttpStatusCodeOk(string requestUri) |
| 68 | + { |
| 69 | + // Arrange |
| 70 | + using var factory = new WebApplicationFactory<Program>(); |
| 71 | + var client = factory.CreateClient(); |
| 72 | + int expectedPersons = 3; |
| 73 | + |
| 74 | + // Act |
| 75 | + var httpResponse = await client.GetAsync(requestUri); |
| 76 | + var result = await httpResponse |
| 77 | + .Content |
| 78 | + .ReadFromJsonAsync<Result<IEnumerable<GetPersonResponse>>>(); |
| 79 | + |
| 80 | + // Asserts |
| 81 | + httpResponse.StatusCode.Should().Be(HttpStatusCode.OK); |
| 82 | + result.IsSuccess.Should().BeTrue(); |
| 83 | + result.Data.Should().HaveCount(expectedPersons); |
| 84 | + } |
| 85 | + |
| 86 | + [Test] |
| 87 | + public async Task Get_WhenWeatherForecastAreObtained_ShouldReturnsHttpStatusCodeOk() |
| 88 | + { |
| 89 | + // Arrange |
| 90 | + using var factory = new WebApplicationFactory<Program>(); |
| 91 | + var client = factory.CreateClient(); |
| 92 | + int expectedWeatherForecast = 5; |
| 93 | + |
| 94 | + // Act |
| 95 | + var httpResponse = await client.GetAsync("/WeatherForecast"); |
| 96 | + var result = await httpResponse |
| 97 | + .Content |
| 98 | + .ReadFromJsonAsync<ListedResult<WeatherForecast>>(); |
| 99 | + |
| 100 | + // Asserts |
| 101 | + httpResponse.StatusCode.Should().Be(HttpStatusCode.OK); |
| 102 | + result.IsSuccess.Should().BeTrue(); |
| 103 | + result.Data.Should().HaveCount(expectedWeatherForecast); |
| 104 | + } |
| 105 | +} |
0 commit comments