Hermetic real-MainWindow tests: LayoutPathOverride temp-DB seam (InternalsVisibleTo); fix tests persisting fake webcam sources over the real layout DB; LayoutStore delete-roundtrip guard
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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 */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Xunit;
|
||||
using ytLive.Models;
|
||||
using ytLive.ViewModels;
|
||||
@@ -47,6 +48,11 @@ public sealed class RoundClipInteractionTests
|
||||
var app = new App();
|
||||
app.InitializeComponent();
|
||||
|
||||
// Never let the real MainWindow read/write the user's actual layout DB —
|
||||
// Shutdown() saves the layout, which would persist these test sources
|
||||
// over the real ones. Point it at a throwaway temp DB instead.
|
||||
var tempDb = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"ytLlive-test-{Guid.NewGuid():N}.db");
|
||||
MainViewModel.LayoutPathOverride = tempDb;
|
||||
var window = new MainWindow();
|
||||
var vm = (MainViewModel)window.DataContext;
|
||||
try
|
||||
@@ -103,6 +109,9 @@ public sealed class RoundClipInteractionTests
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
MainViewModel.LayoutPathOverride = null;
|
||||
SqliteConnection.ClearAllPools();
|
||||
try { System.IO.File.Delete(tempDb); } catch { /* best-effort cleanup */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user