Add integration tests

This commit is contained in:
2024-08-17 16:38:40 +02:00
parent ff2da66a22
commit 19b105b0e8
14 changed files with 583 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
using Npgsql;
using Respawn;
using System.Data.Common;
namespace WebApi.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();
}
}