using FluentAssertions; using System.Net; using System.Net.Http.Json; using Vegasco.Server.Api.Cars; namespace Vegasco.Server.Api.Tests.Integration.Cars; [Collection(SharedTestCollection.Name)] public class GetCarTests : IAsyncLifetime { private readonly WebAppFactory _factory; private readonly CarFaker _carFaker = new(); public GetCarTests(WebAppFactory factory) { _factory = factory; } [Fact] public async Task GetCar_ShouldReturnNotFound_WhenCarDoesNotExist() { // Arrange Guid randomCarId = Guid.NewGuid(); // Act HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{randomCarId}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); } [Fact] public async Task GetCar_ShouldReturnCar_WhenCarExists() { // Arrange CreateCar.Request createCarRequest = _carFaker.CreateCarRequest(); HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); createCarResponse.EnsureSuccessStatusCode(); CreateCar.Response? createdCar = await createCarResponse.Content.ReadFromJsonAsync(); // Act HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{createdCar!.Id}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); GetCar.Response? car = await response.Content.ReadFromJsonAsync(); car.Should().BeEquivalentTo(createdCar); } public Task InitializeAsync() => Task.CompletedTask; public async Task DisposeAsync() { await _factory.ResetDatabaseAsync(); } }