Include necessary info directly in get consumption entries response dto
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-06-22 11:51:38 +02:00
parent a997a3b825
commit cb3c8c0d18
10 changed files with 114 additions and 107 deletions

View File

@@ -31,7 +31,7 @@ public class GetConsumptionsTests : IAsyncLifetime
// Arrange
List<CreateConsumption.Response> createdConsumptions = [];
const int numberOfConsumptions = 3;
for (var i = 0; i < numberOfConsumptions; i++)
for (int i = 0; i < numberOfConsumptions; i++)
{
CreateConsumption.Response createdConsumption = await CreateConsumptionAsync();
createdConsumptions.Add(createdConsumption);
@@ -42,8 +42,16 @@ public class GetConsumptionsTests : IAsyncLifetime
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
var apiResponse = await response.Content.ReadFromJsonAsync<GetConsumptions.ApiResponse>();
apiResponse!.Consumptions.Should().BeEquivalentTo(createdConsumptions);
GetConsumptions.ApiResponse? apiResponse =
await response.Content.ReadFromJsonAsync<GetConsumptions.ApiResponse>();
apiResponse.Should().NotBeNull();
apiResponse.Consumptions.Should().HaveCount(createdConsumptions.Count);
apiResponse.Consumptions.Should().BeEquivalentTo(createdConsumptions, o => o.ExcludingMissingMembers());
apiResponse.Consumptions
.Select(x => x.Car.Id)
.Should()
.BeEquivalentTo(createdConsumptions, o => o.ExcludingMissingMembers());
}
[Fact]
@@ -56,26 +64,32 @@ public class GetConsumptionsTests : IAsyncLifetime
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
var apiResponse = await response.Content.ReadFromJsonAsync<GetConsumptions.ApiResponse>();
GetConsumptions.ApiResponse? apiResponse =
await response.Content.ReadFromJsonAsync<GetConsumptions.ApiResponse>();
apiResponse!.Consumptions.Should().BeEmpty();
}
private async Task<CreateConsumption.Response> CreateConsumptionAsync()
{
CreateCar.Response createdCarResponse = await CreateCarAsync();
CreateConsumption.Request createConsumptionRequest = _consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
using HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
CreateConsumption.Request createConsumptionRequest =
_consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
using HttpResponseMessage response =
await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
response.EnsureSuccessStatusCode();
var createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
CreateConsumption.Response? createdConsumption =
await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
return createdConsumption!;
}
private async Task<CreateCar.Response> CreateCarAsync()
{
CreateCar.Request createCarRequest = new CarFaker().CreateCarRequest();
using HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
using HttpResponseMessage createCarResponse =
await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
createCarResponse.EnsureSuccessStatusCode();
var createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
CreateCar.Response? createdCarResponse =
await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
return createdCarResponse!;
}