Files
Flypaper/test/Flypaper.Tests/Storage/MigrationTests.cs
T
2026-11-14 16:08:45 +01:00

37 lines
1.3 KiB
C#

using Flypaper.Storage;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Shouldly;
namespace Flypaper.Tests.Storage;
public sealed class MigrationTests : IDisposable
{
private readonly string _dbPath = Path.Combine(Path.GetTempPath(), $"flypaper-migration-{Guid.NewGuid():N}.db");
[Fact]
public async Task Removes_obsolete_drip_interval_override_from_existing_databases()
{
await using var db = new FlypaperDbContext(new DbContextOptionsBuilder<FlypaperDbContext>().UseSqlite($"Data Source={_dbPath}").Options);
var migrator = db.GetService<IMigrator>();
await migrator.MigrateAsync("AddOrigin");
await db.Database.ExecuteSqlRawAsync(
"INSERT INTO \"Settings\" (\"Key\", \"Value\") VALUES ('Flypaper:Drip:Interval', '00:00:10'), ('Flypaper:MaxConnections', '50')");
await db.Database.MigrateAsync();
(await db.Settings.Select(s => s.Key).ToListAsync()).ShouldBe(["Flypaper:MaxConnections"]);
}
public void Dispose()
{
SqliteConnection.ClearAllPools();
foreach (var suffix in new[] { "", "-wal", "-shm" })
{
File.Delete(_dbPath + suffix);
}
}
}