mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-14 04:28:38 +08:00
Merge branch 'develop'
This commit is contained in:
commit
eac0faab75
@ -27,7 +27,7 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace BuildingBlocks.TestBase;
|
||||
|
||||
public class IntegrationTestFactory<TEntryPoint> : IAsyncLifetime
|
||||
public class IntegrationTestFactory<TEntryPoint> : IAsyncDisposable
|
||||
where TEntryPoint : class
|
||||
{
|
||||
private readonly WebApplicationFactory<TEntryPoint> _factory;
|
||||
@ -40,6 +40,10 @@ public class IntegrationTestFactory<TEntryPoint> : IAsyncLifetime
|
||||
public IServiceProvider ServiceProvider => _factory.Services;
|
||||
public IConfiguration Configuration => _factory.Services.GetRequiredService<IConfiguration>();
|
||||
|
||||
public MsSqlTestcontainer SqlTestContainer;
|
||||
public MsSqlTestcontainer SqlPersistTestContainer;
|
||||
public MongoDbTestcontainer MongoTestContainer;
|
||||
|
||||
public IntegrationTestFactory()
|
||||
{
|
||||
_factory = new WebApplicationFactory<TEntryPoint>()
|
||||
@ -69,13 +73,7 @@ public class IntegrationTestFactory<TEntryPoint> : IAsyncLifetime
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task DisposeAsync()
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await _factory.DisposeAsync();
|
||||
}
|
||||
@ -364,9 +362,18 @@ public class IntegrationTestFixtureCore<TEntryPoint> : IAsyncLifetime
|
||||
if (MongoConnectionString != null)
|
||||
MongoConnectionString = _mongoRunner.ConnectionString;
|
||||
|
||||
// DefaultConnectionString = TestContainers.SqlTestContainer?.ConnectionString;
|
||||
// PersistConnectionString = TestContainers.SqlPersistTestContainer?.ConnectionString;
|
||||
// MongoConnectionString = TestContainers.MongoTestContainer?.ConnectionString;
|
||||
// <<For using test-container base>>
|
||||
// Fixture.SqlTestContainer = TestContainers.SqlTestContainer;
|
||||
// Fixture.SqlPersistTestContainer = TestContainers.SqlPersistTestContainer;
|
||||
// Fixture.MongoTestContainer = TestContainers.MongoTestContainer;
|
||||
//
|
||||
// await Fixture.SqlTestContainer.StartAsync();
|
||||
// await Fixture.SqlPersistTestContainer.StartAsync();
|
||||
// await Fixture.MongoTestContainer.StartAsync();
|
||||
//
|
||||
// DefaultConnectionString = Fixture.SqlTestContainer?.ConnectionString;
|
||||
// PersistConnectionString = Fixture.SqlPersistTestContainer?.ConnectionString;
|
||||
// MongoConnectionString = Fixture.MongoTestContainer?.ConnectionString;
|
||||
|
||||
await SeedDataAsync();
|
||||
}
|
||||
@ -381,6 +388,11 @@ public class IntegrationTestFixtureCore<TEntryPoint> : IAsyncLifetime
|
||||
|
||||
if (!string.IsNullOrEmpty(PersistConnectionString))
|
||||
_mongoRunner.Dispose();
|
||||
|
||||
// <<For using test-container base>>
|
||||
// await Fixture.SqlTestContainer.StopAsync();
|
||||
// await Fixture.SqlPersistTestContainer.StopAsync();
|
||||
// await Fixture.MongoTestContainer.StopAsync();
|
||||
}
|
||||
|
||||
protected virtual void RegisterTestsServices(IServiceCollection services)
|
||||
|
||||
@ -8,26 +8,28 @@ public static class TestContainers
|
||||
{
|
||||
public static MsSqlTestcontainer SqlTestContainer => new TestcontainersBuilder<MsSqlTestcontainer>()
|
||||
.WithDatabase(
|
||||
new MsSqlTestcontainerConfiguration {Database = "sql_test_db", Password = "localpassword#123uuuuu"})
|
||||
new MsSqlTestcontainerConfiguration
|
||||
{
|
||||
Database = Guid.NewGuid().ToString("D"), Password = Guid.NewGuid().ToString("D")
|
||||
})
|
||||
.WithImage("mcr.microsoft.com/mssql/server:2017-latest")
|
||||
.WithCleanUp(true)
|
||||
.Build();
|
||||
|
||||
public static MsSqlTestcontainer SqlPersistTestContainer => new TestcontainersBuilder<MsSqlTestcontainer>()
|
||||
.WithDatabase(new MsSqlTestcontainerConfiguration
|
||||
{
|
||||
Database = "sql_test_persist_db", Password = "localpassword#123oooo"
|
||||
Database = Guid.NewGuid().ToString("D"), Password = Guid.NewGuid().ToString("D")
|
||||
})
|
||||
.WithImage("mcr.microsoft.com/mssql/server:2017-latest")
|
||||
.WithCleanUp(true)
|
||||
.Build();
|
||||
|
||||
public static MongoDbTestcontainer MongoTestContainer => new TestcontainersBuilder<MongoDbTestcontainer>()
|
||||
.WithDatabase(new MongoDbTestcontainerConfiguration()
|
||||
{
|
||||
Database = "mongo_test_db", Username = "mongo_db", Password = "mongo_db_pass"
|
||||
Database = Guid.NewGuid().ToString("D"),
|
||||
Username = Guid.NewGuid().ToString("D"),
|
||||
Password = Guid.NewGuid().ToString("D")
|
||||
})
|
||||
.WithImage("mongo")
|
||||
.WithCleanUp(true)
|
||||
.Build();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user