diff --git a/src/Vegasco.Server.AppHost.Shared/Constants.cs b/src/Vegasco.Server.AppHost.Shared/Constants.cs index d9a0f57..cdd67eb 100644 --- a/src/Vegasco.Server.AppHost.Shared/Constants.cs +++ b/src/Vegasco.Server.AppHost.Shared/Constants.cs @@ -11,6 +11,6 @@ public static class Constants { public const string ServiceName = "postgres"; - public const string Name = "vegasco"; + public const string Name = "vegasco-database"; } } diff --git a/src/Vegasco.Server.AppHost.Shared/Vegasco.Server.AppHost.Shared.csproj b/src/Vegasco.Server.AppHost.Shared/Vegasco.Server.AppHost.Shared.csproj index 125f4c9..5808fe7 100644 --- a/src/Vegasco.Server.AppHost.Shared/Vegasco.Server.AppHost.Shared.csproj +++ b/src/Vegasco.Server.AppHost.Shared/Vegasco.Server.AppHost.Shared.csproj @@ -6,4 +6,10 @@ enable + + + 3.7.115 + + + diff --git a/src/Vegasco.Server.AppHost/Program.cs b/src/Vegasco.Server.AppHost/Program.cs index bda0036..6c19fd7 100644 --- a/src/Vegasco.Server.AppHost/Program.cs +++ b/src/Vegasco.Server.AppHost/Program.cs @@ -1,8 +1,8 @@ using Vegasco.Server.AppHost.Shared; -var builder = DistributedApplication.CreateBuilder(args); +IDistributedApplicationBuilder builder = DistributedApplication.CreateBuilder(args); -var postgres = builder.AddPostgres(Constants.Database.ServiceName) +IResourceBuilder postgres = builder.AddPostgres(Constants.Database.ServiceName) .WithDataVolume() .AddDatabase(Constants.Database.Name); diff --git a/src/Vegasco.Server.AppHost/Vegasco.Server.AppHost.csproj b/src/Vegasco.Server.AppHost/Vegasco.Server.AppHost.csproj index c22dc1c..70315a2 100644 --- a/src/Vegasco.Server.AppHost/Vegasco.Server.AppHost.csproj +++ b/src/Vegasco.Server.AppHost/Vegasco.Server.AppHost.csproj @@ -12,8 +12,11 @@ - - + + + + 3.7.115 + diff --git a/src/Vegasco.Server.ServiceDefaults/Extensions.cs b/src/Vegasco.Server.ServiceDefaults/Extensions.cs index 13151bf..5984246 100644 --- a/src/Vegasco.Server.ServiceDefaults/Extensions.cs +++ b/src/Vegasco.Server.ServiceDefaults/Extensions.cs @@ -72,7 +72,7 @@ public static class Extensions private static TBuilder AddOpenTelemetryExporters(this TBuilder builder) where TBuilder : IHostApplicationBuilder { - var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + bool useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); if (useOtlpExporter) { diff --git a/src/Vegasco.Server.ServiceDefaults/Vegasco.Server.ServiceDefaults.csproj b/src/Vegasco.Server.ServiceDefaults/Vegasco.Server.ServiceDefaults.csproj index 24b1b4f..f5a831a 100644 --- a/src/Vegasco.Server.ServiceDefaults/Vegasco.Server.ServiceDefaults.csproj +++ b/src/Vegasco.Server.ServiceDefaults/Vegasco.Server.ServiceDefaults.csproj @@ -10,13 +10,16 @@ - - - - - - - + + + + + + + + + 3.7.115 + diff --git a/src/WebApi/Authentication/UserAccessor.cs b/src/WebApi/Authentication/UserAccessor.cs index 6e69d1a..0b16e67 100644 --- a/src/WebApi/Authentication/UserAccessor.cs +++ b/src/WebApi/Authentication/UserAccessor.cs @@ -47,14 +47,14 @@ public sealed class UserAccessor private string GetClaimValue(string claimType) { - var httpContext = _httpContextAccessor.HttpContext; + HttpContext? httpContext = _httpContextAccessor.HttpContext; if (httpContext is null) { ThrowForMissingHttpContext(); } - var claimValue = httpContext.User.FindFirstValue(claimType); + string? claimValue = httpContext.User.FindFirstValue(claimType); if (string.IsNullOrWhiteSpace(claimValue)) { diff --git a/src/WebApi/Cars/CreateCar.cs b/src/WebApi/Cars/CreateCar.cs index ebcb7e2..b968b85 100644 --- a/src/WebApi/Cars/CreateCar.cs +++ b/src/WebApi/Cars/CreateCar.cs @@ -42,9 +42,9 @@ public static class CreateCar return TypedResults.BadRequest(new HttpValidationProblemDetails(failedValidations.ToCombinedDictionary())); } - var userId = userAccessor.GetUserId(); + string userId = userAccessor.GetUserId(); - var user = await dbContext.Users.FindAsync([userId], cancellationToken: cancellationToken); + User? user = await dbContext.Users.FindAsync([userId], cancellationToken: cancellationToken); if (user is null) { user = new User diff --git a/src/WebApi/Cars/DeleteCar.cs b/src/WebApi/Cars/DeleteCar.cs index 05048d7..638ed4b 100644 --- a/src/WebApi/Cars/DeleteCar.cs +++ b/src/WebApi/Cars/DeleteCar.cs @@ -16,7 +16,7 @@ public static class DeleteCar ApplicationDbContext dbContext, CancellationToken cancellationToken) { - var car = await dbContext.Cars.FindAsync([new CarId(id)], cancellationToken: cancellationToken); + Car? car = await dbContext.Cars.FindAsync([new CarId(id)], cancellationToken: cancellationToken); if (car is null) { diff --git a/src/WebApi/Common/DependencyInjectionExtensions.cs b/src/WebApi/Common/DependencyInjectionExtensions.cs index 7c7e8a4..7bd4fdf 100644 --- a/src/WebApi/Common/DependencyInjectionExtensions.cs +++ b/src/WebApi/Common/DependencyInjectionExtensions.cs @@ -3,8 +3,6 @@ using FluentValidation; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.Extensions.Options; using Vegasco.WebApi.Authentication; -using Vegasco.WebApi.Endpoints; -using Vegasco.WebApi.Endpoints.OpenApi; using Vegasco.WebApi.Persistence; namespace Vegasco.WebApi.Common; @@ -14,14 +12,12 @@ public static class DependencyInjectionExtensions /// /// Adds all the WebApi related services to the Dependency Injection container. /// - /// - /// - /// + /// public static void AddWebApiServices(this IHostApplicationBuilder builder) { builder.Services .AddMiscellaneousServices() - .AddOpenApi() + .AddCustomOpenApi() .AddApiVersioning() .AddAuthenticationAndAuthorization(builder.Environment); @@ -38,7 +34,6 @@ public static class DependencyInjectionExtensions ], ServiceLifetime.Singleton); services.AddHealthChecks(); - services.AddEndpointsFromAssemblyContaining(); services.AddHttpContextAccessor(); @@ -47,32 +42,30 @@ public static class DependencyInjectionExtensions return services; } - private static IServiceCollection AddOpenApi(this IServiceCollection services) + private static IServiceCollection AddCustomOpenApi(this IServiceCollection services) { - services.ConfigureOptions(); - services.AddEndpointsApiExplorer(); - services.AddSwaggerGen(o => + services.AddOpenApi(o => { - o.CustomSchemaIds(type => + o.CreateSchemaReferenceId = jsonTypeInfo => { - if (string.IsNullOrEmpty(type.FullName)) + if (string.IsNullOrEmpty(jsonTypeInfo.Type.FullName)) { - return type.Name; + return jsonTypeInfo.Type.Name; } - var fullClassName = type.FullName; + string? fullClassName = jsonTypeInfo.Type.FullName; - if (!string.IsNullOrEmpty(type.Namespace)) + if (!string.IsNullOrEmpty(jsonTypeInfo.Type.Namespace)) { fullClassName = fullClassName - .Replace(type.Namespace, "") + .Replace(jsonTypeInfo.Type.Namespace, "") .TrimStart('.'); } fullClassName = fullClassName.Replace('+', '_'); return fullClassName; - }); + }; }); return services; diff --git a/src/WebApi/Common/FluentValidationOptions.cs b/src/WebApi/Common/FluentValidationOptions.cs index 141e2e7..3131736 100644 --- a/src/WebApi/Common/FluentValidationOptions.cs +++ b/src/WebApi/Common/FluentValidationOptions.cs @@ -1,4 +1,5 @@ using FluentValidation; +using FluentValidation.Results; using Microsoft.Extensions.Options; namespace Vegasco.WebApi.Common; @@ -25,7 +26,7 @@ public class FluentValidationOptions : IValidateOptions ArgumentNullException.ThrowIfNull(options); - var failedValidations = _validators.ValidateAllAsync(options).Result; + List failedValidations = _validators.ValidateAllAsync(options).Result; if (failedValidations.Count == 0) { return ValidateOptionsResult.Success; diff --git a/src/WebApi/Common/StartupExtensions.cs b/src/WebApi/Common/StartupExtensions.cs index 6b2a7fd..92c5ee7 100644 --- a/src/WebApi/Common/StartupExtensions.cs +++ b/src/WebApi/Common/StartupExtensions.cs @@ -45,18 +45,7 @@ internal static class StartupExtensions if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(o => - { - // Create a Swagger endpoint for each API version - IReadOnlyList apiVersions = app.DescribeApiVersions(); - foreach (ApiVersionDescription apiVersionDescription in apiVersions) - { - string url = $"/swagger/{apiVersionDescription.GroupName}/swagger.json"; - string name = apiVersionDescription.GroupName.ToUpperInvariant(); - o.SwaggerEndpoint(url, name); - } - }); + app.MapOpenApi(); } return app; diff --git a/src/WebApi/Common/ValidatorExtensions.cs b/src/WebApi/Common/ValidatorExtensions.cs index 64e04f5..f574e18 100644 --- a/src/WebApi/Common/ValidatorExtensions.cs +++ b/src/WebApi/Common/ValidatorExtensions.cs @@ -15,7 +15,7 @@ public static class ValidatorExtensions /// The failed validation results. public static async Task> ValidateAllAsync(this IEnumerable> validators, T instance, CancellationToken cancellationToken = default) { - var validationTasks = validators + List> validationTasks = validators .Select(validator => validator.ValidateAsync(instance, cancellationToken)) .ToList(); @@ -34,7 +34,7 @@ public static class ValidatorExtensions // Use a hash set to avoid duplicate error messages. Dictionary> combinedErrors = []; - foreach (var error in validationResults.SelectMany(x => x.Errors)) + foreach (ValidationFailure? error in validationResults.SelectMany(x => x.Errors)) { if (!combinedErrors.TryGetValue(error.PropertyName, out HashSet? value)) { @@ -54,7 +54,7 @@ public static class ValidatorExtensions { builder.Services.AddTransient>(serviceProvider => { - var validators = serviceProvider.GetServices>() ?? []; + IEnumerable> validators = serviceProvider.GetServices>() ?? []; return new FluentValidationOptions(builder.Name, validators); }); return builder; diff --git a/src/WebApi/Endpoints/EndpointExtensions.cs b/src/WebApi/Endpoints/EndpointExtensions.cs index 5cc9c9c..599ff6d 100644 --- a/src/WebApi/Endpoints/EndpointExtensions.cs +++ b/src/WebApi/Endpoints/EndpointExtensions.cs @@ -10,22 +10,6 @@ namespace Vegasco.WebApi.Endpoints; public static class EndpointExtensions { - public static IServiceCollection AddEndpointsFromAssemblyContaining(this IServiceCollection services) - { - var assembly = typeof(T).Assembly; - - ServiceDescriptor[] serviceDescriptors = assembly - .DefinedTypes - .Where(type => type is { IsAbstract: false, IsInterface: false } && - type.IsAssignableTo(typeof(IEndpoint))) - .Select(type => ServiceDescriptor.Transient(typeof(IEndpoint), type)) - .ToArray(); - - services.TryAddEnumerable(serviceDescriptors); - - return services; - } - public static void MapEndpoints(this IEndpointRouteBuilder builder) { ApiVersionSet apiVersionSet = builder.NewApiVersionSet() diff --git a/src/WebApi/Endpoints/IEndpoint.cs b/src/WebApi/Endpoints/IEndpoint.cs deleted file mode 100644 index 15e0c50..0000000 --- a/src/WebApi/Endpoints/IEndpoint.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Vegasco.WebApi.Endpoints; - -public interface IEndpoint -{ - void MapEndpoint(IEndpointRouteBuilder builder); -} diff --git a/src/WebApi/Endpoints/OpenApi/ConfigureSwaggerGenOptions.cs b/src/WebApi/Endpoints/OpenApi/ConfigureSwaggerGenOptions.cs deleted file mode 100644 index 571dde8..0000000 --- a/src/WebApi/Endpoints/OpenApi/ConfigureSwaggerGenOptions.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Asp.Versioning.ApiExplorer; -using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Options; -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; - -namespace Vegasco.WebApi.Endpoints.OpenApi; - -/// -/// Registers each api version as its own swagger document. -/// -/// -public class ConfigureSwaggerGenOptions( - IApiVersionDescriptionProvider versionDescriptionProvider) - : IConfigureNamedOptions -{ - private readonly IApiVersionDescriptionProvider _versionDescriptionProvider = versionDescriptionProvider; - - public void Configure(SwaggerGenOptions options) - { - foreach (ApiVersionDescription description in _versionDescriptionProvider.ApiVersionDescriptions) - { - OpenApiSecurityScheme securityScheme = new() - { - Name = "Bearer", - In = ParameterLocation.Header, - Type = SecuritySchemeType.Http, - Scheme = "bearer", - Reference = new OpenApiReference - { - Id = IdentityConstants.BearerScheme, - Type = ReferenceType.SecurityScheme - } - }; - options.AddSecurityDefinition(securityScheme.Reference.Id, securityScheme); - - options.AddSecurityRequirement(new OpenApiSecurityRequirement - { - { securityScheme, Array.Empty() } - }); - - OpenApiInfo openApiInfo = new() - { - Title = "Vegasco API", - Version = description.ApiVersion.ToString() - }; - - options.SwaggerDoc(description.GroupName, openApiInfo); - } - } - - public void Configure(string? name, SwaggerGenOptions options) - { - Configure(options); - } -} diff --git a/src/WebApi/Endpoints/OpenApi/SwaggerDocConstants.cs b/src/WebApi/Endpoints/OpenApi/SwaggerDocConstants.cs deleted file mode 100644 index e88de76..0000000 --- a/src/WebApi/Endpoints/OpenApi/SwaggerDocConstants.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Vegasco.WebApi.Endpoints.OpenApi; - -public static class SwaggerDocConstants -{ - -} diff --git a/src/WebApi/Persistence/ApplyMigrationsService.cs b/src/WebApi/Persistence/ApplyMigrationsService.cs index a55de3a..c135ed1 100644 --- a/src/WebApi/Persistence/ApplyMigrationsService.cs +++ b/src/WebApi/Persistence/ApplyMigrationsService.cs @@ -2,18 +2,14 @@ namespace Vegasco.WebApi.Persistence; -public class ApplyMigrationsService : IHostedService +public class ApplyMigrationsService(ILogger logger, IServiceScopeFactory scopeFactory) + : IHostedService { - private readonly IServiceScopeFactory _scopeFactory; - - public ApplyMigrationsService(IServiceScopeFactory scopeFactory) - { - _scopeFactory = scopeFactory; - } - public async Task StartAsync(CancellationToken cancellationToken) { - using IServiceScope scope = _scopeFactory.CreateScope(); + logger.LogInformation("Starting migrations"); + + using IServiceScope scope = scopeFactory.CreateScope(); await using var dbContext = scope.ServiceProvider.GetRequiredService(); await dbContext.Database.MigrateAsync(cancellationToken); } diff --git a/src/WebApi/WebApi.csproj b/src/WebApi/WebApi.csproj index 8f2416f..9ba8886 100644 --- a/src/WebApi/WebApi.csproj +++ b/src/WebApi/WebApi.csproj @@ -13,25 +13,24 @@ - - - - - - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - - + + + + + + + - @@ -40,7 +39,7 @@ - + diff --git a/tests/WebApi.Tests.Integration/Cars/CreateCarTests.cs b/tests/WebApi.Tests.Integration/Cars/CreateCarTests.cs index b9226af..95d2c03 100644 --- a/tests/WebApi.Tests.Integration/Cars/CreateCarTests.cs +++ b/tests/WebApi.Tests.Integration/Cars/CreateCarTests.cs @@ -28,10 +28,10 @@ public class CreateCarTests : IAsyncLifetime public async Task CreateCar_ShouldCreateCar_WhenRequestIsValid() { // Arrange - var createCarRequest = _carFaker.CreateCarRequest(); + CreateCar.Request createCarRequest = _carFaker.CreateCarRequest(); // Act - var response = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); + HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); // Assert response.StatusCode.Should().Be(HttpStatusCode.Created); @@ -49,7 +49,7 @@ public class CreateCarTests : IAsyncLifetime var createCarRequest = new CreateCar.Request(""); // Act - var response = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); + HttpResponseMessage response = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); // Assert response.StatusCode.Should().Be(HttpStatusCode.BadRequest); diff --git a/tests/WebApi.Tests.Integration/Cars/DeleteCarTests.cs b/tests/WebApi.Tests.Integration/Cars/DeleteCarTests.cs index e672d0f..160d96e 100644 --- a/tests/WebApi.Tests.Integration/Cars/DeleteCarTests.cs +++ b/tests/WebApi.Tests.Integration/Cars/DeleteCarTests.cs @@ -30,7 +30,7 @@ public class DeleteCarTests : IAsyncLifetime var randomCarId = Guid.NewGuid(); // Act - var response = await _factory.HttpClient.DeleteAsync($"v1/cars/{randomCarId}"); + HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/cars/{randomCarId}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); @@ -40,13 +40,13 @@ public class DeleteCarTests : IAsyncLifetime public async Task DeleteCar_ShouldDeleteCar_WhenCarExists() { // Arrange - var createCarRequest = _carFaker.CreateCarRequest(); - var createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); + CreateCar.Request createCarRequest = _carFaker.CreateCarRequest(); + HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); createCarResponse.EnsureSuccessStatusCode(); var createdCar = await createCarResponse.Content.ReadFromJsonAsync(); // Act - var response = await _factory.HttpClient.DeleteAsync($"v1/cars/{createdCar!.Id}"); + HttpResponseMessage response = await _factory.HttpClient.DeleteAsync($"v1/cars/{createdCar!.Id}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.NoContent); diff --git a/tests/WebApi.Tests.Integration/Cars/GetCarTests.cs b/tests/WebApi.Tests.Integration/Cars/GetCarTests.cs index af2dcfa..f425919 100644 --- a/tests/WebApi.Tests.Integration/Cars/GetCarTests.cs +++ b/tests/WebApi.Tests.Integration/Cars/GetCarTests.cs @@ -24,7 +24,7 @@ public class GetCarTests : IAsyncLifetime var randomCarId = Guid.NewGuid(); // Act - var response = await _factory.HttpClient.GetAsync($"v1/cars/{randomCarId}"); + HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{randomCarId}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); @@ -34,13 +34,13 @@ public class GetCarTests : IAsyncLifetime public async Task GetCar_ShouldReturnCar_WhenCarExists() { // Arrange - var createCarRequest = _carFaker.CreateCarRequest(); - var createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); + CreateCar.Request createCarRequest = _carFaker.CreateCarRequest(); + HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); createCarResponse.EnsureSuccessStatusCode(); var createdCar = await createCarResponse.Content.ReadFromJsonAsync(); // Act - var response = await _factory.HttpClient.GetAsync($"v1/cars/{createdCar!.Id}"); + HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/cars/{createdCar!.Id}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); diff --git a/tests/WebApi.Tests.Integration/Cars/UpdateCarTests.cs b/tests/WebApi.Tests.Integration/Cars/UpdateCarTests.cs index 56a81e7..ded5967 100644 --- a/tests/WebApi.Tests.Integration/Cars/UpdateCarTests.cs +++ b/tests/WebApi.Tests.Integration/Cars/UpdateCarTests.cs @@ -28,15 +28,15 @@ public class UpdateCarTests : IAsyncLifetime public async Task UpdateCar_ShouldUpdateCar_WhenCarExistsAndRequestIsValid() { // Arrange - var createCarRequest = _carFaker.CreateCarRequest(); - var createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); + CreateCar.Request createCarRequest = _carFaker.CreateCarRequest(); + HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); createCarResponse.EnsureSuccessStatusCode(); var createdCar = await createCarResponse.Content.ReadFromJsonAsync(); - var updateCarRequest = _carFaker.UpdateCarRequest(); + UpdateCar.Request updateCarRequest = _carFaker.UpdateCarRequest(); // Act - var response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{createdCar!.Id}", updateCarRequest); + HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{createdCar!.Id}", updateCarRequest); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -54,15 +54,15 @@ public class UpdateCarTests : IAsyncLifetime public async Task UpdateCar_ShouldReturnValidationProblems_WhenRequestIsNotValid() { // Arrange - var createCarRequest = _carFaker.CreateCarRequest(); - var createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); + CreateCar.Request createCarRequest = _carFaker.CreateCarRequest(); + HttpResponseMessage createCarResponse = await _factory.HttpClient.PostAsJsonAsync("v1/cars", createCarRequest); createCarResponse.EnsureSuccessStatusCode(); var createdCar = await createCarResponse.Content.ReadFromJsonAsync(); var updateCarRequest = new UpdateCar.Request(""); // Act - var response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{createdCar!.Id}", updateCarRequest); + HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{createdCar!.Id}", updateCarRequest); // Assert response.StatusCode.Should().Be(HttpStatusCode.BadRequest); @@ -79,11 +79,11 @@ public class UpdateCarTests : IAsyncLifetime public async Task UpdateCar_ShouldReturnNotFound_WhenNoCarWithIdExists() { // Arrange - var updateCarRequest = _carFaker.UpdateCarRequest(); + UpdateCar.Request updateCarRequest = _carFaker.UpdateCarRequest(); var randomCarId = Guid.NewGuid(); // Act - var response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{randomCarId}", updateCarRequest); + HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/cars/{randomCarId}", updateCarRequest); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); diff --git a/tests/WebApi.Tests.Integration/Consumptions/GetConsumptionTests.cs b/tests/WebApi.Tests.Integration/Consumptions/GetConsumptionTests.cs index 2e490f9..6448776 100644 --- a/tests/WebApi.Tests.Integration/Consumptions/GetConsumptionTests.cs +++ b/tests/WebApi.Tests.Integration/Consumptions/GetConsumptionTests.cs @@ -35,7 +35,7 @@ public class GetConsumptionTests : IAsyncLifetime using HttpResponseMessage response = await _factory.HttpClient.GetAsync($"v1/consumptions/{createdConsumption.Id}"); // Assert - var content = await response.Content.ReadAsStringAsync(); + string content = await response.Content.ReadAsStringAsync(); response.StatusCode.Should().Be(HttpStatusCode.OK); var consumption = await response.Content.ReadFromJsonAsync(); consumption.Should().BeEquivalentTo(createdConsumption); diff --git a/tests/WebApi.Tests.Integration/Consumptions/UpdateConsumptionTests.cs b/tests/WebApi.Tests.Integration/Consumptions/UpdateConsumptionTests.cs index 723f7eb..3999b1d 100644 --- a/tests/WebApi.Tests.Integration/Consumptions/UpdateConsumptionTests.cs +++ b/tests/WebApi.Tests.Integration/Consumptions/UpdateConsumptionTests.cs @@ -37,7 +37,7 @@ public class UpdateConsumptionTests : IAsyncLifetime using HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/consumptions/{createdConsumption.Id}", updateConsumptionRequest); // Assert - var content = await response.Content.ReadAsStringAsync(); + string content = await response.Content.ReadAsStringAsync(); response.StatusCode.Should().Be(HttpStatusCode.OK); var updatedConsumption = await response.Content.ReadFromJsonAsync(); updatedConsumption.Should().BeEquivalentTo(updateConsumptionRequest, o => o.ExcludingMissingMembers()); @@ -65,7 +65,7 @@ public class UpdateConsumptionTests : IAsyncLifetime using HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/consumptions/{randomGuid}", updateConsumptionRequest); // Assert - var content = await response.Content.ReadAsStringAsync(); + string content = await response.Content.ReadAsStringAsync(); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); var validationProblemDetails = await response.Content.ReadFromJsonAsync(); validationProblemDetails!.Errors.Keys.Should().Contain(x => @@ -86,7 +86,7 @@ public class UpdateConsumptionTests : IAsyncLifetime using HttpResponseMessage response = await _factory.HttpClient.PutAsJsonAsync($"v1/consumptions/{randomGuid}", updateConsumptionRequest); // Assert - var content = await response.Content.ReadAsStringAsync(); + string content = await response.Content.ReadAsStringAsync(); response.StatusCode.Should().Be(HttpStatusCode.NotFound); _dbContext.Consumptions.Should().NotContainEquivalentOf(updateConsumptionRequest); diff --git a/tests/WebApi.Tests.Integration/TestUserAlwaysAuthorizedPolicyEvaluator.cs b/tests/WebApi.Tests.Integration/TestUserAlwaysAuthorizedPolicyEvaluator.cs index ce19bdf..787d255 100644 --- a/tests/WebApi.Tests.Integration/TestUserAlwaysAuthorizedPolicyEvaluator.cs +++ b/tests/WebApi.Tests.Integration/TestUserAlwaysAuthorizedPolicyEvaluator.cs @@ -26,7 +26,7 @@ public sealed class TestUserAlwaysAuthorizedPolicyEvaluator : IPolicyEvaluator ClaimsIdentity identity = new(claims, JwtBearerDefaults.AuthenticationScheme); ClaimsPrincipal principal = new(identity); AuthenticationTicket ticket = new(principal, JwtBearerDefaults.AuthenticationScheme); - var result = AuthenticateResult.Success(ticket); + AuthenticateResult result = AuthenticateResult.Success(ticket); return Task.FromResult(result); ; } diff --git a/tests/WebApi.Tests.Integration/WebApi.Tests.Integration.csproj b/tests/WebApi.Tests.Integration/WebApi.Tests.Integration.csproj index 4d73780..ebfdb83 100644 --- a/tests/WebApi.Tests.Integration/WebApi.Tests.Integration.csproj +++ b/tests/WebApi.Tests.Integration/WebApi.Tests.Integration.csproj @@ -10,21 +10,21 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -40,7 +40,7 @@ - + diff --git a/tests/WebApi.Tests.Unit/Authentication/UserAccessorTests.cs b/tests/WebApi.Tests.Unit/Authentication/UserAccessorTests.cs index c32f769..0e5a68c 100644 --- a/tests/WebApi.Tests.Unit/Authentication/UserAccessorTests.cs +++ b/tests/WebApi.Tests.Unit/Authentication/UserAccessorTests.cs @@ -50,7 +50,7 @@ public sealed class UserAccessorTests // Arrange // Act - var result = _sut.GetUsername(); + string result = _sut.GetUsername(); // Assert result.Should().Be(_defaultUsername); @@ -67,7 +67,7 @@ public sealed class UserAccessorTests ])); // Act - var result = _sut.GetUsername(); + string result = _sut.GetUsername(); // Assert result.Should().Be(_defaultUsername); @@ -81,7 +81,7 @@ public sealed class UserAccessorTests _options.ClearReceivedCalls(); // Act - var result = _sut.GetUsername(); + string result = _sut.GetUsername(); // Assert result.Should().Be(_defaultUsername); @@ -95,7 +95,7 @@ public sealed class UserAccessorTests _httpContextAccessor.HttpContext = null; // Act - var action = () => _sut.GetUsername(); + Func action = () => _sut.GetUsername(); // Assert action.Should().ThrowExactly() @@ -109,7 +109,7 @@ public sealed class UserAccessorTests _httpContextAccessor.HttpContext!.User = new ClaimsPrincipal(); // Act - var action = () => _sut.GetUsername(); + Func action = () => _sut.GetUsername(); // Assert action.Should().ThrowExactly() @@ -126,7 +126,7 @@ public sealed class UserAccessorTests // Arrange // Act - var result = _sut.GetUserId(); + string result = _sut.GetUserId(); // Assert result.Should().Be(_defaultId); @@ -140,7 +140,7 @@ public sealed class UserAccessorTests _options.ClearReceivedCalls(); // Act - var result = _sut.GetUserId(); + string result = _sut.GetUserId(); // Assert result.Should().Be(_defaultId); @@ -154,7 +154,7 @@ public sealed class UserAccessorTests _httpContextAccessor.HttpContext = null; // Act - var action = () => _sut.GetUserId(); + Func action = () => _sut.GetUserId(); // Assert action.Should().ThrowExactly() @@ -168,7 +168,7 @@ public sealed class UserAccessorTests _httpContextAccessor.HttpContext!.User = new ClaimsPrincipal(); // Act - var action = () => _sut.GetUserId(); + Func action = () => _sut.GetUserId(); // Assert action.Should().ThrowExactly() diff --git a/tests/WebApi.Tests.Unit/Cars/CreateCarRequestValidatorTests.cs b/tests/WebApi.Tests.Unit/Cars/CreateCarRequestValidatorTests.cs index 127da32..2185cd3 100644 --- a/tests/WebApi.Tests.Unit/Cars/CreateCarRequestValidatorTests.cs +++ b/tests/WebApi.Tests.Unit/Cars/CreateCarRequestValidatorTests.cs @@ -1,4 +1,5 @@ using FluentAssertions; +using FluentValidation.Results; using Vegasco.WebApi.Cars; namespace WebApi.Tests.Unit.Cars; @@ -15,7 +16,7 @@ public sealed class CreateCarRequestValidatorTests // Arrange // Act - var result = await _sut.ValidateAsync(_validRequest); + ValidationResult? result = await _sut.ValidateAsync(_validRequest); // Assert result.IsValid.Should().BeTrue(); @@ -27,10 +28,10 @@ public sealed class CreateCarRequestValidatorTests public async Task ValidateAsync_ShouldBeValid_WhenNameIsJustWithinTheLimits(int nameLength) { // Arrange - var request = _validRequest with { Name = new string('s', nameLength) }; + CreateCar.Request request = _validRequest with { Name = new string('s', nameLength) }; // Act - var result = await _sut.ValidateAsync(request); + ValidationResult? result = await _sut.ValidateAsync(request); // Assert result.IsValid.Should().BeTrue(); @@ -40,10 +41,10 @@ public sealed class CreateCarRequestValidatorTests public async Task ValidateAsync_ShouldNotBeValid_WhenNameIsEmpty() { // Arrange - var request = _validRequest with { Name = "" }; + CreateCar.Request request = _validRequest with { Name = "" }; // Act - var result = await _sut.ValidateAsync(request); + ValidationResult? result = await _sut.ValidateAsync(request); // Assert result.IsValid.Should().BeFalse(); @@ -57,10 +58,10 @@ public sealed class CreateCarRequestValidatorTests { // Arrange const int nameMaxLength = 50; - var request = _validRequest with { Name = new string('s', nameMaxLength + 1) }; + CreateCar.Request request = _validRequest with { Name = new string('s', nameMaxLength + 1) }; // Act - var result = await _sut.ValidateAsync(request); + ValidationResult? result = await _sut.ValidateAsync(request); // Assert result.IsValid.Should().BeFalse(); diff --git a/tests/WebApi.Tests.Unit/Cars/UpdateCarRequestValidatorTests.cs b/tests/WebApi.Tests.Unit/Cars/UpdateCarRequestValidatorTests.cs index 8e2d1e0..366fd5a 100644 --- a/tests/WebApi.Tests.Unit/Cars/UpdateCarRequestValidatorTests.cs +++ b/tests/WebApi.Tests.Unit/Cars/UpdateCarRequestValidatorTests.cs @@ -1,4 +1,5 @@ using FluentAssertions; +using FluentValidation.Results; using Vegasco.WebApi.Cars; namespace WebApi.Tests.Unit.Cars; @@ -15,7 +16,7 @@ public sealed class UpdateCarRequestValidatorTests // Arrange // Act - var result = await _sut.ValidateAsync(_validRequest); + ValidationResult? result = await _sut.ValidateAsync(_validRequest); // Assert result.IsValid.Should().BeTrue(); @@ -27,10 +28,10 @@ public sealed class UpdateCarRequestValidatorTests public async Task ValidateAsync_ShouldBeValid_WhenNameIsJustWithinTheLimits(int nameLength) { // Arrange - var request = _validRequest with { Name = new string('s', nameLength) }; + UpdateCar.Request request = _validRequest with { Name = new string('s', nameLength) }; // Act - var result = await _sut.ValidateAsync(request); + ValidationResult? result = await _sut.ValidateAsync(request); // Assert result.IsValid.Should().BeTrue(); @@ -40,10 +41,10 @@ public sealed class UpdateCarRequestValidatorTests public async Task ValidateAsync_ShouldNotBeValid_WhenNameIsEmpty() { // Arrange - var request = _validRequest with { Name = "" }; + UpdateCar.Request request = _validRequest with { Name = "" }; // Act - var result = await _sut.ValidateAsync(request); + ValidationResult? result = await _sut.ValidateAsync(request); // Assert result.IsValid.Should().BeFalse(); @@ -57,10 +58,10 @@ public sealed class UpdateCarRequestValidatorTests { // Arrange const int nameMaxLength = 50; - var request = _validRequest with { Name = new string('s', nameMaxLength + 1) }; + UpdateCar.Request request = _validRequest with { Name = new string('s', nameMaxLength + 1) }; // Act - var result = await _sut.ValidateAsync(request); + ValidationResult? result = await _sut.ValidateAsync(request); // Assert result.IsValid.Should().BeFalse(); diff --git a/tests/WebApi.Tests.Unit/WebApi.Tests.Unit.csproj b/tests/WebApi.Tests.Unit/WebApi.Tests.Unit.csproj index e31c3b3..71caaf1 100644 --- a/tests/WebApi.Tests.Unit/WebApi.Tests.Unit.csproj +++ b/tests/WebApi.Tests.Unit/WebApi.Tests.Unit.csproj @@ -10,16 +10,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -34,7 +34,7 @@ - + diff --git a/vegasco-server.slnx b/vegasco-server.slnx index 5cc0fb0..a928535 100644 --- a/vegasco-server.slnx +++ b/vegasco-server.slnx @@ -6,8 +6,8 @@ - - + + @@ -15,4 +15,4 @@ - + \ No newline at end of file