namespace Mr.BrickAdventures.Progression.Tests; /// /// The test-side adapter for . Its existence alongside the JSON store /// is what makes the port a real seam rather than a hypothetical one. /// internal sealed class InMemoryPlaythroughStore : IPlaythroughStore { private readonly Dictionary _saved = new(); private readonly HashSet _corrupt = new(); public void Save(Playthrough playthrough) => _saved[playthrough.Id.Value] = playthrough.Export(); /// Simulates a file that exists but cannot be read back into a valid snapshot. public void Corrupt(PlaythroughId id) => _corrupt.Add(id.Value); public LoadResult Load(PlaythroughId id) { if (_corrupt.Contains(id.Value)) return LoadResult.Corrupt("snapshot could not be read"); if (!_saved.TryGetValue(id.Value, out var snapshot)) return LoadResult.Absent(); try { return LoadResult.Loaded(Playthrough.Restore(snapshot)); } catch (Exception e) { return LoadResult.Corrupt(e.Message); } } }