mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-03 19:41:52 +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();
|
Task SeedAllAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ITestDataSeeder : IDataSeeder
|
public interface ITestDataSeeder
|
||||||
{
|
{
|
||||||
|
Task SeedAllAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class SeedManager(
|
|||||||
|
|
||||||
if (!env.IsEnvironment("test"))
|
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);
|
logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name);
|
||||||
await seeder.SeedAllAsync();
|
await seeder.SeedAllAsync();
|
||||||
@ -30,9 +30,9 @@ public class SeedManager(
|
|||||||
public async Task ExecuteTestSeedAsync()
|
public async Task ExecuteTestSeedAsync()
|
||||||
{
|
{
|
||||||
await using var scope = serviceProvider.CreateAsyncScope();
|
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);
|
logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name);
|
||||||
await seeder.SeedAllAsync();
|
await seeder.SeedAllAsync();
|
||||||
|
|||||||
@ -12,7 +12,7 @@ using Exception;
|
|||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddCustomMassTransit(this IServiceCollection services,
|
public static IServiceCollection AddCustomMassTransit(this IServiceCollection services,
|
||||||
IWebHostEnvironment env, Assembly assembly)
|
IWebHostEnvironment env, params Assembly[] assembly)
|
||||||
{
|
{
|
||||||
services.AddValidateOptions<RabbitMqOptions>();
|
services.AddValidateOptions<RabbitMqOptions>();
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public static class Extensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void SetupMasstransitConfigurations(IServiceCollection services,
|
private static void SetupMasstransitConfigurations(IServiceCollection services,
|
||||||
IBusRegistrationConfigurator configure, Assembly assembly)
|
IBusRegistrationConfigurator configure, params Assembly[] assembly)
|
||||||
{
|
{
|
||||||
configure.AddConsumers(assembly);
|
configure.AddConsumers(assembly);
|
||||||
configure.AddSagaStateMachines(assembly);
|
configure.AddSagaStateMachines(assembly);
|
||||||
|
|||||||
@ -8,10 +8,7 @@ namespace BuildingBlocks.PersistMessageProcessor;
|
|||||||
|
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddPersistMessageProcessor(
|
public static IServiceCollection AddPersistMessageProcessor(this IServiceCollection services)
|
||||||
this IServiceCollection services,
|
|
||||||
IWebHostEnvironment env
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@ public class PersistMessageBackgroundService(
|
|||||||
logger.LogInformation("PersistMessage Background Service Start");
|
logger.LogInformation("PersistMessage Background Service Start");
|
||||||
|
|
||||||
await ProcessAsync(stoppingToken);
|
await ProcessAsync(stoppingToken);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task StopAsync(CancellationToken cancellationToken)
|
public override Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
|||||||
@ -10,7 +10,6 @@ using Microsoft.Extensions.Logging;
|
|||||||
namespace BuildingBlocks.PersistMessageProcessor;
|
namespace BuildingBlocks.PersistMessageProcessor;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Polly;
|
|
||||||
|
|
||||||
public class PersistMessageProcessor : IPersistMessageProcessor
|
public class PersistMessageProcessor : IPersistMessageProcessor
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,15 +1,18 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using Ardalis.GuardClauses;
|
using Ardalis.GuardClauses;
|
||||||
using BuildingBlocks.Core.Event;
|
using BuildingBlocks.Core.Event;
|
||||||
using BuildingBlocks.Core.Model;
|
using BuildingBlocks.Core.Model;
|
||||||
using BuildingBlocks.EFCore;
|
using BuildingBlocks.EFCore;
|
||||||
|
using BuildingBlocks.MassTransit;
|
||||||
using BuildingBlocks.Mongo;
|
using BuildingBlocks.Mongo;
|
||||||
using BuildingBlocks.PersistMessageProcessor;
|
using BuildingBlocks.PersistMessageProcessor;
|
||||||
using BuildingBlocks.Web;
|
using BuildingBlocks.Web;
|
||||||
using EasyNetQ.Management.Client;
|
using EasyNetQ.Management.Client;
|
||||||
using Grpc.Net.Client;
|
using Grpc.Net.Client;
|
||||||
|
using MassTransit;
|
||||||
using MassTransit.Testing;
|
using MassTransit.Testing;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
@ -96,8 +99,11 @@ where TEntryPoint : class
|
|||||||
{
|
{
|
||||||
TestRegistrationServices?.Invoke(services);
|
TestRegistrationServices?.Invoke(services);
|
||||||
services.ReplaceSingleton(AddHttpContextAccessorMock);
|
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
|
// Register all ITestDataSeeder implementations dynamically
|
||||||
services.Scan(scan => scan
|
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.AddMongoDbContext<BookingReadDbContext>(configuration);
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
|||||||
@ -67,7 +67,7 @@ public static class InfrastructureExtensions
|
|||||||
builder.Services.AddCustomDbContext<FlightDbContext>();
|
builder.Services.AddCustomDbContext<FlightDbContext>();
|
||||||
builder.Services.AddScoped<IDataSeeder, FlightDataSeeder>();
|
builder.Services.AddScoped<IDataSeeder, FlightDataSeeder>();
|
||||||
builder.Services.AddMongoDbContext<FlightReadDbContext>(configuration);
|
builder.Services.AddMongoDbContext<FlightReadDbContext>(configuration);
|
||||||
builder.Services.AddPersistMessageProcessor(env);
|
builder.Services.AddPersistMessageProcessor();
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.AddCustomSerilog(env);
|
builder.AddCustomSerilog(env);
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public static class InfrastructureExtensions
|
|||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.Services.AddPersistMessageProcessor(env);
|
builder.Services.AddPersistMessageProcessor();
|
||||||
builder.Services.AddCustomDbContext<IdentityContext>();
|
builder.Services.AddCustomDbContext<IdentityContext>();
|
||||||
builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
|
builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
|
||||||
builder.AddCustomSerilog(env);
|
builder.AddCustomSerilog(env);
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public static class InfrastructureExtensions
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddPersistMessageProcessor(env);
|
builder.Services.AddPersistMessageProcessor();
|
||||||
builder.Services.AddCustomDbContext<PassengerDbContext>();
|
builder.Services.AddCustomDbContext<PassengerDbContext>();
|
||||||
builder.Services.AddMongoDbContext<PassengerReadDbContext>(configuration);
|
builder.Services.AddMongoDbContext<PassengerReadDbContext>(configuration);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user