86 lines
3.8 KiB
C#
86 lines
3.8 KiB
C#
using GeometryTD.Definition;
|
||
using GeometryTD.Procedure;
|
||
using GeometryTD.UI;
|
||
using NUnit.Framework;
|
||
|
||
namespace GeometryTD.Tests.EditMode
|
||
{
|
||
public sealed class ProcedureMainParticipantTowerCleanupServiceTests
|
||
{
|
||
[Test]
|
||
public void RemoveBrokenParticipantTowers_Removes_Only_Broken_Participant_Towers()
|
||
{
|
||
BackpackInventoryData inventory = CreateInventory();
|
||
inventory.MuzzleComponents[0].Endurance = 0f;
|
||
inventory.ParticipantTowerInstanceIds.Add(90002);
|
||
|
||
ProcedureMainParticipantTowerCleanupResult result =
|
||
ProcedureMainParticipantTowerCleanupService.RemoveBrokenParticipantTowers(inventory, 4);
|
||
|
||
Assert.That(result.HasAnyRemovedTower, Is.True);
|
||
Assert.That(result.RemovedResults.Count, Is.EqualTo(1));
|
||
Assert.That(result.RemovedResults[0].TowerInstanceId, Is.EqualTo(90001));
|
||
CollectionAssert.AreEqual(new long[] { 90002 }, inventory.ParticipantTowerInstanceIds);
|
||
Assert.That(inventory.Towers[0].IsParticipatingInCombat, Is.False);
|
||
Assert.That(inventory.Towers[1].IsParticipatingInCombat, Is.True);
|
||
}
|
||
|
||
[Test]
|
||
public void BuildRemovedTowerDialogRawData_Lists_Removed_Broken_Towers()
|
||
{
|
||
ProcedureMainParticipantTowerCleanupResult cleanupResult = new ProcedureMainParticipantTowerCleanupResult();
|
||
cleanupResult.RemovedResults.Add(new CombatParticipantTowerValidationResult
|
||
{
|
||
TowerInstanceId = 90001,
|
||
FailureReason = CombatParticipantTowerValidationFailureReason.BrokenMuzzleComponent
|
||
});
|
||
cleanupResult.RemovedResults.Add(new CombatParticipantTowerValidationResult
|
||
{
|
||
TowerInstanceId = 90002,
|
||
FailureReason = CombatParticipantTowerValidationFailureReason.BrokenBaseComponent
|
||
});
|
||
|
||
DialogFormRawData rawData =
|
||
ProcedureMainParticipantTowerCleanupService.BuildRemovedTowerDialogRawData(cleanupResult);
|
||
|
||
Assert.That(rawData.Title, Is.EqualTo("出战塔已损坏"));
|
||
Assert.That(
|
||
rawData.Message,
|
||
Is.EqualTo("以下防御塔已损坏,已自动移出参战区:\n塔 #90001 枪口组件耐久为 0,无法参战。\n塔 #90002 底座组件耐久为 0,无法参战。"));
|
||
Assert.That(rawData.ConfirmText, Is.EqualTo("知道了"));
|
||
}
|
||
|
||
private static BackpackInventoryData CreateInventory()
|
||
{
|
||
BackpackInventoryData inventory = new BackpackInventoryData();
|
||
AddTower(inventory, 90001, 10001, 20001, 30001);
|
||
AddTower(inventory, 90002, 10002, 20002, 30002);
|
||
inventory.ParticipantTowerInstanceIds.Add(90001);
|
||
inventory.ParticipantTowerInstanceIds.Add(90002);
|
||
inventory.Towers[0].IsParticipatingInCombat = true;
|
||
inventory.Towers[1].IsParticipatingInCombat = true;
|
||
return inventory;
|
||
}
|
||
|
||
private static void AddTower(
|
||
BackpackInventoryData inventory,
|
||
long towerId,
|
||
long muzzleId,
|
||
long bearingId,
|
||
long baseId)
|
||
{
|
||
inventory.MuzzleComponents.Add(new MuzzleCompItemData { InstanceId = muzzleId, Endurance = 100f });
|
||
inventory.BearingComponents.Add(new BearingCompItemData { InstanceId = bearingId, Endurance = 100f });
|
||
inventory.BaseComponents.Add(new BaseCompItemData { InstanceId = baseId, Endurance = 100f });
|
||
inventory.Towers.Add(new TowerItemData
|
||
{
|
||
InstanceId = towerId,
|
||
MuzzleComponentInstanceId = muzzleId,
|
||
BearingComponentInstanceId = bearingId,
|
||
BaseComponentInstanceId = baseId,
|
||
Stats = new TowerStatsData()
|
||
});
|
||
}
|
||
}
|
||
}
|