Files
vigilcare-clinical/VigilCareClinicalAPI.Tests/Helpers/DbResetHelper.cs
T

29 lines
1011 B
C#

using Microsoft.EntityFrameworkCore;
public static class DbResetHelper
{
// Truncate all data between tests — faster than dropping and re-creating
// the database, and preserves the schema (migrations do not re-run).
public static async Task ResetAsync(AppDbContext db)
{
for (var attempt = 0; ; attempt++)
{
try
{
await db.Database.ExecuteSqlRawAsync(@"
SET lock_timeout = '3s';
TRUNCATE TABLE sepsis_bundle_elements, sepsis_bundles,
reconciliation_alerts, outbox_events, orders,
clinical_alerts, news2_scores, observations, encounters,
alert_thresholds, patients
RESTART IDENTITY CASCADE;
");
return;
}
catch when (attempt < 5)
{
await Task.Delay(1000);
}
}
}
}