34 lines
873 B
C#
34 lines
873 B
C#
using Jellyfin.Plugin.Herald.Storage;
|
|
using Microsoft.Data.Sqlite;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
namespace Jellyfin.Plugin.Herald.Tests;
|
|
|
|
/// <summary>
|
|
/// A database in a throwaway directory.
|
|
/// </summary>
|
|
public sealed class TempDatabase : IDisposable
|
|
{
|
|
private readonly string _directory = Path.Combine(Path.GetTempPath(), "herald-tests-" + Guid.NewGuid().ToString("N"));
|
|
|
|
public TempDatabase()
|
|
{
|
|
Database = Open();
|
|
}
|
|
|
|
public HeraldDatabase Database { get; }
|
|
|
|
public string FilePath => Path.Combine(_directory, "nested", "herald.db");
|
|
|
|
public HeraldDatabase Open() => new(FilePath, NullLogger<HeraldDatabase>.Instance);
|
|
|
|
public void Dispose()
|
|
{
|
|
SqliteConnection.ClearAllPools();
|
|
if (Directory.Exists(_directory))
|
|
{
|
|
Directory.Delete(_directory, true);
|
|
}
|
|
}
|
|
}
|