using Xunit; using ytLive.Models; using ytLive.ViewModels; namespace ytLive.Tests; /// /// The app is a five-scene product: Starting/Live/BRB/Chat/Ending. Scenes are /// worked on by name; you can delete them but never add beyond the set, and the /// live background belongs to Live alone. /// public class SceneCatalogTests { [Fact] public void SceneCatalog_Defines_The_Five_Canonical_Scenes() { Assert.Equal( new[] { "Starting", "Live", "BRB", "Chat", "Ending" }, SceneCatalog.All); } [Theory] [InlineData("Starting", true)] [InlineData("Live", true)] [InlineData("BRB", true)] [InlineData("Chat", true)] [InlineData("Ending", true)] [InlineData("live", true)] [InlineData("My Scene", false)] [InlineData("", false)] [InlineData(null, false)] public void SceneCatalog_IsCanonical_Matches_By_Name(string? name, bool expected) { Assert.Equal(expected, SceneCatalog.IsCanonical(name)); } [Theory] [InlineData("Starting", false)] [InlineData("Live", true)] [InlineData("BRB", false)] [InlineData("Chat", false)] [InlineData("Ending", false)] public void SceneCatalog_HasBackground_Only_For_Live(string name, bool expected) { Assert.Equal(expected, SceneCatalog.HasBackground(name)); } [Fact] public void EnforceBackgroundPolicy_Removes_Background_From_NonLive_Scenes() { var chat = new Scene { Name = "Chat", HasBackground = true }; var live = new Scene { Name = "Live", HasBackground = true }; var chatBackground = MainViewModel.EnsureBackground(chat)!; var liveBackground = MainViewModel.EnsureBackground(live)!; Assert.Contains(chat.Elements, e => ReferenceEquals(e, chatBackground)); MainViewModel.EnforceBackgroundPolicy(new[] { chat, live }); Assert.False(chat.HasBackground); Assert.DoesNotContain(chat.Elements, e => e is Source { IsBackground: true }); Assert.True(live.HasBackground); Assert.Contains(live.Elements, e => ReferenceEquals(e, liveBackground)); } [Fact] public void EnforceBackgroundPolicy_Marks_Live_And_Clears_A_Pre_Policy_Database() { var starting = new Scene { Name = "Starting", HasBackground = true }; MainViewModel.EnsureBackground(starting); var live = new Scene { Name = "Live", HasBackground = false }; MainViewModel.EnforceBackgroundPolicy(new[] { starting, live }); Assert.False(starting.HasBackground); Assert.True(live.HasBackground); } }