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.None, catalog.Events["GenerationFailed"].Action); Assert.Equal("Начало дня", catalog.Label("ru", catalog.Events["DayStarted"])); Assert.Equal("The day has started", catalog.Label("en", catalog.Events["DayStarted"])); } [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(() => _loader.Load([CatalogLoader.CorePackId], documents)); Assert.Contains("trigger", ex.Message, StringComparison.Ordinal); Assert.Contains("fullMoon", ex.Message, StringComparison.Ordinal); } private DefCatalog LoadVanilla() { var root = Path.Combine(AppContext.BaseDirectory, "vanilla"); return _loader.Load([CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root)); } }