refactor(tests): streamline service removal in CustomersControllerTests

This commit is contained in:
Jean Gatto
2025-08-10 09:04:11 -03:00
parent 34e4f22012
commit 80f5614579
2 changed files with 14 additions and 14 deletions
+2 -1
View File
@@ -20,7 +20,8 @@ public static class ConfigureServices
var assembly = Assembly.GetAssembly(typeof(IApplicationMarker)); var assembly = Assembly.GetAssembly(typeof(IApplicationMarker));
return services return services
.AddValidatorsFromAssembly(assembly, ServiceLifetime.Singleton) .AddValidatorsFromAssembly(assembly, ServiceLifetime.Singleton)
.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(assembly) .AddMediatR(cfg => cfg
.RegisterServicesFromAssembly(assembly)
.AddBehavior(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>))); .AddBehavior(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)));
} }
} }
@@ -484,14 +484,15 @@ public class CustomersControllerTests : IAsyncLifetime
hostBuilder.ConfigureServices(services => hostBuilder.ConfigureServices(services =>
{ {
services.RemoveAll<DbConnection>(); services
services.RemoveAll<DbContextOptions>(); .RemoveAll<DbConnection>()
services.RemoveAll<WriteDbContext>(); .RemoveAll<DbContextOptions>()
services.RemoveAll<DbContextOptions<WriteDbContext>>(); .RemoveAll<WriteDbContext>()
services.RemoveAll<EventStoreDbContext>(); .RemoveAll<DbContextOptions<WriteDbContext>>()
services.RemoveAll<DbContextOptions<EventStoreDbContext>>(); .RemoveAll<EventStoreDbContext>()
services.RemoveAll<NoSqlDbContext>(); .RemoveAll<DbContextOptions<EventStoreDbContext>>()
services.RemoveAll<ISynchronizeDb>(); .RemoveAll<NoSqlDbContext>()
.RemoveAll<ISynchronizeDb>();
services.AddDbContext<WriteDbContext>( services.AddDbContext<WriteDbContext>(
options => options options => options
@@ -503,8 +504,9 @@ public class CustomersControllerTests : IAsyncLifetime
.UseSqlite(_eventStoreDbContextSqlite) .UseSqlite(_eventStoreDbContextSqlite)
.ConfigureWarnings(warningBuilder => warningBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning))); .ConfigureWarnings(warningBuilder => warningBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
services.AddSingleton(_ => Substitute.For<IReadDbContext>()); services
services.AddSingleton(_ => Substitute.For<ISynchronizeDb>()); .AddSingleton(_ => Substitute.For<IReadDbContext>())
.AddSingleton(_ => Substitute.For<ISynchronizeDb>());
configureServices?.Invoke(services); configureServices?.Invoke(services);
@@ -518,9 +520,6 @@ public class CustomersControllerTests : IAsyncLifetime
eventStoreDbContext.Database.EnsureCreated(); eventStoreDbContext.Database.EnsureCreated();
configureServiceScope?.Invoke(serviceScope); configureServiceScope?.Invoke(serviceScope);
writeDbContext.Dispose();
eventStoreDbContext.Dispose();
}); });
}); });
} }