-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathWeatherForecastTests.cs
47 lines (38 loc) · 1.23 KB
/
WeatherForecastTests.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
using Microsoft.AspNetCore.Mvc.Testing; // To use WebApplicationFactory<T>.
using System.Net.Http.Json; // To use ReadFromJsonAsync.
using Northwind.WebApi; // To use Program.
namespace WebServiceTests;
public class WeatherForecastTests :
IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
private const string relativePath = "/weatherforecast";
public WeatherForecastTests(WebApplicationFactory<Program> factory)
{
_factory = factory;
}
[Fact]
public async Task Get_WeatherForecasts_ReturnsSuccessStatusCode()
{
// Arrange
HttpClient client = _factory.CreateClient();
// Act
HttpResponseMessage response =
await client.GetAsync(relativePath);
// Assert
Assert.True(response.IsSuccessStatusCode); // Status Code 200-299.
}
[Fact]
public async Task Get_WeatherForecasts_ReturnsFiveForecasts()
{
// Arrange
HttpClient client = _factory.CreateClient();
// Act
HttpResponseMessage response = await client.GetAsync(relativePath);
WeatherForecast[]? forecasts = await response.Content
.ReadFromJsonAsync<WeatherForecast[]>();
// Assert
Assert.NotNull(forecasts);
Assert.True(forecasts.Length == 5);
}
}