Files
h-school/tests/HSchool.Content.Tests/EventDefTests.cs
T
Leonid Pershin 9e429d0cd7 Show director summons as info toasts and presence queue labels.
Corridor waiters need a summon-phase byte on presence (v11); EventDef DirectorSummoned is info-only so clocks keep running.
2026-08-21 13:07:47 +03:00

89 lines
4.2 KiB
C#

using HSchool.Content;
namespace HSchool.Content.Tests;
public class EventDefTests
{
private readonly CatalogLoader _loader = new();
[Fact]
public void VanillaCore_LoadsDayAndLessonStarted()
{
var catalog = LoadVanilla();
Assert.True(catalog.Events.ContainsKey("DayStarted"));
Assert.Equal(EventSeverities.Info, catalog.Events["DayStarted"].Severity);
Assert.False(catalog.Events["DayStarted"].Pause);
Assert.Equal(8000, catalog.Events["DayStarted"].TtlMs);
Assert.Equal(EventTriggers.DayStart, catalog.Events["DayStarted"].Trigger);
Assert.Equal(EventActions.None, catalog.Events["DayStarted"].Action);
Assert.True(catalog.Events.ContainsKey("LessonStarted"));
Assert.Equal(EventSeverities.Info, catalog.Events["LessonStarted"].Severity);
Assert.False(catalog.Events["LessonStarted"].Pause);
Assert.Equal(8000, catalog.Events["LessonStarted"].TtlMs);
Assert.Equal(EventTriggers.LessonStart, catalog.Events["LessonStarted"].Trigger);
Assert.Equal(EventActions.None, catalog.Events["LessonStarted"].Action);
Assert.True(catalog.Events.ContainsKey("GenerationFailed"));
Assert.Equal(EventSeverities.Error, catalog.Events["GenerationFailed"].Severity);
Assert.True(catalog.Events["GenerationFailed"].Pause);
Assert.Equal(0, catalog.Events["GenerationFailed"].TtlMs);
Assert.Equal(EventTriggers.GenerationFailed, catalog.Events["GenerationFailed"].Trigger);
Assert.Equal(EventActions.GenerateImage, catalog.Events["GenerationFailed"].Action);
Assert.Equal("Начало дня", catalog.Label("ru", catalog.Events["DayStarted"]));
Assert.Equal("The day has started", catalog.Label("en", catalog.Events["DayStarted"]));
Assert.True(catalog.Events.ContainsKey("DirectorSummoned"));
Assert.Equal(EventSeverities.Info, catalog.Events["DirectorSummoned"].Severity);
Assert.False(catalog.Events["DirectorSummoned"].Pause);
Assert.Equal(8000, catalog.Events["DirectorSummoned"].TtlMs);
Assert.Equal(EventTriggers.DirectorSummon, catalog.Events["DirectorSummoned"].Trigger);
Assert.Equal(EventActions.None, catalog.Events["DirectorSummoned"].Action);
Assert.Equal("Ученика вызвали к директору", catalog.Label("ru", catalog.Events["DirectorSummoned"]));
Assert.Equal("A pupil was summoned to the principal", catalog.Label("en", catalog.Events["DirectorSummoned"]));
}
[Fact]
public void UnknownTrigger_FailsTheCatalog()
{
var documents = PackDocuments.FromDirectory(
CatalogLoader.CorePackId,
Path.Combine(AppContext.BaseDirectory, "vanilla"))
.Append(PackDocuments.Def(
CatalogLoader.CorePackId,
"events",
"bad",
"""{ "defName": "BadMoon", "severity": "info", "ttlMs": 1, "trigger": "fullMoon", "action": "none" }"""))
.ToList();
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load([CatalogLoader.CorePackId], documents));
Assert.Contains("trigger", ex.Message, StringComparison.Ordinal);
Assert.Contains("fullMoon", ex.Message, StringComparison.Ordinal);
}
[Fact]
public void UnknownAction_FailsTheCatalog()
{
var documents = PackDocuments.FromDirectory(
CatalogLoader.CorePackId,
Path.Combine(AppContext.BaseDirectory, "vanilla"))
.Append(PackDocuments.Def(
CatalogLoader.CorePackId,
"events",
"bad-action",
"""{ "defName": "BadAct", "severity": "info", "ttlMs": 1, "trigger": "dayStart", "action": "teleport" }"""))
.ToList();
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load([CatalogLoader.CorePackId], documents));
Assert.Contains("action", ex.Message, StringComparison.Ordinal);
Assert.Contains("teleport", ex.Message, StringComparison.Ordinal);
}
private DefCatalog LoadVanilla()
{
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
return _loader.Load([CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
}
}