Files
vegasco/tests/Vegasco.Server.Api.Tests.Integration/PostgresRespawner.cs
ThompsonNye a1999bfe41
All checks were successful
continuous-integration/drone/push Build is passing
Rename WebApi project to Vegasco.Server.Api
And update all references including comments etc.
2025-06-12 18:23:09 +02:00

41 lines
938 B
C#

using Npgsql;
using Respawn;
using System.Data.Common;
namespace Vegasco.Server.Api.Tests.Integration;
internal sealed class PostgresRespawner : IDisposable
{
private readonly DbConnection _connection;
private readonly Respawner _respawner;
private PostgresRespawner(Respawner respawner, DbConnection connection)
{
_respawner = respawner;
_connection = connection;
}
public static async Task<PostgresRespawner> CreateAsync(string connectionString)
{
DbConnection connection = new NpgsqlConnection(connectionString);
await connection.OpenAsync();
var respawner = await Respawner.CreateAsync(connection,
new RespawnerOptions
{
SchemasToInclude = ["public"],
DbAdapter = DbAdapter.Postgres
});
return new PostgresRespawner(respawner, connection);
}
public async Task ResetDatabaseAsync()
{
await _respawner.ResetAsync(_connection);
}
public void Dispose()
{
_connection.Dispose();
}
}