mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-10 22:24:14 -04:00
fix(test): own and close private server database before cleanup
This commit is contained in:
1 parent
4d94273a00
commit
648ffbca65
1 file changed
+4
-1
@@ -15,6 +15,7 @@ namespace OpenNest.Server.Tests;
|
||||
public sealed class ServerFactory : WebApplicationFactory<global::Program>
|
||||
{
|
||||
private bool _cleanedUp;
|
||||
private NestDatabase? _database;
|
||||
|
||||
public ServerFactory(string? databasePath = null)
|
||||
{
|
||||
@@ -33,7 +34,8 @@ public sealed class ServerFactory : WebApplicationFactory<global::Program>
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
services.RemoveAll<NestDatabase>();
|
||||
services.AddSingleton(_ => new NestDatabase(DatabasePath, pooling: false));
|
||||
// Register an externally owned instance; this factory closes it before deleting its file.
|
||||
services.AddSingleton(_database = new NestDatabase(DatabasePath, pooling: false));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,6 +46,7 @@ public sealed class ServerFactory : WebApplicationFactory<global::Program>
|
||||
return;
|
||||
|
||||
_cleanedUp = true;
|
||||
_database?.Dispose();
|
||||
if (Directory.Exists(DirectoryPath))
|
||||
Directory.Delete(DirectoryPath, recursive: true);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user