From e97aac505d9ff3ceec31b11e9cbd093590bf514f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 06:37:00 +0000 Subject: [PATCH 1/2] Initial plan From 64eeaff49279a87b8b6e190094124de142681083 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 06:48:07 +0000 Subject: [PATCH 2/2] Update Respawn package and migrate from Checkpoint to Respawner API Co-authored-by: mitchelsellers <5659113+mitchelsellers@users.noreply.github.com> --- .../DatabaseFixture.cs | 24 ++++++++++++------- .../NetCore.Utilities.UnitTesting.csproj | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/NetCore.Utilities.UnitTesting/DatabaseFixture.cs b/src/NetCore.Utilities.UnitTesting/DatabaseFixture.cs index 365bb33..5512fcd 100644 --- a/src/NetCore.Utilities.UnitTesting/DatabaseFixture.cs +++ b/src/NetCore.Utilities.UnitTesting/DatabaseFixture.cs @@ -131,9 +131,9 @@ public abstract class DatabaseFixture where TContext : DbContext { /// - /// The Checkpoint information used by Respawn to clear the database between test runs + /// The Respawner information used by Respawn to clear the database between test runs /// - private readonly Checkpoint _checkpoint; + private Respawner? _respawner; /// /// Options used for creating all database contexts handed out by this fixture. @@ -142,6 +142,7 @@ public abstract class DatabaseFixture private WeakReference _outputHelper = new(null!); private readonly DatabaseFixtureLoggingSettings _logSettings; + private readonly RespawnerOptions _respawnerOptions; /// /// Creates an instance of the database fixture. Not normally called by testing code, the lifetime of this class is expected to be managed by xUnit. @@ -151,8 +152,8 @@ public abstract class DatabaseFixture /// An action to set up the DbContextOptions used to create the context. If null, it will default to using Sql Server with the connection /// string provided by the parameter. /// - /// - /// A function returning a object. If null, a default configuration + /// + /// A function returning a object. If null, a default configuration /// that ignores the EF migrations table will be used. /// /// @@ -163,7 +164,7 @@ public abstract class DatabaseFixture protected DatabaseFixture( string connectionString, Action>? contextOptionsAction = null, - Func? checkpointFunc = null, + Func? respawnerOptionsFunc = null, DatabaseFixtureLoggingSettings? logging = null) { var optionsBuilder = new DbContextOptionsBuilder(); @@ -192,9 +193,9 @@ protected DatabaseFixture( throw new InvalidOperationException($"The DbContext type used by the database fixture must have a public constructor that takes a DbContextOptions."); } - if (checkpointFunc == null) + if (respawnerOptionsFunc == null) { - _checkpoint = new Checkpoint() + _respawnerOptions = new RespawnerOptions { TablesToIgnore = new Table[] { "__EFMigrationsHistory" }, DbAdapter = DbAdapter.SqlServer @@ -202,7 +203,7 @@ protected DatabaseFixture( } else { - _checkpoint = checkpointFunc(); + _respawnerOptions = respawnerOptionsFunc(); } } @@ -290,7 +291,12 @@ public async Task Reset() if (conn.State == ConnectionState.Closed) await conn.OpenAsync(); - await _checkpoint.Reset(conn); + if (_respawner == null) + { + _respawner = await Respawner.CreateAsync(conn, _respawnerOptions); + } + + await _respawner.ResetAsync(conn); } /// diff --git a/src/NetCore.Utilities.UnitTesting/NetCore.Utilities.UnitTesting.csproj b/src/NetCore.Utilities.UnitTesting/NetCore.Utilities.UnitTesting.csproj index 01189a4..5efde2d 100644 --- a/src/NetCore.Utilities.UnitTesting/NetCore.Utilities.UnitTesting.csproj +++ b/src/NetCore.Utilities.UnitTesting/NetCore.Utilities.UnitTesting.csproj @@ -38,7 +38,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - +