Files
AIC-Project/Client/Assets/Script/Tests/EditMode/PlayerProfileModuleTests.cs
T
2026-07-31 17:39:52 +08:00

96 lines
2.8 KiB
C#

using NUnit.Framework;
using System;
using UnityEngine;
using XGame;
#if UNITY_EDITOR
using XGame.EditorTools;
#endif
public sealed class PlayerProfileModuleTests
{
[TearDown]
public void TearDown()
{
PlayerProfileStore.ResetToDefault();
}
[Test]
public void DefaultProfile_HasPlayableCombatStats()
{
PlayerProfileData profile = PlayerProfileData.CreateDefault();
Assert.That(profile.Nickname, Is.EqualTo("Player"));
Assert.That(profile.Uid, Is.EqualTo("0"));
Assert.That(profile.Lv, Is.EqualTo(1));
Assert.That(profile.HpMax, Is.GreaterThan(0));
Assert.That(profile.Hp, Is.EqualTo(profile.HpMax));
Assert.That(profile.MpMax, Is.GreaterThan(0));
Assert.That(profile.Mp, Is.EqualTo(profile.MpMax));
Assert.That(profile.Ad, Is.GreaterThan(0));
Assert.That(profile.MoveSpeed, Is.GreaterThan(0f));
}
[Test]
public void Replace_SanitizesInvalidValuesAndRaisesChanged()
{
int changed = 0;
Action<PlayerProfileData> handler = _ => changed++;
PlayerProfileStore.Changed += handler;
try
{
PlayerProfileStore.Replace(new PlayerProfileData
{
Nickname = "Alice",
Uid = "42",
AvatarId = -1,
RoleType = PlayerRoleType.Mage,
Lv = -5,
Exp = -20,
Hp = 999,
HpMax = 100,
Mp = -3,
MpMax = 50,
AtkSpeed = -1f,
MoveSpeed = -2f
});
}
finally
{
PlayerProfileStore.Changed -= handler;
}
PlayerProfileData current = PlayerProfileStore.Current;
Assert.That(changed, Is.EqualTo(1));
Assert.That(current.AvatarId, Is.EqualTo(0));
Assert.That(current.Lv, Is.EqualTo(1));
Assert.That(current.Exp, Is.EqualTo(0));
Assert.That(current.Hp, Is.EqualTo(100));
Assert.That(current.Mp, Is.EqualTo(0));
Assert.That(current.AtkSpeed, Is.GreaterThan(0f));
Assert.That(current.MoveSpeed, Is.GreaterThan(0f));
}
[Test]
public void Experience01_ClampsAgainstLevelRequirement()
{
PlayerProfileData profile = PlayerProfileData.CreateDefault();
profile.Lv = 2;
profile.Exp = 150;
Assert.That(profile.Experience01, Is.EqualTo(0.75f).Within(0.001f));
profile.Exp = 999;
Assert.That(profile.Experience01, Is.EqualTo(1f));
}
#if UNITY_EDITOR
[Test]
public void PlayerProfileJsonFiles_PassPrefabBuilderValidation()
{
Assert.That(JsonUIPrefabBuilder.Validate("../Doc/UIPrefabCreater/UI_PlayerProfileHud.json").Ok, Is.True);
Assert.That(JsonUIPrefabBuilder.Validate("../Doc/UIPrefabCreater/UI_PlayerProfilePanel.json").Ok, Is.True);
}
#endif
}