Files
przygody-pana-cegly/progression.tests/ProfileStoreTests.cs
Gabriel Kaszewski 003ec4b010 feat(progression): snapshots, ports, in-memory adapters (slice 5)
flat snapshot record per aggregate - separate files mean saving a run
doesn't rewrite the Profile, deleting a slot is deleting a file, and a
corrupt slot doesn't cost achievements or best times.

snapshots hold primitives so Restore re-runs the value-object factories;
a serialiser building LevelId directly would bypass every guard.

LoadResult has three outcomes: Absent != Corrupt. Collapsing them is the
bug where a version bump made ContinueGame overwrite the save.

Profile.Restore writes collections directly - replaying UnlockAchievement
would re-fire popups and Steam pushes on every load. 44 tests.
2026-07-28 19:02:41 +02:00

39 lines
1.1 KiB
C#

namespace Mr.BrickAdventures.Progression.Tests;
public class ProfileStoreTests
{
private static readonly LevelId Level = LevelId.Of("village_1");
[Fact]
public void On_a_first_run_there_is_no_profile_yet_and_that_is_absent_not_corrupt()
{
var store = new InMemoryProfileStore();
Assert.Equal(LoadOutcome.Absent, store.Load().Outcome);
}
[Fact]
public void A_saved_profile_loads_back_with_its_best_times()
{
var store = new InMemoryProfileStore();
var profile = Profile.Empty();
profile.RecordTime(Level, LevelTime.Of(31.25));
store.Save(profile);
var result = store.Load();
Assert.Equal(LoadOutcome.Loaded, result.Outcome);
Assert.Equal(LevelTime.Of(31.25), result.Value!.BestTimeFor(Level));
}
[Fact]
public void A_profile_that_cannot_be_read_is_corrupt_so_achievements_are_not_silently_wiped()
{
var store = new InMemoryProfileStore();
store.Save(Profile.Empty());
store.Corrupt();
Assert.Equal(LoadOutcome.Corrupt, store.Load().Outcome);
}
}