Files
ytLlive/ytLive.Tests/SceneAccessPolicyTests.cs
T

68 lines
2.3 KiB
C#

using System.Linq;
using Xunit;
using ytLive.Models;
using ytLive.Services;
namespace ytLive.Tests;
/// <summary>
/// The per-scene source access matrix from the source catalog (TASKS.md).
/// One integration test: each canonical scene allows exactly its matrix set,
/// nothing more; non-canonical scenes allow nothing.
/// </summary>
public class SceneAccessPolicyTests
{
private static readonly SourceType[] All =
{
SourceType.DisplayCapture, SourceType.WindowCapture, SourceType.Background,
SourceType.Image, SourceType.TextOverlay, SourceType.Chatbox,
SourceType.Alerts, SourceType.Socials,
};
[Fact]
public void SceneAccessPolicy_Enforces_The_Full_Access_Matrix()
{
var allowed = new[]
{
(Scene: "Starting", Types: new[]
{
SourceType.Background, SourceType.Image, SourceType.TextOverlay,
SourceType.Alerts, SourceType.Socials,
}),
(Scene: "Live", Types: All),
(Scene: "BRB", Types: new[]
{
SourceType.Background, SourceType.Image, SourceType.TextOverlay,
SourceType.Chatbox, SourceType.Alerts, SourceType.Socials,
}),
(Scene: "Chat", Types: new[]
{
SourceType.Background, SourceType.Image, SourceType.TextOverlay,
SourceType.Chatbox, SourceType.Alerts, SourceType.Socials,
}),
(Scene: "Ending", Types: new[]
{
SourceType.Background, SourceType.Image, SourceType.TextOverlay,
SourceType.Alerts, SourceType.Socials,
}),
};
foreach (var (scene, types) in allowed)
{
foreach (var type in types)
Assert.True(
SceneAccessPolicy.Allows(scene, type),
$"{type} should be allowed in {scene}");
foreach (var type in All.Where(t => !types.Contains(t)))
Assert.False(
SceneAccessPolicy.Allows(scene, type),
$"{type} should NOT be allowed in {scene}");
}
Assert.False(SceneAccessPolicy.Allows(null, SourceType.Image));
Assert.False(SceneAccessPolicy.Allows("My Scene", SourceType.Image));
Assert.False(SceneAccessPolicy.Allows(" ", SourceType.TextOverlay));
}
}