public class JobTypeControllerTests :
IClassFixture<CustomWebApplicationFactory<Startup>>
{
private readonly HttpClient _client;
private readonly CustomWebApplicationFactory<Startup>
_factory;
public JobTypeControllerTests(
CustomWebApplicationFactory<Startup> factory)
{
_factory = factory;
_client = factory.CreateClient(new WebApplicationFactoryClientOptions
{
AllowAutoRedirect = false
});
}
public async Task AuthenticateAsync()
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", await GetJwtAsync());
}
private async Task<string> GetJwtAsync()
{
var login = new UserLoginRequest
{
Email = "[email protected]",
Password = "Qaz12!"
};
var response = await _client.PostAsJsonAsync(ApiRoutes.Identity.Login, login);
var loginResponse = await response.Content.ReadAsAsync<AuthenticationResult>();
return loginResponse.Token;
}
[Fact]
public async Task GetById_WithItemNotExists_ReturnsNotFound()
{
// Arrange
await AuthenticateAsync();
// Act
var response = await _client.GetAsync(ApiRoutes.JobTypes.GetById.Replace("{id}", "12"));
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}
}