242 lines
10 KiB
C#
242 lines
10 KiB
C#
using System.Linq;
|
|
using GeometryTD.Definition;
|
|
using NUnit.Framework;
|
|
|
|
namespace GeometryTD.Tests.EditMode
|
|
{
|
|
public sealed class CombatParticipantTowerValidationServiceTests
|
|
{
|
|
[Test]
|
|
public void ValidateTower_Returns_Valid_When_Tower_And_Three_Components_Exist()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, 90001);
|
|
|
|
Assert.That(result.IsValid, Is.True);
|
|
Assert.That(result.TowerInstanceId, Is.EqualTo(90001));
|
|
Assert.That(result.FailureReason, Is.EqualTo(CombatParticipantTowerValidationFailureReason.None));
|
|
Assert.That(result.Tower, Is.Not.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateTower_Returns_TowerMissing_When_Tower_Does_Not_Exist()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, 12345);
|
|
|
|
Assert.That(result.IsValid, Is.False);
|
|
Assert.That(result.TowerInstanceId, Is.EqualTo(12345));
|
|
Assert.That(result.FailureReason, Is.EqualTo(CombatParticipantTowerValidationFailureReason.TowerMissing));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateTower_Returns_MissingMuzzle_When_Muzzle_Is_Not_Resolvable()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.Towers[0].MuzzleComponentInstanceId = 99901;
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, inventory.Towers[0]);
|
|
|
|
Assert.That(result.IsValid, Is.False);
|
|
Assert.That(result.FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.MissingMuzzleComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateTower_Returns_MissingBearing_When_Bearing_Is_Not_Resolvable()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.Towers[0].BearingComponentInstanceId = 99902;
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, inventory.Towers[0]);
|
|
|
|
Assert.That(result.IsValid, Is.False);
|
|
Assert.That(result.FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.MissingBearingComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateTower_Returns_MissingBase_When_Base_Is_Not_Resolvable()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.Towers[0].BaseComponentInstanceId = 99903;
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, inventory.Towers[0]);
|
|
|
|
Assert.That(result.IsValid, Is.False);
|
|
Assert.That(result.FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.MissingBaseComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateTower_Returns_BrokenMuzzle_When_Muzzle_Endurance_Is_Zero()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.MuzzleComponents[0].Endurance = 0f;
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, inventory.Towers[0]);
|
|
|
|
Assert.That(result.IsValid, Is.False);
|
|
Assert.That(result.FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.BrokenMuzzleComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateTower_Returns_BrokenBearing_When_Bearing_Endurance_Is_Zero()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.BearingComponents[0].Endurance = 0f;
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, inventory.Towers[0]);
|
|
|
|
Assert.That(result.IsValid, Is.False);
|
|
Assert.That(result.FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.BrokenBearingComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateTower_Returns_BrokenBase_When_Base_Endurance_Is_Zero()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.BaseComponents[0].Endurance = 0f;
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, inventory.Towers[0]);
|
|
|
|
Assert.That(result.IsValid, Is.False);
|
|
Assert.That(result.FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.BrokenBaseComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateParticipantTowers_Splits_Valid_And_Invalid_Towers()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.Towers.Add(new TowerItemData
|
|
{
|
|
InstanceId = 90002,
|
|
Name = "非法塔",
|
|
MuzzleComponentInstanceId = 10001,
|
|
BearingComponentInstanceId = 20001,
|
|
BaseComponentInstanceId = 99903,
|
|
Stats = new TowerStatsData()
|
|
});
|
|
inventory.ParticipantTowerInstanceIds.Add(90002);
|
|
|
|
CombatParticipantTowerValidationSummary summary =
|
|
CombatParticipantTowerValidationService.ValidateParticipantTowers(inventory);
|
|
|
|
Assert.That(summary.HasAnyValidParticipantTower, Is.True);
|
|
Assert.That(summary.ValidTowers.Count, Is.EqualTo(1));
|
|
Assert.That(summary.ValidTowers[0].InstanceId, Is.EqualTo(90001));
|
|
Assert.That(summary.InvalidResults.Count, Is.EqualTo(1));
|
|
Assert.That(summary.InvalidResults[0].TowerInstanceId, Is.EqualTo(90002));
|
|
Assert.That(summary.InvalidResults[0].FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.MissingBaseComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateParticipantTowers_Treats_Zero_Endurance_As_Invalid_For_S5_02()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.MuzzleComponents[0].Endurance = 0f;
|
|
|
|
CombatParticipantTowerValidationSummary summary =
|
|
CombatParticipantTowerValidationService.ValidateParticipantTowers(inventory);
|
|
|
|
Assert.That(summary.HasAnyValidParticipantTower, Is.False);
|
|
Assert.That(summary.ValidTowers.Count, Is.EqualTo(0));
|
|
Assert.That(summary.InvalidResults.Count, Is.EqualTo(1));
|
|
Assert.That(summary.InvalidResults[0].FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.BrokenMuzzleComponent));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateParticipantTowers_Does_Not_Require_TowerStats()
|
|
{
|
|
BackpackInventoryData inventory = CreateInventory();
|
|
inventory.Towers[0].Stats = null;
|
|
|
|
CombatParticipantTowerValidationResult result =
|
|
CombatParticipantTowerValidationService.ValidateTower(inventory, inventory.Towers[0]);
|
|
|
|
Assert.That(result.IsValid, Is.True);
|
|
Assert.That(result.FailureReason, Is.EqualTo(CombatParticipantTowerValidationFailureReason.None));
|
|
}
|
|
|
|
[Test]
|
|
public void ValidateParticipantTowers_Handles_Empty_And_Duplicate_Participant_Ids()
|
|
{
|
|
BackpackInventoryData emptyInventory = CreateInventory();
|
|
emptyInventory.ParticipantTowerInstanceIds.Clear();
|
|
|
|
CombatParticipantTowerValidationSummary emptySummary =
|
|
CombatParticipantTowerValidationService.ValidateParticipantTowers(emptyInventory);
|
|
|
|
Assert.That(emptySummary.HasAnyValidParticipantTower, Is.False);
|
|
Assert.That(emptySummary.ValidTowers.Count, Is.EqualTo(0));
|
|
Assert.That(emptySummary.InvalidResults.Count, Is.EqualTo(0));
|
|
|
|
BackpackInventoryData duplicateInventory = CreateInventory();
|
|
duplicateInventory.ParticipantTowerInstanceIds.Add(90001);
|
|
duplicateInventory.ParticipantTowerInstanceIds.Add(99999);
|
|
duplicateInventory.ParticipantTowerInstanceIds.Add(99999);
|
|
|
|
CombatParticipantTowerValidationSummary duplicateSummary =
|
|
CombatParticipantTowerValidationService.ValidateParticipantTowers(duplicateInventory);
|
|
|
|
Assert.That(duplicateSummary.ValidTowers.Count, Is.EqualTo(1));
|
|
Assert.That(duplicateSummary.InvalidResults.Count, Is.EqualTo(1));
|
|
Assert.That(duplicateSummary.InvalidResults.Single().TowerInstanceId, Is.EqualTo(99999));
|
|
Assert.That(duplicateSummary.InvalidResults.Single().FailureReason,
|
|
Is.EqualTo(CombatParticipantTowerValidationFailureReason.TowerMissing));
|
|
}
|
|
|
|
private static BackpackInventoryData CreateInventory()
|
|
{
|
|
BackpackInventoryData inventory = new BackpackInventoryData();
|
|
|
|
inventory.MuzzleComponents.Add(new MuzzleCompItemData
|
|
{
|
|
InstanceId = 10001,
|
|
Name = "枪口",
|
|
Endurance = 100f
|
|
});
|
|
inventory.BearingComponents.Add(new BearingCompItemData
|
|
{
|
|
InstanceId = 20001,
|
|
Name = "轴承",
|
|
Endurance = 100f
|
|
});
|
|
inventory.BaseComponents.Add(new BaseCompItemData
|
|
{
|
|
InstanceId = 30001,
|
|
Name = "底座",
|
|
Endurance = 100f
|
|
});
|
|
|
|
inventory.Towers.Add(new TowerItemData
|
|
{
|
|
InstanceId = 90001,
|
|
Name = "合法塔",
|
|
MuzzleComponentInstanceId = 10001,
|
|
BearingComponentInstanceId = 20001,
|
|
BaseComponentInstanceId = 30001,
|
|
Stats = new TowerStatsData()
|
|
});
|
|
|
|
inventory.ParticipantTowerInstanceIds.Add(90001);
|
|
return inventory;
|
|
}
|
|
}
|
|
}
|