152 lines
7.1 KiB
C#
152 lines
7.1 KiB
C#
using GeometryTD.CustomUtility;
|
|
using GeometryTD.Definition;
|
|
using NUnit.Framework;
|
|
|
|
namespace GeometryTD.Tests.EditMode
|
|
{
|
|
public sealed class ParticipantTowerAssignResultTests
|
|
{
|
|
[Test]
|
|
public void TryAddParticipantTower_Returns_Success_For_Legal_Tower()
|
|
{
|
|
BackpackInventoryData inventory = CreateValidInventory();
|
|
|
|
ParticipantTowerAssignResult result = InventoryParticipantUtility.TryAddParticipantTower(inventory, 90001, 4);
|
|
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result.IsSuccess, Is.True);
|
|
Assert.That(result.FailureReason, Is.EqualTo(ParticipantTowerAssignFailureReason.None));
|
|
Assert.That(result.ValidationFailureReason, Is.EqualTo(CombatParticipantTowerValidationFailureReason.None));
|
|
Assert.That(inventory.ParticipantTowerInstanceIds.Count, Is.EqualTo(1));
|
|
Assert.That(inventory.ParticipantTowerInstanceIds[0], Is.EqualTo(90001));
|
|
Assert.That(inventory.Towers[0].IsParticipatingInCombat, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void TryAddParticipantTower_Returns_TowerMissing_When_Tower_Is_Not_Found()
|
|
{
|
|
BackpackInventoryData inventory = CreateValidInventory();
|
|
|
|
ParticipantTowerAssignResult result = InventoryParticipantUtility.TryAddParticipantTower(inventory, 99999, 4);
|
|
|
|
Assert.That(result.IsSuccess, Is.False);
|
|
Assert.That(result.FailureReason, Is.EqualTo(ParticipantTowerAssignFailureReason.TowerMissing));
|
|
Assert.That(result.ValidationFailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.TowerMissing));
|
|
Assert.That(inventory.ParticipantTowerInstanceIds.Count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TryAddParticipantTower_Returns_InvalidTower_With_Missing_Component_Reason()
|
|
{
|
|
BackpackInventoryData inventory = CreateValidInventory();
|
|
inventory.Towers[0].BaseComponentInstanceId = 33333;
|
|
|
|
ParticipantTowerAssignResult result = InventoryParticipantUtility.TryAddParticipantTower(inventory, 90001, 4);
|
|
|
|
Assert.That(result.IsSuccess, Is.False);
|
|
Assert.That(result.FailureReason, Is.EqualTo(ParticipantTowerAssignFailureReason.InvalidTower));
|
|
Assert.That(result.ValidationFailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.MissingBaseComponent));
|
|
Assert.That(inventory.ParticipantTowerInstanceIds.Count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TryAddParticipantTower_Returns_InvalidTower_With_Broken_Component_Reason()
|
|
{
|
|
BackpackInventoryData inventory = CreateValidInventory();
|
|
inventory.MuzzleComponents[0].Endurance = 0f;
|
|
|
|
ParticipantTowerAssignResult result = InventoryParticipantUtility.TryAddParticipantTower(inventory, 90001, 4);
|
|
|
|
Assert.That(result.IsSuccess, Is.False);
|
|
Assert.That(result.FailureReason, Is.EqualTo(ParticipantTowerAssignFailureReason.InvalidTower));
|
|
Assert.That(result.ValidationFailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.BrokenMuzzleComponent));
|
|
Assert.That(inventory.ParticipantTowerInstanceIds.Count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TryAddParticipantTower_Returns_AlreadyAssigned_Without_Duplicating_List()
|
|
{
|
|
BackpackInventoryData inventory = CreateValidInventory();
|
|
inventory.ParticipantTowerInstanceIds.Add(90001);
|
|
inventory.Towers[0].IsParticipatingInCombat = true;
|
|
|
|
ParticipantTowerAssignResult result = InventoryParticipantUtility.TryAddParticipantTower(inventory, 90001, 4);
|
|
|
|
Assert.That(result.IsSuccess, Is.False);
|
|
Assert.That(result.FailureReason, Is.EqualTo(ParticipantTowerAssignFailureReason.AlreadyAssigned));
|
|
Assert.That(result.ValidationFailureReason, Is.EqualTo(CombatParticipantTowerValidationFailureReason.None));
|
|
Assert.That(inventory.ParticipantTowerInstanceIds.Count, Is.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public void TryAddParticipantTower_Returns_ParticipantAreaFull_When_MaxCount_Reached()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventoryWithFourParticipantTowers();
|
|
|
|
ParticipantTowerAssignResult result = InventoryParticipantUtility.TryAddParticipantTower(inventory, 90005, 4);
|
|
|
|
Assert.That(result.IsSuccess, Is.False);
|
|
Assert.That(result.FailureReason, Is.EqualTo(ParticipantTowerAssignFailureReason.ParticipantAreaFull));
|
|
Assert.That(result.ValidationFailureReason, Is.EqualTo(CombatParticipantTowerValidationFailureReason.None));
|
|
Assert.That(inventory.ParticipantTowerInstanceIds.Count, Is.EqualTo(4));
|
|
Assert.That(inventory.Towers[4].IsParticipatingInCombat, Is.False);
|
|
}
|
|
|
|
private static BackpackInventoryData CreateValidInventory()
|
|
{
|
|
BackpackInventoryData inventory = new BackpackInventoryData();
|
|
inventory.MuzzleComponents.Add(new MuzzleCompItemData { InstanceId = 10001, Name = "枪口" });
|
|
inventory.BearingComponents.Add(new BearingCompItemData { InstanceId = 20001, Name = "轴承" });
|
|
inventory.BaseComponents.Add(new BaseCompItemData { InstanceId = 30001, Name = "底座" });
|
|
inventory.Towers.Add(new TowerItemData
|
|
{
|
|
InstanceId = 90001,
|
|
Name = "合法塔",
|
|
MuzzleComponentInstanceId = 10001,
|
|
BearingComponentInstanceId = 20001,
|
|
BaseComponentInstanceId = 30001,
|
|
Stats = new TowerStatsData()
|
|
});
|
|
|
|
return inventory;
|
|
}
|
|
|
|
private static BackpackInventoryData CreateInventoryWithFourParticipantTowers()
|
|
{
|
|
BackpackInventoryData inventory = new BackpackInventoryData();
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
long towerId = 90001 + i;
|
|
long muzzleId = 10001 + i;
|
|
long bearingId = 20001 + i;
|
|
long baseId = 30001 + i;
|
|
|
|
inventory.MuzzleComponents.Add(new MuzzleCompItemData { InstanceId = muzzleId, Name = $"枪口-{i}" });
|
|
inventory.BearingComponents.Add(new BearingCompItemData { InstanceId = bearingId, Name = $"轴承-{i}" });
|
|
inventory.BaseComponents.Add(new BaseCompItemData { InstanceId = baseId, Name = $"底座-{i}" });
|
|
inventory.Towers.Add(new TowerItemData
|
|
{
|
|
InstanceId = towerId,
|
|
Name = $"塔-{i}",
|
|
MuzzleComponentInstanceId = muzzleId,
|
|
BearingComponentInstanceId = bearingId,
|
|
BaseComponentInstanceId = baseId,
|
|
Stats = new TowerStatsData(),
|
|
IsParticipatingInCombat = i < 4
|
|
});
|
|
|
|
if (i < 4)
|
|
{
|
|
inventory.ParticipantTowerInstanceIds.Add(towerId);
|
|
}
|
|
}
|
|
|
|
return inventory;
|
|
}
|
|
}
|
|
}
|