Happy flow for creating realms works
But needs more validating...
This commit is contained in:
parent
f99c97f392
commit
92b34bd0b5
25 changed files with 437 additions and 12 deletions
70
IdentityShroud.Core.Tests/Fixtures/DbFixture.cs
Normal file
70
IdentityShroud.Core.Tests/Fixtures/DbFixture.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
using DotNet.Testcontainers.Containers;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Npgsql;
|
||||
using Testcontainers.PostgreSql;
|
||||
|
||||
namespace IdentityShroud.Core.Tests.Fixtures;
|
||||
|
||||
public class DbFixture : IAsyncLifetime
|
||||
{
|
||||
private readonly IContainer _postgresqlServer;
|
||||
|
||||
private string ConnectionString =>
|
||||
$"Host={_postgresqlServer.Hostname};" +
|
||||
$"Port={DbPort};" +
|
||||
$"Username={Username};Password={Password}";
|
||||
|
||||
private string Username => "postgres";
|
||||
private string Password => "password";
|
||||
private string DbHostname => _postgresqlServer.Hostname;
|
||||
private int DbPort => _postgresqlServer.GetMappedPublicPort(PostgreSqlBuilder.PostgreSqlPort);
|
||||
|
||||
public Db CreateDbContext(string dbName)
|
||||
{
|
||||
var db = new Db(Options.Create<DbConfiguration>(new()
|
||||
{
|
||||
ConnectionString = ConnectionString + ";Database=" + dbName,
|
||||
LogSensitiveData = false,
|
||||
}), new NullLoggerFactory());
|
||||
return db;
|
||||
}
|
||||
|
||||
public DbFixture()
|
||||
{
|
||||
_postgresqlServer = new PostgreSqlBuilder("postgres:18.1")
|
||||
.WithName("KMS-Test-Infra-" + Guid.NewGuid().ToString("D"))
|
||||
.WithPassword(Password)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await _postgresqlServer.StopAsync();
|
||||
}
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
await _postgresqlServer.StartAsync();
|
||||
}
|
||||
|
||||
public NpgsqlConnection GetConnection(string dbname)
|
||||
{
|
||||
string connString = ConnectionString
|
||||
+ $";Database={dbname}";
|
||||
var connection = new NpgsqlConnection(connString);
|
||||
connection.Open();
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
[CollectionDefinition("PostgresqlFixtureCollection", DisableParallelization = false)]
|
||||
public class PostgresqlFactoryCollection : ICollectionFixture<PostgresqlFixture>
|
||||
{
|
||||
// This class has no code, and is never created. Its purpose is simply
|
||||
// to be the place to apply [CollectionDefinition] and all the
|
||||
// ICollectionFixture<> interfaces.
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue