diff --git a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs index 5aef3604..1efc84a4 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs @@ -51,7 +51,10 @@ IWebHostEnvironment env services.AddScoped(); - services.AddHostedService(); + if (env.EnvironmentName != "test") + { + services.AddHostedService(); + } return services; } diff --git a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs index 68f40925..7ec8f646 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs @@ -14,15 +14,12 @@ IOptions options { private PersistMessageOptions _options = options.Value; - private Task? _executingTask; - - protected override Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogInformation("PersistMessage Background Service Start"); - _executingTask = ProcessAsync(stoppingToken); + await ProcessAsync(stoppingToken); - return _executingTask; } public override Task StopAsync(CancellationToken cancellationToken) diff --git a/src/BuildingBlocks/TestBase/TestBase.cs b/src/BuildingBlocks/TestBase/TestBase.cs index 4f788832..20c3c0b0 100644 --- a/src/BuildingBlocks/TestBase/TestBase.cs +++ b/src/BuildingBlocks/TestBase/TestBase.cs @@ -95,8 +95,7 @@ protected TestFixture() { TestRegistrationServices?.Invoke(services); services.ReplaceSingleton(AddHttpContextAccessorMock); - services.RemoveAll(); - + // services.RemoveAll(); services.AddSingleton(); // Register all ITestDataSeeder implementations dynamically