111 lines
4.5 KiB
C#
111 lines
4.5 KiB
C#
using Xunit;
|
|
using ytLive.Models;
|
|
using ytLive.ViewModels;
|
|
|
|
namespace ytLive.Tests;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
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", true)]
|
|
[InlineData("Live", true)]
|
|
[InlineData("BRB", true)]
|
|
[InlineData("Chat", true)]
|
|
[InlineData("Ending", true)]
|
|
public void SceneCatalog_HasBackground_For_All_Canonical_Scenes(string name, bool expected)
|
|
{
|
|
Assert.Equal(expected, SceneCatalog.HasBackground(name));
|
|
}
|
|
|
|
[Fact]
|
|
public void NormalizeBackgrounds_Heals_Dirty_Layouts_To_The_Locked_Model()
|
|
{
|
|
// Pre-TASK-25 rot: static Background + stray Game Capture duplicates,
|
|
// wrong names, wrong z-order, stale flags on non-canonical scenes.
|
|
var starting = new Scene { Name = "Starting", HasBackground = false };
|
|
var image = new Source { Name = "Image 1", Type = SourceType.Image };
|
|
starting.Elements.Add(new Source { Name = "Background", Type = SourceType.Background, IsBackground = true, Width = 10 });
|
|
starting.Elements.Add(image);
|
|
starting.Elements.Add(new Source { Name = "Game Capture", Type = SourceType.DisplayCapture, IsBackground = true });
|
|
|
|
var live = new Scene { Name = "Live", HasBackground = false };
|
|
live.Elements.Add(new Source { Name = "Game Capture", Type = SourceType.Background, IsBackground = true });
|
|
|
|
MainViewModel.NormalizeBackgrounds(new[] { starting, live });
|
|
|
|
Assert.True(starting.HasBackground);
|
|
var startingBackgrounds = starting.Elements.OfType<Source>().Where(s => s.IsBackground).ToList();
|
|
var kept = Assert.Single(startingBackgrounds);
|
|
Assert.Equal("Background", kept.Name);
|
|
Assert.Equal(SourceType.Background, kept.Type); // correct flavor preferred over the stray capture row
|
|
Assert.Same(image, starting.Elements[1]); // regular layers untouched
|
|
Assert.Equal(0, starting.Elements.IndexOf(kept));
|
|
|
|
Assert.True(live.HasBackground);
|
|
var liveKept = Assert.Single(live.Elements.OfType<Source>(), s => s.IsBackground);
|
|
Assert.Equal("Background", liveKept.Name);
|
|
Assert.Equal(SourceType.DisplayCapture, liveKept.Type); // flavor corrected to capture
|
|
Assert.Equal(0, live.Elements.IndexOf(liveKept));
|
|
}
|
|
|
|
[Fact]
|
|
public void NormalizeBackgrounds_Strips_Backgrounds_From_NonCanonical_Scenes()
|
|
{
|
|
var custom = new Scene { Name = "My Scene", HasBackground = true };
|
|
custom.Elements.Add(new Source { Name = "Background", Type = SourceType.Background, IsBackground = true });
|
|
var layer = new Source { Name = "Image 1", Type = SourceType.Image };
|
|
custom.Elements.Add(layer);
|
|
|
|
MainViewModel.NormalizeBackgrounds(new[] { custom });
|
|
|
|
Assert.False(custom.HasBackground);
|
|
Assert.DoesNotContain(custom.Elements, e => e is Source { IsBackground: true });
|
|
Assert.Contains(custom.Elements, e => ReferenceEquals(e, layer));
|
|
}
|
|
|
|
[Fact]
|
|
public void EnsureBackground_Seeds_The_Right_Flavor_Per_Scene()
|
|
{
|
|
var starting = new Scene { Name = "Starting", HasBackground = true };
|
|
var startingBackground = MainViewModel.EnsureBackground(starting)!;
|
|
Assert.Equal(SourceType.Background, startingBackground.Type);
|
|
Assert.Equal("Background", startingBackground.Name);
|
|
|
|
var live = new Scene { Name = "Live", HasBackground = true };
|
|
var liveBackground = MainViewModel.EnsureBackground(live)!;
|
|
Assert.Equal(SourceType.DisplayCapture, liveBackground.Type);
|
|
|
|
var noBackgroundScene = new Scene { Name = "My Scene", HasBackground = false };
|
|
Assert.Null(MainViewModel.EnsureBackground(noBackgroundScene));
|
|
Assert.Empty(noBackgroundScene.Elements);
|
|
}
|
|
}
|