namespace HSchool.People.Tests; internal static class PackDocuments { public static IReadOnlyList FromDirectory(string packId, string packRoot) { var documents = new List(); foreach (var path in Directory.EnumerateFiles(packRoot, "*.*", SearchOption.AllDirectories)) { if (!path.EndsWith(".jsonc", StringComparison.OrdinalIgnoreCase) && !path.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { continue; } var relative = Path.GetRelativePath(packRoot, path).Replace('\\', '/'); documents.Add(new ContentDocument(packId, relative, File.ReadAllText(path))); } return documents; } } internal static class Fixtures { public static readonly DateTime AsOf = RosterGenerator.DefaultAsOf; public const int SchoolSeed = 20260818; public static DefCatalog Catalog() { var root = Path.Combine(AppContext.BaseDirectory, "vanilla"); return new CatalogLoader().Load( [CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root)); } public static MapLayout Classrooms(int count, int desks = 16) { var rooms = new RoomNode[count]; for (var i = 0; i < count; i++) { rooms[i] = new RoomNode { Id = $"classroom-{i:00}", Def = "Classroom", Building = "main", Floor = "floor-1", Label = $"{101 + i}", Seats = desks, }; } return new MapLayout { Rooms = rooms }; } /// /// One tiny class and five posts: the pupils' parents cannot fill them, so the generator has /// to top the staff up, and the deficit is odd on purpose. /// public static MapLayout PostHeavyMap() { var rooms = new List { new() { Id = "classroom-00", Def = "Classroom", Building = "main", Floor = "floor-1", Label = "101", Seats = 1, }, }; foreach (var def in new[] { "PrincipalsOffice", "SecretaryOffice", "Library", "MedicalOffice" }) { rooms.Add(new RoomNode { Id = def, Def = def, Building = "main", Floor = "floor-1" }); } return new MapLayout { Rooms = rooms }; } public static MapLayout VanillaMap() { var root = Path.Combine(AppContext.BaseDirectory, "vanilla"); var map = CatalogLoader.LastDefaultMap( [CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root)); if (map is null) { throw new InvalidOperationException("Vanilla default map is missing."); } return map; } public static Roster Generate(MapLayout map, int seed = SchoolSeed) => RosterGenerator.Generate(Catalog(), map, seed, "Slavic", AsOf, "RussianLanguage"); public static string RepoRoot() { var dir = new DirectoryInfo(AppContext.BaseDirectory); while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "h-school.sln"))) { dir = dir.Parent; } if (dir is null) { throw new InvalidOperationException("Could not find h-school.sln from the test output directory."); } return dir.FullName; } }