diff --git a/src/BuildingBlocks/EFCore/IDataSeeder.cs b/src/BuildingBlocks/EFCore/IDataSeeder.cs index f09d485e..a3083ff0 100644 --- a/src/BuildingBlocks/EFCore/IDataSeeder.cs +++ b/src/BuildingBlocks/EFCore/IDataSeeder.cs @@ -5,7 +5,8 @@ public interface IDataSeeder Task SeedAllAsync(); } - public interface ITestDataSeeder : IDataSeeder + public interface ITestDataSeeder { + Task SeedAllAsync(); } } diff --git a/src/BuildingBlocks/EFCore/SeedManagers.cs b/src/BuildingBlocks/EFCore/SeedManagers.cs index 9ba1a3de..e50715aa 100644 --- a/src/BuildingBlocks/EFCore/SeedManagers.cs +++ b/src/BuildingBlocks/EFCore/SeedManagers.cs @@ -18,7 +18,7 @@ public async Task ExecuteSeedAsync() if (!env.IsEnvironment("test")) { - foreach (var seeder in dataSeeders.Where(x => x is not ITestDataSeeder)) + foreach (var seeder in dataSeeders) { logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name); await seeder.SeedAllAsync(); @@ -30,9 +30,9 @@ public async Task ExecuteSeedAsync() public async Task ExecuteTestSeedAsync() { await using var scope = serviceProvider.CreateAsyncScope(); - var dataSeeders = scope.ServiceProvider.GetServices(); + var dataSeeders = scope.ServiceProvider.GetServices(); - foreach (var seeder in dataSeeders.Where(x => x is ITestDataSeeder)) + foreach (var seeder in dataSeeders) { logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name); await seeder.SeedAllAsync(); diff --git a/src/BuildingBlocks/MassTransit/Extensions.cs b/src/BuildingBlocks/MassTransit/Extensions.cs index b264bbd4..ae09548c 100644 --- a/src/BuildingBlocks/MassTransit/Extensions.cs +++ b/src/BuildingBlocks/MassTransit/Extensions.cs @@ -12,7 +12,7 @@ namespace BuildingBlocks.MassTransit; public static class Extensions { public static IServiceCollection AddCustomMassTransit(this IServiceCollection services, - IWebHostEnvironment env, Assembly assembly) + IWebHostEnvironment env, params Assembly[] assembly) { services.AddValidateOptions(); @@ -32,7 +32,7 @@ public static IServiceCollection AddCustomMassTransit(this IServiceCollection se } private static void SetupMasstransitConfigurations(IServiceCollection services, - IBusRegistrationConfigurator configure, Assembly assembly) + IBusRegistrationConfigurator configure, params Assembly[] assembly) { configure.AddConsumers(assembly); configure.AddSagaStateMachines(assembly); diff --git a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs index 5aef3604..ed62cbde 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs @@ -8,10 +8,7 @@ namespace BuildingBlocks.PersistMessageProcessor; public static class Extensions { - public static IServiceCollection AddPersistMessageProcessor( - this IServiceCollection services, - IWebHostEnvironment env - ) + public static IServiceCollection AddPersistMessageProcessor(this IServiceCollection services) { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); diff --git a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs index 7ec8f646..35ee175f 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs @@ -19,7 +19,6 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) logger.LogInformation("PersistMessage Background Service Start"); await ProcessAsync(stoppingToken); - } public override Task StopAsync(CancellationToken cancellationToken) diff --git a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs index faa4b84a..ecb53ca0 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs @@ -10,7 +10,6 @@ namespace BuildingBlocks.PersistMessageProcessor; using Microsoft.EntityFrameworkCore; -using Polly; public class PersistMessageProcessor : IPersistMessageProcessor { diff --git a/src/BuildingBlocks/TestBase/TestBase.cs b/src/BuildingBlocks/TestBase/TestBase.cs index ba54b4a4..ee5513fa 100644 --- a/src/BuildingBlocks/TestBase/TestBase.cs +++ b/src/BuildingBlocks/TestBase/TestBase.cs @@ -1,15 +1,18 @@ using System.Globalization; using System.Net; +using System.Reflection; using System.Security.Claims; using Ardalis.GuardClauses; using BuildingBlocks.Core.Event; using BuildingBlocks.Core.Model; using BuildingBlocks.EFCore; +using BuildingBlocks.MassTransit; using BuildingBlocks.Mongo; using BuildingBlocks.PersistMessageProcessor; using BuildingBlocks.Web; using EasyNetQ.Management.Client; using Grpc.Net.Client; +using MassTransit; using MassTransit.Testing; using MediatR; using Microsoft.AspNetCore.Hosting; @@ -96,8 +99,11 @@ protected TestFixture() { TestRegistrationServices?.Invoke(services); services.ReplaceSingleton(AddHttpContextAccessorMock); - services.RemoveAll(); - services.AddSingleton(); + + services.RemoveHostedService(); + services.AddSingleton(); // Register as a singleton + services.AddHostedService(provider => provider.GetRequiredService()); // Use the same instance for hosted service + // Register all ITestDataSeeder implementations dynamically services.Scan(scan => scan diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index 56c4b155..18f8ba8d 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -58,7 +58,7 @@ public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder })); }); - builder.Services.AddPersistMessageProcessor(env); + builder.Services.AddPersistMessageProcessor(); builder.Services.AddMongoDbContext(configuration); builder.Services.AddEndpointsApiExplorer(); diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index e75c24d3..fd06f53b 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -67,7 +67,7 @@ public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder.Services.AddCustomDbContext(); builder.Services.AddScoped(); builder.Services.AddMongoDbContext(configuration); - builder.Services.AddPersistMessageProcessor(env); + builder.Services.AddPersistMessageProcessor(); builder.Services.AddEndpointsApiExplorer(); builder.AddCustomSerilog(env); diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs index b4efd409..8960e461 100644 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -61,7 +61,7 @@ public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder.Services.AddEndpointsApiExplorer(); builder.Services.AddControllers(); - builder.Services.AddPersistMessageProcessor(env); + builder.Services.AddPersistMessageProcessor(); builder.Services.AddCustomDbContext(); builder.Services.AddScoped(); builder.AddCustomSerilog(env); diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index 024250eb..cbcadd8e 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -60,7 +60,7 @@ public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder })); }); - builder.Services.AddPersistMessageProcessor(env); + builder.Services.AddPersistMessageProcessor(); builder.Services.AddCustomDbContext(); builder.Services.AddMongoDbContext(configuration);