Files
h-school/tests/HSchool.People.Tests/Fixtures.cs
T

106 lines
3.3 KiB
C#

namespace HSchool.People.Tests;
internal static class PackDocuments
{
public static IReadOnlyList<ContentDocument> FromDirectory(string packId, string packRoot)
{
var documents = new List<ContentDocument>();
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}",
Slots =
[
new SlotFill { Key = "studentDesks", Thing = "StudentDesk", Count = desks },
],
};
}
return new MapLayout { Rooms = rooms };
}
/// <summary>
/// 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.
/// </summary>
public static MapLayout PostHeavyMap()
{
var rooms = new List<RoomNode>
{
new()
{
Id = "classroom-00",
Def = "Classroom",
Building = "main",
Floor = "floor-1",
Label = "101",
Slots = [new SlotFill { Key = "studentDesks", Thing = "StudentDesk", Count = 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 Roster Generate(MapLayout map, int seed = SchoolSeed) =>
RosterGenerator.Generate(Catalog(), map, seed, "Slavic", AsOf);
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;
}
}