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