Lesson multipliers stay explicit in tests; poor marks and unexcused absences toast and may auto-summon, while illness stays excused.
95 lines
4.7 KiB
C#
95 lines
4.7 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"]));
|
|
|
|
Assert.True(catalog.Events.ContainsKey("PoorGradeTrail"));
|
|
Assert.Equal(EventSeverities.Info, catalog.Events["PoorGradeTrail"].Severity);
|
|
Assert.Equal(EventTriggers.PoorGradeTrail, catalog.Events["PoorGradeTrail"].Trigger);
|
|
Assert.Equal("Слабый учебный след у ученика", catalog.Label("ru", catalog.Events["PoorGradeTrail"]));
|
|
Assert.Equal("A pupil has a weak grade trail", catalog.Label("en", catalog.Events["PoorGradeTrail"]));
|
|
}
|
|
|
|
[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));
|
|
}
|
|
}
|