namespace HSchool.Content.Tests;
///
/// The shipped mods/example folder, copied next to vanilla core. Last-wins, patches and a
/// placeable room have to work from disk — in-memory documents already have their own tests.
///
public class ExamplePackTests
{
private const string ExamplePackId = "example";
private readonly CatalogLoader _loader = new();
[Fact]
public void DuplicateChair_LastWinsAndWarns()
{
var log = new RecordingLog();
var catalog = LoadCoreAndExample(log);
Assert.Equal(["Sit", "Chat"], catalog.Things["Chair"].Actions);
Assert.Contains(
log.Warnings,
warning => warning.Contains("Chair", StringComparison.Ordinal)
&& warning.Contains(ExamplePackId, StringComparison.Ordinal));
}
[Fact]
public void PatchAddsASlot_OnlyWhenThePackIsLoaded()
{
var vanilla = LoadCore();
Assert.DoesNotContain(vanilla.Rooms["PrincipalsOffice"].Slots, slot => slot.Key == "exampleLocker");
var withPack = LoadCoreAndExample();
Assert.Contains(withPack.Rooms["PrincipalsOffice"].Slots, slot => slot.Key == "exampleLocker" && slot.Thing == "Locker");
}
[Fact]
public void PackTypes_LoadWithLocalizedLabels()
{
var catalog = LoadCoreAndExample();
Assert.True(catalog.Traits.ContainsKey("ExampleEarlyRiser"));
Assert.True(catalog.Traits.ContainsKey("ExampleNightOwl"));
Assert.True(catalog.NameSets.ContainsKey("ExampleNames"));
Assert.True(catalog.Rooms.ContainsKey("ExampleStore"));
Assert.Equal("Кладовая", catalog.Label("ru", catalog.Rooms["ExampleStore"]));
Assert.Equal("Storeroom", catalog.Label("en", catalog.Rooms["ExampleStore"]));
Assert.Equal("Примерные имена", catalog.Label("ru", catalog.NameSets["ExampleNames"]));
Assert.Equal(["RussianLanguage"], catalog.NameSets["ExampleNames"].Spoken.ToArray());
Assert.True(catalog.Rooms.ContainsKey("PrincipalsOffice"));
Assert.Equal("Кабинет директора", catalog.Label("ru", catalog.Rooms["PrincipalsOffice"]));
}
[Fact]
public void MapUsingThePackRoom_PassesValidation()
{
var catalog = LoadCoreAndExample();
var map = new MapLayout
{
Territory = new TerritoryNode { Id = "yard", Def = "SchoolYard" },
Buildings = [new BuildingNode { Id = "main", Def = "MainBuilding" }],
Floors = [new FloorNode { Id = "floor-1", Def = "StandardFloor", Building = "main" }],
Rooms =
[
new RoomNode { Id = "store", Def = "ExampleStore", Building = "main", Floor = "floor-1" },
],
Links = [new MapLink { A = "yard", B = "store" }],
};
MapValidator.Validate(map, catalog);
var defaults = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId, ExamplePackId], Documents());
Assert.NotNull(defaults);
Assert.Equal("SchoolYard", defaults.Territory?.Def);
}
private DefCatalog LoadCore() =>
_loader.Load(
[CatalogLoader.CorePackId],
PackDocuments.FromDirectory(CatalogLoader.CorePackId, CoreRoot()));
private DefCatalog LoadCoreAndExample(IContentLog? log = null) =>
_loader.Load([CatalogLoader.CorePackId, ExamplePackId], Documents(), log);
private static IReadOnlyList Documents()
{
var example = ExampleRoot();
Assert.True(Directory.Exists(example), $"Example pack was not copied to {example}.");
return
[
.. PackDocuments.FromDirectory(CatalogLoader.CorePackId, CoreRoot()),
.. PackDocuments.FromDirectory(ExamplePackId, example),
];
}
private static string CoreRoot() => Path.Combine(AppContext.BaseDirectory, "vanilla");
private static string ExampleRoot() => Path.Combine(AppContext.BaseDirectory, "example");
}