using System.Text.Json;
using System.Text.Json.Nodes;
using GerbilManagerWebAPI.Import;
using GerbilManagerWebAPI.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace GerbilManager.Tests
{
///
/// Regression tests for the "Freeze/Override" mechanism (verified key animals + manual work
/// survive the re-ingest). Exercised at the service + ingest level with an InMemory DB, mirroring
/// the harness in .
///
public class VerifiedGerbilTests : IDisposable
{
private static readonly Guid Schwarz = new("00000000-0000-0000-0000-000000000006");
private readonly List _dirs = new();
public void Dispose()
{
foreach (var d in _dirs)
try { Directory.Delete(d, recursive: true); } catch { }
}
// ── Harness helpers ──────────────────────────────────────────────────
private string NewDir()
{
var dir = Path.Combine(Path.GetTempPath(), "verified-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
_dirs.Add(dir);
return dir;
}
private static ApplicationContext NewDb()
{
var opts = new DbContextOptionsBuilder()
.UseInMemoryDatabase("verified-" + Guid.NewGuid().ToString("N"))
.Options;
var db = new ApplicationContext(opts);
db.Database.EnsureCreated();
return db;
}
private static IngestResolvedService Service(ApplicationContext db, string dir)
{
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary
{
{ "Import:SourcePath", dir },
{ "Photos:RootPath", dir },
})
.Build();
return new IngestResolvedService(db, config, null!);
}
private static void WritePayload(string dir, object[] gerbils, object[]? litters = null, object[]? contacts = null) =>
File.WriteAllText(Path.Combine(dir, "resolved_import.json"), JsonSerializer.Serialize(new
{
Contacts = contacts ?? Array.Empty