New Angular based web version #1
@@ -65,7 +65,7 @@ public static class CreateCar
|
|||||||
UserId = userId
|
UserId = userId
|
||||||
};
|
};
|
||||||
|
|
||||||
var isDuplicate = await dbContext.Cars
|
bool isDuplicate = await dbContext.Cars
|
||||||
.AnyAsync(x => x.Name.ToUpper() == request.Name.ToUpper(), cancellationToken);
|
.AnyAsync(x => x.Name.ToUpper() == request.Name.ToUpper(), cancellationToken);
|
||||||
|
|
||||||
if (isDuplicate)
|
if (isDuplicate)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public static class DeleteCar
|
|||||||
ILoggerFactory loggerFactory,
|
ILoggerFactory loggerFactory,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var rows = await dbContext.Cars
|
int rows = await dbContext.Cars
|
||||||
.Where(x => x.Id == new CarId(id))
|
.Where(x => x.Id == new CarId(id))
|
||||||
.ExecuteDeleteAsync(cancellationToken);
|
.ExecuteDeleteAsync(cancellationToken);
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public static class DeleteCar
|
|||||||
|
|
||||||
if (rows > 1)
|
if (rows > 1)
|
||||||
{
|
{
|
||||||
var logger = loggerFactory.CreateLogger(nameof(DeleteCar));
|
ILogger logger = loggerFactory.CreateLogger(nameof(DeleteCar));
|
||||||
logger.LogWarning("Deleted '{DeletedRowCount}' rows for id '{CarId}'", rows, id);
|
logger.LogWarning("Deleted '{DeletedRowCount}' rows for id '{CarId}'", rows, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public static class GetCar
|
|||||||
return TypedResults.NotFound();
|
return TypedResults.NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new Response(car.Id.Value, car.Name);
|
Response response = new Response(car.Id.Value, car.Name);
|
||||||
return TypedResults.Ok(response);
|
return TypedResults.Ok(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ public static class GetCars
|
|||||||
.Select(x => new ResponseDto(x.Id.Value, x.Name))
|
.Select(x => new ResponseDto(x.Id.Value, x.Name))
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
var response = new ApiResponse
|
ApiResponse response = new ApiResponse
|
||||||
{
|
{
|
||||||
Cars = cars
|
Cars = cars
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public static class UpdateCar
|
|||||||
return TypedResults.NotFound();
|
return TypedResults.NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var isDuplicate = await dbContext.Cars
|
bool isDuplicate = await dbContext.Cars
|
||||||
.AnyAsync(x => x.Name.ToUpper() == request.Name.ToUpper(), cancellationToken);
|
.AnyAsync(x => x.Name.ToUpper() == request.Name.ToUpper(), cancellationToken);
|
||||||
|
|
||||||
if (isDuplicate)
|
if (isDuplicate)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public static class DependencyInjectionExtensions
|
|||||||
.ValidateFluently()
|
.ValidateFluently()
|
||||||
.ValidateOnStart();
|
.ValidateOnStart();
|
||||||
|
|
||||||
var jwtOptions = services.BuildServiceProvider().GetRequiredService<IOptions<JwtOptions>>();
|
IOptions<JwtOptions> jwtOptions = services.BuildServiceProvider().GetRequiredService<IOptions<JwtOptions>>();
|
||||||
|
|
||||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, o =>
|
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, o =>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public static class DeleteConsumption
|
|||||||
ILoggerFactory loggerFactory,
|
ILoggerFactory loggerFactory,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var rows = await dbContext.Consumptions
|
int rows = await dbContext.Consumptions
|
||||||
.Where(x => x.Id == new ConsumptionId(id))
|
.Where(x => x.Id == new ConsumptionId(id))
|
||||||
.ExecuteDeleteAsync(cancellationToken);
|
.ExecuteDeleteAsync(cancellationToken);
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public static class DeleteConsumption
|
|||||||
|
|
||||||
if (rows > 1)
|
if (rows > 1)
|
||||||
{
|
{
|
||||||
var logger = loggerFactory.CreateLogger(nameof(DeleteConsumption));
|
ILogger logger = loggerFactory.CreateLogger(nameof(DeleteConsumption));
|
||||||
logger.LogWarning("Deleted '{DeletedRowCount}' rows for id '{ConsumptionId}'", rows, id);
|
logger.LogWarning("Deleted '{DeletedRowCount}' rows for id '{ConsumptionId}'", rows, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public static class GetConsumptions
|
|||||||
|
|
||||||
List<ResponseDto> responses = [];
|
List<ResponseDto> responses = [];
|
||||||
|
|
||||||
foreach (var consumptions in consumptionsByCar.Select(x => x.Value))
|
foreach (List<Consumption> consumptions in consumptionsByCar.Select(x => x.Value))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < consumptions.Count; i++)
|
for (int i = 0; i < consumptions.Count; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ public class ApplyMigrationsService(
|
|||||||
{
|
{
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var activity = activitySource.StartActivity("ApplyMigrations");
|
using Activity? activity = activitySource.StartActivity("ApplyMigrations");
|
||||||
|
|
||||||
logger.LogInformation("Starting migrations");
|
logger.LogInformation("Starting migrations");
|
||||||
|
|
||||||
using IServiceScope scope = scopeFactory.CreateScope();
|
using IServiceScope scope = scopeFactory.CreateScope();
|
||||||
await using var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
await using ApplicationDbContext dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||||
await dbContext.Database.MigrateAsync(cancellationToken);
|
await dbContext.Database.MigrateAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class CreateCarTests : IAsyncLifetime
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.Created);
|
response.StatusCode.Should().Be(HttpStatusCode.Created);
|
||||||
var createdCar = await response.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCar = await response.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
createdCar.Should().BeEquivalentTo(createCarRequest, o => o.ExcludingMissingMembers());
|
createdCar.Should().BeEquivalentTo(createCarRequest, o => o.ExcludingMissingMembers());
|
||||||
|
|
||||||
_dbContext.Cars.Should().ContainEquivalentOf(createdCar, o => o.Excluding(x => x!.Id))
|
_dbContext.Cars.Should().ContainEquivalentOf(createdCar, o => o.Excluding(x => x!.Id))
|
||||||
@@ -46,14 +46,14 @@ public class CreateCarTests : IAsyncLifetime
|
|||||||
public async Task CreateCar_ShouldReturnValidationProblems_WhenRequestIsNotValid()
|
public async Task CreateCar_ShouldReturnValidationProblems_WhenRequestIsNotValid()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var createCarRequest = new CreateCar.Request("");
|
CreateCar.Request createCarRequest = new CreateCar.Request("");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||||
var validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
ValidationProblemDetails? validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
||||||
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
||||||
x.Equals(nameof(CreateCar.Request.Name), StringComparison.OrdinalIgnoreCase));
|
x.Equals(nameof(CreateCar.Request.Name), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class DeleteCarTests : IAsyncLifetime
|
|||||||
public async Task DeleteCar_ShouldReturnNotFound_WhenCarDoesNotExist()
|
public async Task DeleteCar_ShouldReturnNotFound_WhenCarDoesNotExist()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var randomCarId = Guid.NewGuid();
|
Guid randomCarId = Guid.NewGuid();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/cars/{randomCarId}");
|
HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/cars/{randomCarId}");
|
||||||
@@ -43,7 +43,7 @@ public class DeleteCarTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
||||||
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
||||||
createCarResponse.EnsureSuccessStatusCode();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/cars/{createdCar!.Id}");
|
HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/cars/{createdCar!.Id}");
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class GetCarTests : IAsyncLifetime
|
|||||||
public async Task GetCar_ShouldReturnNotFound_WhenCarDoesNotExist()
|
public async Task GetCar_ShouldReturnNotFound_WhenCarDoesNotExist()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var randomCarId = Guid.NewGuid();
|
Guid randomCarId = Guid.NewGuid();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{randomCarId}");
|
HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{randomCarId}");
|
||||||
@@ -37,14 +37,14 @@ public class GetCarTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
||||||
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
||||||
createCarResponse.EnsureSuccessStatusCode();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{createdCar!.Id}");
|
HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{createdCar!.Id}");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
var car = await response.Content.ReadFromJsonAsync<GetCar.Response>();
|
GetCar.Response? car = await response.Content.ReadFromJsonAsync<GetCar.Response>();
|
||||||
car.Should().BeEquivalentTo(createdCar);
|
car.Should().BeEquivalentTo(createdCar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class GetCarsTests : IAsyncLifetime
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
var apiResponse = await response.Content.ReadFromJsonAsync<GetCars.ApiResponse>();
|
GetCars.ApiResponse? apiResponse = await response.Content.ReadFromJsonAsync<GetCars.ApiResponse>();
|
||||||
apiResponse!.Cars.Should().BeEmpty();
|
apiResponse!.Cars.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,13 +38,13 @@ public class GetCarsTests : IAsyncLifetime
|
|||||||
List<CreateCar.Response> createdCars = [];
|
List<CreateCar.Response> createdCars = [];
|
||||||
|
|
||||||
const int numberOfCars = 5;
|
const int numberOfCars = 5;
|
||||||
for (var i = 0; i < numberOfCars; i++)
|
for (int i = 0; i < numberOfCars; i++)
|
||||||
{
|
{
|
||||||
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
||||||
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
||||||
createCarResponse.EnsureSuccessStatusCode();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
createdCars.Add(createdCar!);
|
createdCars.Add(createdCar!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public class GetCarsTests : IAsyncLifetime
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
var apiResponse = await response.Content.ReadFromJsonAsync<GetCars.ApiResponse>();
|
GetCars.ApiResponse? apiResponse = await response.Content.ReadFromJsonAsync<GetCars.ApiResponse>();
|
||||||
apiResponse!.Cars.Should().BeEquivalentTo(createdCars);
|
apiResponse!.Cars.Should().BeEquivalentTo(createdCars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class UpdateCarTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
||||||
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
||||||
createCarResponse.EnsureSuccessStatusCode();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
|
|
||||||
UpdateCar.Request updateCarRequest = _carFaker.UpdateCarRequest();
|
UpdateCar.Request updateCarRequest = _carFaker.UpdateCarRequest();
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public class UpdateCarTests : IAsyncLifetime
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
var updatedCar = await response.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? updatedCar = await response.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
updatedCar!.Id.Should().Be(createdCar.Id);
|
updatedCar!.Id.Should().Be(createdCar.Id);
|
||||||
updatedCar.Should().BeEquivalentTo(updateCarRequest, o => o.ExcludingMissingMembers());
|
updatedCar.Should().BeEquivalentTo(updateCarRequest, o => o.ExcludingMissingMembers());
|
||||||
|
|
||||||
@@ -57,16 +57,16 @@ public class UpdateCarTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
CreateCar.Request createCarRequest = _carFaker.CreateCarRequest();
|
||||||
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest);
|
||||||
createCarResponse.EnsureSuccessStatusCode();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCar = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
|
|
||||||
var updateCarRequest = new UpdateCar.Request("");
|
UpdateCar.Request updateCarRequest = new UpdateCar.Request("");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{createdCar!.Id}", updateCarRequest);
|
HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{createdCar!.Id}", updateCarRequest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||||
var validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
ValidationProblemDetails? validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
||||||
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
||||||
x.Equals(nameof(CreateCar.Request.Name), StringComparison.OrdinalIgnoreCase));
|
x.Equals(nameof(CreateCar.Request.Name), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class UpdateCarTests : IAsyncLifetime
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UpdateCar.Request updateCarRequest = _carFaker.UpdateCarRequest();
|
UpdateCar.Request updateCarRequest = _carFaker.UpdateCarRequest();
|
||||||
var randomCarId = Guid.NewGuid();
|
Guid randomCarId = Guid.NewGuid();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{randomCarId}", updateCarRequest);
|
HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{randomCarId}", updateCarRequest);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class CreateConsumptionTests : IAsyncLifetime
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.Created);
|
response.StatusCode.Should().Be(HttpStatusCode.Created);
|
||||||
var createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
CreateConsumption.Response? createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
||||||
createdConsumption.Should().BeEquivalentTo(createConsumptionRequest, o => o.ExcludingMissingMembers());
|
createdConsumption.Should().BeEquivalentTo(createConsumptionRequest, o => o.ExcludingMissingMembers());
|
||||||
|
|
||||||
_dbContext.Consumptions.Should().HaveCount(1)
|
_dbContext.Consumptions.Should().HaveCount(1)
|
||||||
@@ -64,7 +64,7 @@ public class CreateConsumptionTests : IAsyncLifetime
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||||
var validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
ValidationProblemDetails? validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
||||||
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
||||||
x.Equals(nameof(createConsumptionRequest.CarId), StringComparison.OrdinalIgnoreCase));
|
x.Equals(nameof(createConsumptionRequest.CarId), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class CreateConsumptionTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = new CarFaker().CreateCarRequest();
|
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();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
return createdCarResponse!;
|
return createdCarResponse!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class DeleteConsumptionTests : IAsyncLifetime
|
|||||||
public async Task DeleteConsumption_ShouldReturnNotFound_WhenConsumptionDoesNotExist()
|
public async Task DeleteConsumption_ShouldReturnNotFound_WhenConsumptionDoesNotExist()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var consumptionId = Guid.NewGuid();
|
Guid consumptionId = Guid.NewGuid();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
using HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/consumptions/{consumptionId}");
|
using HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/consumptions/{consumptionId}");
|
||||||
@@ -58,7 +58,7 @@ public class DeleteConsumptionTests : IAsyncLifetime
|
|||||||
CreateConsumption.Request createConsumptionRequest = _consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
|
CreateConsumption.Request createConsumptionRequest = _consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
|
||||||
using HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
|
using HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
var createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
CreateConsumption.Response? createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
||||||
return createdConsumption!;
|
return createdConsumption!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ public class DeleteConsumptionTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = new CarFaker().CreateCarRequest();
|
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();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
return createdCarResponse!;
|
return createdCarResponse!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class GetConsumptionTests : IAsyncLifetime
|
|||||||
// Assert
|
// Assert
|
||||||
string content = await response.Content.ReadAsStringAsync();
|
string content = await response.Content.ReadAsStringAsync();
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
var consumption = await response.Content.ReadFromJsonAsync<GetConsumption.Response>();
|
GetConsumption.Response? consumption = await response.Content.ReadFromJsonAsync<GetConsumption.Response>();
|
||||||
consumption.Should().BeEquivalentTo(createdConsumption);
|
consumption.Should().BeEquivalentTo(createdConsumption);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class GetConsumptionTests : IAsyncLifetime
|
|||||||
public async Task GetConsumptions_ShouldReturnNotFound_WhenConsumptionDoesNotExist()
|
public async Task GetConsumptions_ShouldReturnNotFound_WhenConsumptionDoesNotExist()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var consumptionId = Guid.NewGuid();
|
Guid consumptionId = Guid.NewGuid();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
using HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/consumptions{consumptionId}");
|
using HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/consumptions{consumptionId}");
|
||||||
@@ -60,7 +60,7 @@ public class GetConsumptionTests : IAsyncLifetime
|
|||||||
CreateConsumption.Request createConsumptionRequest = _consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
|
CreateConsumption.Request createConsumptionRequest = _consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
|
||||||
using HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
|
using HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
var createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
CreateConsumption.Response? createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
||||||
return createdConsumption!;
|
return createdConsumption!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class GetConsumptionTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = new CarFaker().CreateCarRequest();
|
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();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
return createdCarResponse!;
|
return createdCarResponse!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class UpdateConsumptionTests : IAsyncLifetime
|
|||||||
// Assert
|
// Assert
|
||||||
string content = await response.Content.ReadAsStringAsync();
|
string content = await response.Content.ReadAsStringAsync();
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
var updatedConsumption = await response.Content.ReadFromJsonAsync<UpdateConsumption.Response>();
|
UpdateConsumption.Response? updatedConsumption = await response.Content.ReadFromJsonAsync<UpdateConsumption.Response>();
|
||||||
updatedConsumption.Should().BeEquivalentTo(updateConsumptionRequest, o => o.ExcludingMissingMembers());
|
updatedConsumption.Should().BeEquivalentTo(updateConsumptionRequest, o => o.ExcludingMissingMembers());
|
||||||
|
|
||||||
_dbContext.Consumptions.Should().HaveCount(1)
|
_dbContext.Consumptions.Should().HaveCount(1)
|
||||||
@@ -59,7 +59,7 @@ public class UpdateConsumptionTests : IAsyncLifetime
|
|||||||
// Arrange
|
// Arrange
|
||||||
CreateConsumption.Response createdConsumption = await CreateConsumptionAsync();
|
CreateConsumption.Response createdConsumption = await CreateConsumptionAsync();
|
||||||
UpdateConsumption.Request updateConsumptionRequest = _consumptionFaker.UpdateConsumptionRequest() with { Distance = -42 };
|
UpdateConsumption.Request updateConsumptionRequest = _consumptionFaker.UpdateConsumptionRequest() with { Distance = -42 };
|
||||||
var randomGuid = Guid.NewGuid();
|
Guid randomGuid = Guid.NewGuid();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
using HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/consumptions/{randomGuid}", updateConsumptionRequest);
|
using HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/consumptions/{randomGuid}", updateConsumptionRequest);
|
||||||
@@ -67,7 +67,7 @@ public class UpdateConsumptionTests : IAsyncLifetime
|
|||||||
// Assert
|
// Assert
|
||||||
string content = await response.Content.ReadAsStringAsync();
|
string content = await response.Content.ReadAsStringAsync();
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||||
var validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
ValidationProblemDetails? validationProblemDetails = await response.Content.ReadFromJsonAsync<ValidationProblemDetails>();
|
||||||
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
validationProblemDetails!.Errors.Keys.Should().Contain(x =>
|
||||||
x.Equals(nameof(updateConsumptionRequest.Distance), StringComparison.OrdinalIgnoreCase));
|
x.Equals(nameof(updateConsumptionRequest.Distance), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class UpdateConsumptionTests : IAsyncLifetime
|
|||||||
// Arrange
|
// Arrange
|
||||||
CreateConsumption.Response createdConsumption = await CreateConsumptionAsync();
|
CreateConsumption.Response createdConsumption = await CreateConsumptionAsync();
|
||||||
UpdateConsumption.Request updateConsumptionRequest = _consumptionFaker.UpdateConsumptionRequest();
|
UpdateConsumption.Request updateConsumptionRequest = _consumptionFaker.UpdateConsumptionRequest();
|
||||||
var randomGuid = Guid.NewGuid();
|
Guid randomGuid = Guid.NewGuid();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
using HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/consumptions/{randomGuid}", updateConsumptionRequest);
|
using HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/consumptions/{randomGuid}", updateConsumptionRequest);
|
||||||
@@ -98,7 +98,7 @@ public class UpdateConsumptionTests : IAsyncLifetime
|
|||||||
CreateConsumption.Request createConsumptionRequest = _consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
|
CreateConsumption.Request createConsumptionRequest = _consumptionFaker.CreateConsumptionRequest(createdCarResponse.Id);
|
||||||
using HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
|
using HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/consumptions", createConsumptionRequest);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
var createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
CreateConsumption.Response? createdConsumption = await response.Content.ReadFromJsonAsync<CreateConsumption.Response>();
|
||||||
return createdConsumption!;
|
return createdConsumption!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public class UpdateConsumptionTests : IAsyncLifetime
|
|||||||
CreateCar.Request createCarRequest = new CarFaker().CreateCarRequest();
|
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();
|
createCarResponse.EnsureSuccessStatusCode();
|
||||||
var createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
CreateCar.Response? createdCarResponse = await createCarResponse.Content.ReadFromJsonAsync<CreateCar.Response>();
|
||||||
return createdCarResponse!;
|
return createdCarResponse!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class GetServerInfoTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.IsSuccessStatusCode.Should().BeTrue();
|
response.IsSuccessStatusCode.Should().BeTrue();
|
||||||
var serverInfo = await response.Content.ReadFromJsonAsync<GetServerInfo.Response>();
|
GetServerInfo.Response? serverInfo = await response.Content.ReadFromJsonAsync<GetServerInfo.Response>();
|
||||||
serverInfo!.Environment.Should().NotBeEmpty();
|
serverInfo!.Environment.Should().NotBeEmpty();
|
||||||
serverInfo.CommitDate.Should().BeAfter(23.August(2024))
|
serverInfo.CommitDate.Should().BeAfter(23.August(2024))
|
||||||
.And.NotBeAfter(DateTime.Now);
|
.And.NotBeAfter(DateTime.Now);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ internal sealed class PostgresRespawner : IDisposable
|
|||||||
DbConnection connection = new NpgsqlConnection(connectionString);
|
DbConnection connection = new NpgsqlConnection(connectionString);
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
|
|
||||||
var respawner = await Respawner.CreateAsync(connection,
|
Respawner respawner = await Respawner.CreateAsync(connection,
|
||||||
new RespawnerOptions
|
new RespawnerOptions
|
||||||
{
|
{
|
||||||
SchemasToInclude = ["public"],
|
SchemasToInclude = ["public"],
|
||||||
|
|||||||
Reference in New Issue
Block a user