Files
ytLlive/ytLive.Tests/LayoutStorePersistenceTests.cs
T

51 lines
1.4 KiB
C#

using System;
using System.IO;
using Microsoft.Data.Sqlite;
using Xunit;
using ytLive.Models;
using ytLive.Services;
namespace ytLive.Tests;
/// <summary>
/// The layout DB is a full rewrite on every save (DELETE all scenes/sources,
/// re-insert from memory). This guards the round trip: sources the user deletes
/// in the UI must not come back after a save + reload.
/// </summary>
public class LayoutStorePersistenceTests
{
[Fact]
public void Deleted_Webcam_Source_Does_Not_Return_After_Save_And_Reload()
{
var path = Path.Combine(Path.GetTempPath(), $"ytLlive-layout-{Guid.NewGuid():N}.db");
try
{
using var store = new LayoutStore(path);
var scene = new Scene { Name = "Starting" };
scene.Sources.Add(new Source
{
Name = "Webcam",
Type = SourceType.Webcam,
DeviceId = "real-device",
Width = 480,
Height = 270,
});
store.Save(new[] { scene });
var reloaded = store.Load();
Assert.Single(reloaded[0].Sources);
reloaded[0].Sources.RemoveAt(0);
store.Save(reloaded);
var afterDelete = store.Load();
Assert.Empty(afterDelete[0].Sources);
}
finally
{
SqliteConnection.ClearAllPools();
try { File.Delete(path); } catch { /* best-effort cleanup */ }
}
}
}