using System; using System.Linq; using Xunit; using ytLive.Models; using ytLive.Services; using ytLive.ViewModels; namespace ytLive.Tests; /// /// A scene switch in edit mode raises the preview transition with the chosen type and /// length, before the staged scene changes, so the preview can animate the old picture. /// [Collection("RealApp")] public sealed class PreviewTransitionTests { private readonly RealAppHost _app; public PreviewTransitionTests(RealAppHost app) => _app = app; [Fact] public void Scene_Switch_In_Edit_Mode_Raises_The_Preview_Transition_Before_The_Switch() { _app.Run(Run); } private static void Run() { var tempDb = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"ytLlive-preview-{Guid.NewGuid():N}.db"); MainViewModel.LayoutPathOverride = tempDb; try { using (var schema = new LayoutStore(tempDb)) { } Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools(); var vm = new MainViewModel(); var from = vm.StagedScene!; var to = vm.Scenes.First(s => s != from && !s.IsHidden); vm.SelectedTransitionType = TransitionType.Fade; vm.TransitionDurationMs = 800; Scene? stagedWhenRaised = null; TransitionType? typeRaised = null; double? msRaised = null; vm.PreviewTransition += (type, ms) => { stagedWhenRaised = vm.StagedScene; typeRaised = type; msRaised = ms; }; vm.TransitionToScene(to); Assert.Same(from, stagedWhenRaised); Assert.Equal(TransitionType.Fade, typeRaised); Assert.Equal(800, msRaised); Assert.Same(to, vm.StagedScene); } finally { MainViewModel.LayoutPathOverride = null; Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools(); try { System.IO.File.Delete(tempDb); } catch { } } } }