Update packages, use explicit type, use Microsoft OpenApi package
This commit is contained in:
@@ -11,6 +11,6 @@ public static class Constants
|
||||
{
|
||||
public const string ServiceName = "postgres";
|
||||
|
||||
public const string Name = "vegasco";
|
||||
public const string Name = "vegasco-database";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="Nerdbank.GitVersioning">
|
||||
<Version>3.7.115</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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<PostgresDatabaseResource> postgres = builder.AddPostgres(Constants.Database.ServiceName)
|
||||
.WithDataVolume()
|
||||
.AddDatabase(Constants.Database.Name);
|
||||
|
||||
|
||||
@@ -12,8 +12,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
|
||||
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.0.0" />
|
||||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0" />
|
||||
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.3.0" />
|
||||
<PackageReference Update="Nerdbank.GitVersioning">
|
||||
<Version>3.7.115</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -72,7 +72,7 @@ public static class Extensions
|
||||
|
||||
private static TBuilder AddOpenTelemetryExporters<TBuilder>(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)
|
||||
{
|
||||
|
||||
@@ -10,13 +10,16 @@
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.5.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.3.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.12.0" />
|
||||
<PackageReference Update="Nerdbank.GitVersioning">
|
||||
<Version>3.7.115</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Adds all the WebApi related services to the Dependency Injection container.
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="environment"></param>
|
||||
/// <param name="builder"></param>
|
||||
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<IWebApiMarker>();
|
||||
|
||||
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<ConfigureSwaggerGenOptions>();
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Vegasco.WebApi.Common;
|
||||
@@ -25,7 +26,7 @@ public class FluentValidationOptions<TOptions> : IValidateOptions<TOptions>
|
||||
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
|
||||
var failedValidations = _validators.ValidateAllAsync(options).Result;
|
||||
List<ValidationResult> failedValidations = _validators.ValidateAllAsync(options).Result;
|
||||
if (failedValidations.Count == 0)
|
||||
{
|
||||
return ValidateOptionsResult.Success;
|
||||
|
||||
@@ -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<ApiVersionDescription> 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;
|
||||
|
||||
@@ -15,7 +15,7 @@ public static class ValidatorExtensions
|
||||
/// <returns>The failed validation results.</returns>
|
||||
public static async Task<List<ValidationResult>> ValidateAllAsync<T>(this IEnumerable<IValidator<T>> validators, T instance, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var validationTasks = validators
|
||||
List<Task<ValidationResult>> 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<string, HashSet<string>> 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<string>? value))
|
||||
{
|
||||
@@ -54,7 +54,7 @@ public static class ValidatorExtensions
|
||||
{
|
||||
builder.Services.AddTransient<IValidateOptions<T>>(serviceProvider =>
|
||||
{
|
||||
var validators = serviceProvider.GetServices<IValidator<T>>() ?? [];
|
||||
IEnumerable<IValidator<T>> validators = serviceProvider.GetServices<IValidator<T>>() ?? [];
|
||||
return new FluentValidationOptions<T>(builder.Name, validators);
|
||||
});
|
||||
return builder;
|
||||
|
||||
@@ -10,22 +10,6 @@ namespace Vegasco.WebApi.Endpoints;
|
||||
|
||||
public static class EndpointExtensions
|
||||
{
|
||||
public static IServiceCollection AddEndpointsFromAssemblyContaining<T>(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()
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Vegasco.WebApi.Endpoints;
|
||||
|
||||
public interface IEndpoint
|
||||
{
|
||||
void MapEndpoint(IEndpointRouteBuilder builder);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Registers each api version as its own swagger document.
|
||||
/// </summary>
|
||||
/// <param name="versionDescriptionProvider"></param>
|
||||
public class ConfigureSwaggerGenOptions(
|
||||
IApiVersionDescriptionProvider versionDescriptionProvider)
|
||||
: IConfigureNamedOptions<SwaggerGenOptions>
|
||||
{
|
||||
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<string>() }
|
||||
});
|
||||
|
||||
OpenApiInfo openApiInfo = new()
|
||||
{
|
||||
Title = "Vegasco API",
|
||||
Version = description.ApiVersion.ToString()
|
||||
};
|
||||
|
||||
options.SwaggerDoc(description.GroupName, openApiInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public void Configure(string? name, SwaggerGenOptions options)
|
||||
{
|
||||
Configure(options);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Vegasco.WebApi.Endpoints.OpenApi;
|
||||
|
||||
public static class SwaggerDocConstants
|
||||
{
|
||||
|
||||
}
|
||||
@@ -2,18 +2,14 @@
|
||||
|
||||
namespace Vegasco.WebApi.Persistence;
|
||||
|
||||
public class ApplyMigrationsService : IHostedService
|
||||
public class ApplyMigrationsService(ILogger<ApplyMigrationsService> 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<ApplicationDbContext>();
|
||||
await dbContext.Database.MigrateAsync(cancellationToken);
|
||||
}
|
||||
|
||||
@@ -13,25 +13,24 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Http" Version="8.1.0" />
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
|
||||
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.3.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
|
||||
<PackageReference Include="OpenTelemetry" Version="1.10.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.2" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="OpenTelemetry" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
|
||||
<PackageReference Include="StronglyTypedId" Version="1.0.0-beta08" PrivateAssets="all" ExcludeAssets="runtime" />
|
||||
<PackageReference Include="StronglyTypedId.Templates" Version="1.0.0-beta08" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -40,7 +39,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="Nerdbank.GitVersioning" Version="3.7.112" />
|
||||
<PackageReference Update="Nerdbank.GitVersioning" Version="3.7.115" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<CreateCar.Response>();
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -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<CreateCar.Response>();
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -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<CreateCar.Response>();
|
||||
|
||||
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<CreateCar.Response>();
|
||||
|
||||
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);
|
||||
|
||||
@@ -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<GetConsumption.Response>();
|
||||
consumption.Should().BeEquivalentTo(createdConsumption);
|
||||
|
||||
@@ -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<UpdateConsumption.Response>();
|
||||
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>();
|
||||
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);
|
||||
|
||||
@@ -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); ;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,21 +10,21 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Identity" Version="1.13.1" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Azure.Identity" Version="1.14.0" />
|
||||
<PackageReference Include="Bogus" Version="35.6.3" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="8.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Respawn" Version="6.2.1" />
|
||||
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
|
||||
<PackageReference Include="Testcontainers.PostgreSql" Version="4.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
|
||||
<PackageReference Include="System.Formats.Asn1" Version="9.0.5" />
|
||||
<PackageReference Include="Testcontainers.PostgreSql" Version="4.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
@@ -40,7 +40,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="Nerdbank.GitVersioning" Version="3.7.112" />
|
||||
<PackageReference Update="Nerdbank.GitVersioning" Version="3.7.115" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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<string> action = () => _sut.GetUsername();
|
||||
|
||||
// Assert
|
||||
action.Should().ThrowExactly<InvalidOperationException>()
|
||||
@@ -109,7 +109,7 @@ public sealed class UserAccessorTests
|
||||
_httpContextAccessor.HttpContext!.User = new ClaimsPrincipal();
|
||||
|
||||
// Act
|
||||
var action = () => _sut.GetUsername();
|
||||
Func<string> action = () => _sut.GetUsername();
|
||||
|
||||
// Assert
|
||||
action.Should().ThrowExactly<InvalidOperationException>()
|
||||
@@ -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<string> action = () => _sut.GetUserId();
|
||||
|
||||
// Assert
|
||||
action.Should().ThrowExactly<InvalidOperationException>()
|
||||
@@ -168,7 +168,7 @@ public sealed class UserAccessorTests
|
||||
_httpContextAccessor.HttpContext!.User = new ClaimsPrincipal();
|
||||
|
||||
// Act
|
||||
var action = () => _sut.GetUserId();
|
||||
Func<string> action = () => _sut.GetUserId();
|
||||
|
||||
// Assert
|
||||
action.Should().ThrowExactly<InvalidOperationException>()
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="8.3.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
@@ -34,7 +34,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="Nerdbank.GitVersioning" Version="3.7.112" />
|
||||
<PackageReference Update="Nerdbank.GitVersioning" Version="3.7.115" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<File Path="version.json" />
|
||||
</Folder>
|
||||
<Folder Name="/src/">
|
||||
<Project Path="src/Vegasco.Server.AppHost.Shared/Vegasco.Server.AppHost.Shared.csproj" Id="218fcbfa-9ff7-45a2-a9b9-2351a304223f" />
|
||||
<Project Path="src/Vegasco.Server.AppHost/Vegasco.Server.AppHost.csproj" Id="ae9c4f8c-43c9-4fad-bcc6-23b952458935" />
|
||||
<Project Path="src/Vegasco.Server.AppHost.Shared/Vegasco.Server.AppHost.Shared.csproj" />
|
||||
<Project Path="src/Vegasco.Server.AppHost/Vegasco.Server.AppHost.csproj" />
|
||||
<Project Path="src/Vegasco.Server.ServiceDefaults/Vegasco.Server.ServiceDefaults.csproj" />
|
||||
<Project Path="src/WebApi/WebApi.csproj" />
|
||||
</Folder>
|
||||
|
||||
Reference in New Issue
Block a user