Bifrost/tests/Bifrost.Web.Tests/SnapshotDriftTests.cs
Heimdall ee700d4931 Test: snapshot has no drift from the design-time model (passes at base 425af74)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 02:20:25 +00:00

28 lines
1.2 KiB
C#

using Bifrost.Web.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.DependencyInjection;
namespace Bifrost.Web.Tests;
public sealed class SnapshotDriftTests
{
// Migrations here are hand-written with a hand-edited snapshot, so the snapshot is compared with the model the app runs on:
// a column or index the model has and the snapshot lacks would never reach a database.
[Fact]
public void The_model_snapshot_has_no_drift_from_the_design_time_model()
{
using var db = new BifrostDbContext(new DbContextOptionsBuilder<BifrostDbContext>().UseNpgsql("Host=unused").Options);
var snapshotModel = db.GetService<IMigrationsAssembly>().ModelSnapshot!.Model;
var designModel = db.GetService<IDesignTimeModel>().Model;
var differ = db.GetService<IMigrationsModelDiffer>();
var differences = differ.GetDifferences(
db.GetService<IModelRuntimeInitializer>().Initialize(snapshotModel).GetRelationalModel(),
designModel.GetRelationalModel());
Assert.Empty(differences.Select(x => x.GetType().Name + ": " + x));
}
}