mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-18 01:42:10 +08:00
fix: fix issue in registration persist message background service in test base
This commit is contained in:
parent
b9aa18a043
commit
321b7ce901
@ -5,7 +5,8 @@ namespace BuildingBlocks.EFCore
|
||||
Task SeedAllAsync();
|
||||
}
|
||||
|
||||
public interface ITestDataSeeder : IDataSeeder
|
||||
public interface ITestDataSeeder
|
||||
{
|
||||
Task SeedAllAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ public class SeedManager(
|
||||
|
||||
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 class SeedManager(
|
||||
public async Task ExecuteTestSeedAsync()
|
||||
{
|
||||
await using var scope = serviceProvider.CreateAsyncScope();
|
||||
var dataSeeders = scope.ServiceProvider.GetServices<IDataSeeder>();
|
||||
var dataSeeders = scope.ServiceProvider.GetServices<ITestDataSeeder>();
|
||||
|
||||
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();
|
||||
|
||||
@ -12,7 +12,7 @@ using Exception;
|
||||
public static class Extensions
|
||||
{
|
||||
public static IServiceCollection AddCustomMassTransit(this IServiceCollection services,
|
||||
IWebHostEnvironment env, Assembly assembly)
|
||||
IWebHostEnvironment env, params Assembly[] assembly)
|
||||
{
|
||||
services.AddValidateOptions<RabbitMqOptions>();
|
||||
|
||||
@ -32,7 +32,7 @@ public static class Extensions
|
||||
}
|
||||
|
||||
private static void SetupMasstransitConfigurations(IServiceCollection services,
|
||||
IBusRegistrationConfigurator configure, Assembly assembly)
|
||||
IBusRegistrationConfigurator configure, params Assembly[] assembly)
|
||||
{
|
||||
configure.AddConsumers(assembly);
|
||||
configure.AddSagaStateMachines(assembly);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ public class PersistMessageBackgroundService(
|
||||
logger.LogInformation("PersistMessage Background Service Start");
|
||||
|
||||
await ProcessAsync(stoppingToken);
|
||||
|
||||
}
|
||||
|
||||
public override Task StopAsync(CancellationToken cancellationToken)
|
||||
|
||||
@ -10,7 +10,6 @@ using Microsoft.Extensions.Logging;
|
||||
namespace BuildingBlocks.PersistMessageProcessor;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Polly;
|
||||
|
||||
public class PersistMessageProcessor : IPersistMessageProcessor
|
||||
{
|
||||
|
||||
@ -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 @@ where TEntryPoint : class
|
||||
{
|
||||
TestRegistrationServices?.Invoke(services);
|
||||
services.ReplaceSingleton(AddHttpContextAccessorMock);
|
||||
services.RemoveAll<IHostedService>();
|
||||
services.AddSingleton<PersistMessageBackgroundService>();
|
||||
|
||||
services.RemoveHostedService<PersistMessageBackgroundService>();
|
||||
services.AddSingleton<PersistMessageBackgroundService>(); // Register as a singleton
|
||||
services.AddHostedService(provider => provider.GetRequiredService<PersistMessageBackgroundService>()); // Use the same instance for hosted service
|
||||
|
||||
|
||||
// Register all ITestDataSeeder implementations dynamically
|
||||
services.Scan(scan => scan
|
||||
|
||||
@ -58,7 +58,7 @@ public static class InfrastructureExtensions
|
||||
}));
|
||||
});
|
||||
|
||||
builder.Services.AddPersistMessageProcessor(env);
|
||||
builder.Services.AddPersistMessageProcessor();
|
||||
builder.Services.AddMongoDbContext<BookingReadDbContext>(configuration);
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
@ -67,7 +67,7 @@ public static class InfrastructureExtensions
|
||||
builder.Services.AddCustomDbContext<FlightDbContext>();
|
||||
builder.Services.AddScoped<IDataSeeder, FlightDataSeeder>();
|
||||
builder.Services.AddMongoDbContext<FlightReadDbContext>(configuration);
|
||||
builder.Services.AddPersistMessageProcessor(env);
|
||||
builder.Services.AddPersistMessageProcessor();
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.AddCustomSerilog(env);
|
||||
|
||||
@ -61,7 +61,7 @@ public static class InfrastructureExtensions
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddPersistMessageProcessor(env);
|
||||
builder.Services.AddPersistMessageProcessor();
|
||||
builder.Services.AddCustomDbContext<IdentityContext>();
|
||||
builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
|
||||
builder.AddCustomSerilog(env);
|
||||
|
||||
@ -60,7 +60,7 @@ public static class InfrastructureExtensions
|
||||
}));
|
||||
});
|
||||
|
||||
builder.Services.AddPersistMessageProcessor(env);
|
||||
builder.Services.AddPersistMessageProcessor();
|
||||
builder.Services.AddCustomDbContext<PassengerDbContext>();
|
||||
builder.Services.AddMongoDbContext<PassengerReadDbContext>(configuration);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user