Files
YachtDice/Assets/Scripts/Tests/Editor/SaveSystemTests.cs
T
horooko bee20fd1f8 [Refactor] Add folder-based namespaces to all C# scripts
Wrap all 39 scripts and 6 test files in namespaces matching their folder
structure (e.g. Assets/Scripts/Dice/ → YachtDice.Dice). Add cross-namespace
using directives where types are referenced across modules. Set rootNamespace
in both .asmdef files (YachtDice, YachtDice.Tests).

Namespace mapping:
- YachtDice.Dice — Dice, DiceRoller
- YachtDice.Economy — CurrencyBank
- YachtDice.Game — GameManager, DiceManager, DebugGameInput
- YachtDice.Inventory — InventoryController/Model/SlotView/View
- YachtDice.Modifiers — ModifierData/Effect/Enums/Pipeline/Runtime/Target
- YachtDice.Persistence — SaveData, SaveSystem
- YachtDice.Scoring — CategoryScorer, ScoreResult, ScoringSystem, YachtCategory
- YachtDice.Shop — ShopCatalog/Controller/ItemView/Model/View
- YachtDice.UI — CategoryRowView, DicePanelView, GameController, GameInfoView, ScoreCardView
- YachtDice.Editor — ModifierAssetCreator
- YachtDice.Tests — all test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:06:57 +07:00

94 lines
2.2 KiB
C#

using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using YachtDice.Persistence;
namespace YachtDice.Tests
{
public sealed class SaveSystemTests
{
[SetUp]
public void SetUp()
{
SaveSystem.Delete();
}
[TearDown]
public void TearDown()
{
SaveSystem.Delete();
}
[Test]
public void SaveAndLoad_RoundTrip_PreservesData()
{
var data = new SaveData
{
Currency = 999,
OwnedModifiers = new List<ModifierSaveEntry>
{
new() { ModifierId = "mod1", IsActive = true, RemainingUses = 3 },
new() { ModifierId = "mod2", IsActive = false, RemainingUses = -1 }
}
};
SaveSystem.Save(data);
var loaded = SaveSystem.Load();
Assert.AreEqual(999, loaded.Currency);
Assert.AreEqual(2, loaded.OwnedModifiers.Count);
Assert.AreEqual("mod1", loaded.OwnedModifiers[0].ModifierId);
Assert.IsTrue(loaded.OwnedModifiers[0].IsActive);
Assert.AreEqual(3, loaded.OwnedModifiers[0].RemainingUses);
Assert.AreEqual("mod2", loaded.OwnedModifiers[1].ModifierId);
Assert.IsFalse(loaded.OwnedModifiers[1].IsActive);
}
[Test]
public void Load_MissingKey_ReturnsDefault()
{
var loaded = SaveSystem.Load();
Assert.IsNotNull(loaded);
Assert.AreEqual(0, loaded.Currency);
Assert.AreEqual(0, loaded.OwnedModifiers.Count);
}
[Test]
public void HasSave_ReturnsFalseWhenEmpty()
{
Assert.IsFalse(SaveSystem.HasSave());
}
[Test]
public void HasSave_ReturnsTrueAfterSave()
{
SaveSystem.Save(new SaveData { Currency = 100 });
Assert.IsTrue(SaveSystem.HasSave());
}
[Test]
public void Delete_RemovesSaveData()
{
SaveSystem.Save(new SaveData { Currency = 100 });
SaveSystem.Delete();
Assert.IsFalse(SaveSystem.HasSave());
}
[Test]
public void Load_CorruptJson_ReturnsDefault()
{
PlayerPrefs.SetString("YachtDice_SaveData", "{invalid json!!!");
PlayerPrefs.Save();
var loaded = SaveSystem.Load();
Assert.IsNotNull(loaded);
Assert.AreEqual(0, loaded.Currency);
}
}
}