From 1bd845130c6d2041617df93998f1a56fdc9cd9e9 Mon Sep 17 00:00:00 2001 From: Tom Brereton Date: Tue, 10 Sep 2024 20:37:24 +1000 Subject: [PATCH] fix tests --- src/Web.Api/Features/Calendars/CreateCalendar.cs | 2 +- src/Web.Api/Features/DependencyInjection.cs | 16 ++++++++++++++++ src/Web.Api/Program.cs | 8 ++------ .../Helpers/MsSqlContainerStartup.cs | 2 ++ .../Database/AppointerDbContextShould.cs | 2 +- .../Publishing/AppointerDbContextShould.cs | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/Web.Api/Features/DependencyInjection.cs diff --git a/src/Web.Api/Features/Calendars/CreateCalendar.cs b/src/Web.Api/Features/Calendars/CreateCalendar.cs index 14b92a6..8765694 100644 --- a/src/Web.Api/Features/Calendars/CreateCalendar.cs +++ b/src/Web.Api/Features/Calendars/CreateCalendar.cs @@ -10,7 +10,7 @@ public static class CreateCalendar { public class Handler : INotificationHandler { - private IUserAccountRepository _repository; + private readonly IUserAccountRepository _repository; public Handler(IUserAccountRepository repository) { diff --git a/src/Web.Api/Features/DependencyInjection.cs b/src/Web.Api/Features/DependencyInjection.cs new file mode 100644 index 0000000..f800664 --- /dev/null +++ b/src/Web.Api/Features/DependencyInjection.cs @@ -0,0 +1,16 @@ +using Carter; +using FluentValidation; + +namespace Web.Api.Features; + +public static class DependencyInjection +{ + public static IServiceCollection AddFeatures(this IServiceCollection services) + { + var assembly = typeof(Web.Api.Program).Assembly; + services.AddMediatR(config => config.RegisterServicesFromAssembly(assembly)); + services.AddCarter(); + services.AddValidatorsFromAssembly(assembly); + return services; + } +} \ No newline at end of file diff --git a/src/Web.Api/Program.cs b/src/Web.Api/Program.cs index 2500302..78ea7ab 100644 --- a/src/Web.Api/Program.cs +++ b/src/Web.Api/Program.cs @@ -1,20 +1,16 @@ using Carter; using FluentValidation; +using Web.Api.Features; using Web.Api.Infrastructure; var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.AddFeatures(); builder.Services.AddInfrastructure(builder.Configuration); -var assembly = typeof(Web.Api.Program).Assembly; -builder.Services.AddMediatR(config => config.RegisterServicesFromAssembly(assembly)); -builder.Services.AddCarter(); -builder.Services.AddValidatorsFromAssembly(assembly); - var app = builder.Build(); - if (app.Environment.IsDevelopment()) { app.UseSwagger(); diff --git a/tests/Web.Api.IntegrationTests/Helpers/MsSqlContainerStartup.cs b/tests/Web.Api.IntegrationTests/Helpers/MsSqlContainerStartup.cs index 79f3155..9805f6c 100644 --- a/tests/Web.Api.IntegrationTests/Helpers/MsSqlContainerStartup.cs +++ b/tests/Web.Api.IntegrationTests/Helpers/MsSqlContainerStartup.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Testcontainers.MsSql; +using Web.Api.Features; using Web.Api.Infrastructure; using Web.Api.Infrastructure.Database; @@ -24,6 +25,7 @@ public async Task InitializeAsync() Services = new ServiceCollection() .AddInfrastructure(config) + .AddFeatures() .BuildServiceProvider(); var db = Services.GetRequiredService(); diff --git a/tests/Web.Api.IntegrationTests/Infrastructure/Database/AppointerDbContextShould.cs b/tests/Web.Api.IntegrationTests/Infrastructure/Database/AppointerDbContextShould.cs index 7635360..52e1b71 100644 --- a/tests/Web.Api.IntegrationTests/Infrastructure/Database/AppointerDbContextShould.cs +++ b/tests/Web.Api.IntegrationTests/Infrastructure/Database/AppointerDbContextShould.cs @@ -8,7 +8,7 @@ namespace Web.Api.IntegrationTests.Infrastructure.Database; public class AppointerDbContextShould : MsSqlContainerStartup { - // [Fact] + [Fact] public async Task PersistUserAccount() { // arrange diff --git a/tests/Web.Api.IntegrationTests/Infrastructure/Publishing/AppointerDbContextShould.cs b/tests/Web.Api.IntegrationTests/Infrastructure/Publishing/AppointerDbContextShould.cs index a01d594..2c03814 100644 --- a/tests/Web.Api.IntegrationTests/Infrastructure/Publishing/AppointerDbContextShould.cs +++ b/tests/Web.Api.IntegrationTests/Infrastructure/Publishing/AppointerDbContextShould.cs @@ -8,7 +8,7 @@ namespace Web.Api.IntegrationTests.Infrastructure.Publishing; public class AppointerDbContextShould : MsSqlContainerStartup { - // [Fact] + [Fact] public async Task PersistUserAccount() { // arrange