Skip users.json when loading school saves.

The session user list sits beside {id}.json; LoadAll treated it as a school with id 0.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Leonid Pershin
2026-08-20 12:46:52 +03:00
co-authored by Cursor
parent 7496718d88
commit 0b1a52a5e5
6 changed files with 102 additions and 2 deletions
@@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\HSchool.Server\HSchool.Server.csproj" />
<ProjectReference Include="..\..\src\HSchool.People\HSchool.People.csproj" />
<ProjectReference Include="..\..\src\HSchool.Simulation\HSchool.Simulation.csproj" />
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,60 @@
using HSchool.Server.Game;
using HSchool.Simulation;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
namespace HSchool.Server.Tests;
public class SchoolStoreTests
{
[Fact]
public void LoadAll_SkipsUsersJsonBesideASchoolSave()
{
var directory = Directory.CreateTempSubdirectory("h-school-store-");
try
{
File.WriteAllText(
Path.Combine(directory.FullName, UserStore.FileName),
"""{ "users": [ { "name": "Player" } ] }""");
File.WriteAllText(
Path.Combine(directory.FullName, "1.json"),
"""
{
"format": 3,
"id": 1,
"name": "North",
"gameTime": "2012-03-31T06:00:00Z",
"running": false,
"speedIndex": 0
}
""");
var store = CreateStore(directory.FullName);
var saves = store.LoadAll();
var save = Assert.Single(saves);
Assert.Equal(1, save.Id);
Assert.Equal("North", save.Name);
}
finally
{
directory.Delete(recursive: true);
}
}
private static SchoolStore CreateStore(string directory)
{
var options = Options.Create(new SimulationOptions { SavesDirectory = directory });
return new SchoolStore(options, new StubHost(), NullLogger<SchoolStore>.Instance);
}
private sealed class StubHost : IHostEnvironment
{
public string ApplicationName { get; set; } = "HSchool.Server.Tests";
public string EnvironmentName { get; set; } = "Development";
public string ContentRootPath { get; set; } = Path.GetTempPath();
public IFileProvider ContentRootFileProvider { get; set; } = new NullFileProvider();
}
}