From: Tayrtahn Date: Fri, 4 Jul 2025 20:48:55 +0000 (-0400) Subject: Validate `ProtoId`s in tests (#38745) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=3a278bca8bf690d8e2b8553773ac8e7c5b2f544f;p=space-station-14.git Validate `ProtoId`s in tests (#38745) * Convert string literals to protoids in Content.Tests * Convert string literals to protoids or consts in Content.IntegrationTests * Fix linter failures Tricksy static using misled me --- diff --git a/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs b/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs index 064b4f9a2d..b74c35ba11 100644 --- a/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs +++ b/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs @@ -7,10 +7,12 @@ namespace Content.IntegrationTests.Tests.Atmos [TestOf(typeof(AtmosAlarmThreshold))] public sealed class AlarmThresholdTest { + private const string AlarmThresholdTestDummyId = "AlarmThresholdTestDummy"; + [TestPrototypes] - private const string Prototypes = @" + private const string Prototypes = $@" - type: alarmThreshold - id: AlarmThresholdTestDummy + id: {AlarmThresholdTestDummyId} upperBound: !type:AlarmThresholdSetting threshold: 5 lowerBound: !type:AlarmThresholdSetting @@ -30,7 +32,7 @@ namespace Content.IntegrationTests.Tests.Atmos var prototypeManager = server.ResolveDependency(); AtmosAlarmThreshold threshold = default!; - var proto = prototypeManager.Index("AlarmThresholdTestDummy"); + var proto = prototypeManager.Index(AlarmThresholdTestDummyId); threshold = new(proto); await server.WaitAssertion(() => diff --git a/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs b/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs index cfc8007306..e4ec7e907a 100644 --- a/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs +++ b/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs @@ -15,6 +15,8 @@ namespace Content.IntegrationTests.Tests.Commands [TestOf(typeof(RejuvenateSystem))] public sealed class RejuvenateTest { + private static readonly ProtoId TestDamageGroup = "Toxin"; + [TestPrototypes] private const string Prototypes = @" - type: entity @@ -62,7 +64,7 @@ namespace Content.IntegrationTests.Tests.Commands }); // Kill the entity - DamageSpecifier damage = new(prototypeManager.Index("Toxin"), FixedPoint2.New(10000000)); + DamageSpecifier damage = new(prototypeManager.Index(TestDamageGroup), FixedPoint2.New(10000000)); damSystem.TryChangeDamage(human, damage, true); diff --git a/Content.IntegrationTests/Tests/Commands/SuicideCommandTests.cs b/Content.IntegrationTests/Tests/Commands/SuicideCommandTests.cs index b53b87dd5c..61b8d54448 100644 --- a/Content.IntegrationTests/Tests/Commands/SuicideCommandTests.cs +++ b/Content.IntegrationTests/Tests/Commands/SuicideCommandTests.cs @@ -53,6 +53,8 @@ public sealed class SuicideCommandTests components: - type: MaterialReclaimer"; private static readonly ProtoId CannotSuicideTag = "CannotSuicide"; + private static readonly ProtoId DamageType = "Slash"; + /// /// Run the suicide command in the console /// Should successfully kill the player and ghost them @@ -144,7 +146,7 @@ public sealed class SuicideCommandTests mobThresholdsComp = entManager.GetComponent(player); damageableComp = entManager.GetComponent(player); - if (protoMan.TryIndex("Slash", out var slashProto)) + if (protoMan.TryIndex(DamageType, out var slashProto)) damageableSystem.TryChangeDamage(player, new DamageSpecifier(slashProto, FixedPoint2.New(46.5))); }); diff --git a/Content.IntegrationTests/Tests/Construction/Interaction/WindowRepair.cs b/Content.IntegrationTests/Tests/Construction/Interaction/WindowRepair.cs index 6eea519af3..192604edfd 100644 --- a/Content.IntegrationTests/Tests/Construction/Interaction/WindowRepair.cs +++ b/Content.IntegrationTests/Tests/Construction/Interaction/WindowRepair.cs @@ -8,6 +8,8 @@ namespace Content.IntegrationTests.Tests.Construction.Interaction; public sealed class WindowRepair : InteractionTest { + private static readonly ProtoId BluntDamageType = "Blunt"; + [Test] public async Task RepairReinforcedWindow() { @@ -16,7 +18,7 @@ public sealed class WindowRepair : InteractionTest // Damage the entity. var sys = SEntMan.System(); var comp = Comp(); - var damageType = Server.ResolveDependency().Index("Blunt"); + var damageType = Server.ProtoMan.Index(BluntDamageType); var damage = new DamageSpecifier(damageType, FixedPoint2.New(10)); Assert.That(comp.Damage.GetTotal(), Is.EqualTo(FixedPoint2.Zero)); await Server.WaitPost(() => sys.TryChangeDamage(SEntMan.GetEntity(Target), damage, ignoreResistances: true)); diff --git a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs index 69069fc82f..f610ab732e 100644 --- a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs +++ b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs @@ -1,9 +1,7 @@ -using System.Linq; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Prototypes; @@ -14,66 +12,79 @@ namespace Content.IntegrationTests.Tests.Damageable [TestOf(typeof(DamageableSystem))] public sealed class DamageableTest { + private const string TestDamageableEntityId = "TestDamageableEntityId"; + private const string TestGroup1 = "TestGroup1"; + private const string TestGroup2 = "TestGroup2"; + private const string TestGroup3 = "TestGroup3"; + private const string TestDamage1 = "TestDamage1"; + private const string TestDamage2a = "TestDamage2a"; + private const string TestDamage2b = "TestDamage2b"; + + private const string TestDamage3a = "TestDamage3a"; + + private const string TestDamage3b = "TestDamage3b"; + private const string TestDamage3c = "TestDamage3c"; + [TestPrototypes] - private const string Prototypes = @" + private const string Prototypes = $@" # Define some damage groups - type: damageType - id: TestDamage1 + id: {TestDamage1} name: damage-type-blunt - type: damageType - id: TestDamage2a + id: {TestDamage2a} name: damage-type-blunt - type: damageType - id: TestDamage2b + id: {TestDamage2b} name: damage-type-blunt - type: damageType - id: TestDamage3a + id: {TestDamage3a} name: damage-type-blunt - type: damageType - id: TestDamage3b + id: {TestDamage3b} name: damage-type-blunt - type: damageType - id: TestDamage3c + id: {TestDamage3c} name: damage-type-blunt # Define damage Groups with 1,2,3 damage types - type: damageGroup - id: TestGroup1 + id: {TestGroup1} name: damage-group-brute damageTypes: - - TestDamage1 + - {TestDamage1} - type: damageGroup - id: TestGroup2 + id: {TestGroup2} name: damage-group-brute damageTypes: - - TestDamage2a - - TestDamage2b + - {TestDamage2a} + - {TestDamage2b} - type: damageGroup - id: TestGroup3 + id: {TestGroup3} name: damage-group-brute damageTypes: - - TestDamage3a - - TestDamage3b - - TestDamage3c + - {TestDamage3a} + - {TestDamage3b} + - {TestDamage3c} # This container should not support TestDamage1 or TestDamage2b - type: damageContainer id: testDamageContainer supportedGroups: - - TestGroup3 + - {TestGroup3} supportedTypes: - - TestDamage2a + - {TestDamage2a} - type: entity - id: TestDamageableEntityId - name: TestDamageableEntityId + id: {TestDamageableEntityId} + name: {TestDamageableEntityId} components: - type: Damageable damageContainer: testDamageContainer @@ -113,20 +124,20 @@ namespace Content.IntegrationTests.Tests.Damageable { var coordinates = map.MapCoords; - sDamageableEntity = sEntityManager.SpawnEntity("TestDamageableEntityId", coordinates); + sDamageableEntity = sEntityManager.SpawnEntity(TestDamageableEntityId, coordinates); sDamageableComponent = sEntityManager.GetComponent(sDamageableEntity); sDamageableSystem = sEntitySystemManager.GetEntitySystem(); - group1 = sPrototypeManager.Index("TestGroup1"); - group2 = sPrototypeManager.Index("TestGroup2"); - group3 = sPrototypeManager.Index("TestGroup3"); + group1 = sPrototypeManager.Index(TestGroup1); + group2 = sPrototypeManager.Index(TestGroup2); + group3 = sPrototypeManager.Index(TestGroup3); - type1 = sPrototypeManager.Index("TestDamage1"); - type2a = sPrototypeManager.Index("TestDamage2a"); - type2b = sPrototypeManager.Index("TestDamage2b"); - type3a = sPrototypeManager.Index("TestDamage3a"); - type3b = sPrototypeManager.Index("TestDamage3b"); - type3c = sPrototypeManager.Index("TestDamage3c"); + type1 = sPrototypeManager.Index(TestDamage1); + type2a = sPrototypeManager.Index(TestDamage2a); + type2b = sPrototypeManager.Index(TestDamage2b); + type3a = sPrototypeManager.Index(TestDamage3a); + type3b = sPrototypeManager.Index(TestDamage3b); + type3c = sPrototypeManager.Index(TestDamage3c); }); await server.WaitRunTicks(5); diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs index d37de7a504..0da07ad5a1 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs @@ -54,8 +54,8 @@ namespace Content.IntegrationTests.Tests.Destructible await server.WaitAssertion(() => { - var bruteDamageGroup = sPrototypeManager.Index("TestBrute"); - var burnDamageGroup = sPrototypeManager.Index("TestBurn"); + var bruteDamageGroup = sPrototypeManager.Index(TestBruteDamageGroupId); + var burnDamageGroup = sPrototypeManager.Index(TestBurnDamageGroupId); DamageSpecifier bruteDamage = new(bruteDamageGroup, FixedPoint2.New(5)); DamageSpecifier burnDamage = new(burnDamageGroup, FixedPoint2.New(5)); diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs index 69891cbd89..ccd459668b 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs @@ -49,8 +49,8 @@ namespace Content.IntegrationTests.Tests.Destructible await server.WaitAssertion(() => { - var bluntDamageType = protoManager.Index("TestBlunt"); - var slashDamageType = protoManager.Index("TestSlash"); + var bluntDamageType = protoManager.Index(TestBluntDamageTypeId); + var slashDamageType = protoManager.Index(TestSlashDamageTypeId); var bluntDamage = new DamageSpecifier(bluntDamageType, 5); var slashDamage = new DamageSpecifier(slashDamageType, 5); diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs index a50238d8f5..4e169e7dfa 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs @@ -39,7 +39,7 @@ namespace Content.IntegrationTests.Tests.Destructible await server.WaitAssertion(() => { var coordinates = sEntityManager.GetComponent(sDestructibleEntity).Coordinates; - var bruteDamageGroup = sPrototypeManager.Index("TestBrute"); + var bruteDamageGroup = sPrototypeManager.Index(TestBruteDamageGroupId); DamageSpecifier bruteDamage = new(bruteDamageGroup, 50); #pragma warning disable NUnit2045 // Interdependent assertions. diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs index 7ff9242398..872e414ac3 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs @@ -7,48 +7,56 @@ namespace Content.IntegrationTests.Tests.Destructible public const string DestructibleDestructionEntityId = "DestructibleTestsDestructibleDestructionEntity"; public const string DestructibleDamageTypeEntityId = "DestructibleTestsDestructibleDamageTypeEntity"; public const string DestructibleDamageGroupEntityId = "DestructibleTestsDestructibleDamageGroupEntity"; + public const string TestBruteDamageGroupId = "TestBrute"; + public const string TestBurnDamageGroupId = "TestBurn"; + public const string TestBluntDamageTypeId = "TestBlunt"; + public const string TestSlashDamageTypeId = "TestSlash"; + public const string TestPiercingDamageTypeId = "TestPiercing"; + public const string TestHeatDamageTypeId = "TestHeat"; + public const string TestShockDamageTypeId = "TestShock"; + public const string TestColdDamageTypeId = "TestCold"; [TestPrototypes] public const string DamagePrototypes = $@" - type: damageType - id: TestBlunt + id: {TestBluntDamageTypeId} name: damage-type-blunt - type: damageType - id: TestSlash + id: {TestSlashDamageTypeId} name: damage-type-slash - type: damageType - id: TestPiercing + id: {TestPiercingDamageTypeId} name: damage-type-piercing - type: damageType - id: TestHeat + id: {TestHeatDamageTypeId} name: damage-type-heat - type: damageType - id: TestShock + id: {TestShockDamageTypeId} name: damage-type-shock - type: damageType - id: TestCold + id: {TestColdDamageTypeId} name: damage-type-cold - type: damageGroup - id: TestBrute + id: {TestBruteDamageGroupId} name: damage-group-brute damageTypes: - - TestBlunt - - TestSlash - - TestPiercing + - {TestBluntDamageTypeId} + - {TestSlashDamageTypeId} + - {TestPiercingDamageTypeId} - type: damageGroup - id: TestBurn + id: {TestBurnDamageGroupId} name: damage-group-burn damageTypes: - - TestHeat - - TestShock - - TestCold + - {TestHeatDamageTypeId} + - {TestShockDamageTypeId} + - {TestColdDamageTypeId} - type: entity id: {SpawnedEntityId} @@ -114,10 +122,10 @@ namespace Content.IntegrationTests.Tests.Destructible !type:AndTrigger triggers: - !type:DamageTypeTrigger - damageType: TestBlunt + damageType: {TestBluntDamageTypeId} damage: 10 - !type:DamageTypeTrigger - damageType: TestSlash + damageType: {TestSlashDamageTypeId} damage: 10 - type: entity @@ -131,10 +139,10 @@ namespace Content.IntegrationTests.Tests.Destructible !type:AndTrigger triggers: - !type:DamageGroupTrigger - damageGroup: TestBrute + damageGroup: {TestBruteDamageGroupId} damage: 10 - !type:DamageGroupTrigger - damageGroup: TestBurn + damageGroup: {TestBurnDamageGroupId} damage: 10"; } } diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs index 80f750c715..af86e406ef 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs @@ -61,7 +61,7 @@ namespace Content.IntegrationTests.Tests.Destructible await server.WaitAssertion(() => { - var bluntDamage = new DamageSpecifier(sPrototypeManager.Index("TestBlunt"), 10); + var bluntDamage = new DamageSpecifier(sPrototypeManager.Index(TestBluntDamageTypeId), 10); sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage, true); diff --git a/Content.IntegrationTests/Tests/Minds/MindTests.cs b/Content.IntegrationTests/Tests/Minds/MindTests.cs index d4d551f4e0..60e98b69fe 100644 --- a/Content.IntegrationTests/Tests/Minds/MindTests.cs +++ b/Content.IntegrationTests/Tests/Minds/MindTests.cs @@ -24,6 +24,8 @@ namespace Content.IntegrationTests.Tests.Minds; [TestFixture] public sealed partial class MindTests { + private static readonly ProtoId BluntDamageType = "Blunt"; + [TestPrototypes] private const string Prototypes = @" - type: entity @@ -144,7 +146,7 @@ public sealed partial class MindTests await server.WaitAssertion(() => { var damageable = entMan.GetComponent(entity); - if (!protoMan.TryIndex("Blunt", out var prototype)) + if (!protoMan.TryIndex(BluntDamageType, out var prototype)) { return; } diff --git a/Content.IntegrationTests/Tests/PostMapInitTest.cs b/Content.IntegrationTests/Tests/PostMapInitTest.cs index 97be2b8705..a7a50a5270 100644 --- a/Content.IntegrationTests/Tests/PostMapInitTest.cs +++ b/Content.IntegrationTests/Tests/PostMapInitTest.cs @@ -77,6 +77,8 @@ namespace Content.IntegrationTests.Tests "Exo", }; + private static readonly ProtoId DoNotMapCategory = "DoNotMap"; + /// /// Asserts that specific files have been saved as grids and not maps. /// @@ -254,7 +256,7 @@ namespace Content.IntegrationTests.Tests return; var yamlEntities = node["entities"]; - if (!protoManager.TryIndex("DoNotMap", out var dnmCategory)) + if (!protoManager.TryIndex(DoNotMapCategory, out var dnmCategory)) return; Assert.Multiple(() => diff --git a/Content.IntegrationTests/Tests/Station/StationJobsTest.cs b/Content.IntegrationTests/Tests/Station/StationJobsTest.cs index d68fdafb76..3fee4a146c 100644 --- a/Content.IntegrationTests/Tests/Station/StationJobsTest.cs +++ b/Content.IntegrationTests/Tests/Station/StationJobsTest.cs @@ -17,8 +17,10 @@ namespace Content.IntegrationTests.Tests.Station; [TestOf(typeof(StationJobsSystem))] public sealed class StationJobsTest { + private const string StationMapId = "FooStation"; + [TestPrototypes] - private const string Prototypes = @" + private const string Prototypes = $@" - type: playTimeTracker id: PlayTimeDummyAssistant @@ -35,13 +37,13 @@ public sealed class StationJobsTest id: PlayTimeDummyChaplain - type: gameMap - id: FooStation + id: {StationMapId} minPlayers: 0 - mapName: FooStation + mapName: {StationMapId} mapPath: /Maps/Test/empty.yml stations: Station: - mapNameTemplate: FooStation + mapNameTemplate: {StationMapId} stationProto: StandardNanotrasenStation components: - type: StationJobs @@ -87,7 +89,7 @@ public sealed class StationJobsTest var server = pair.Server; var prototypeManager = server.ResolveDependency(); - var fooStationProto = prototypeManager.Index("FooStation"); + var fooStationProto = prototypeManager.Index(StationMapId); var entSysMan = server.ResolveDependency().EntitySysManager; var stationJobs = entSysMan.GetEntitySystem(); var stationSystem = entSysMan.GetEntitySystem(); @@ -161,7 +163,7 @@ public sealed class StationJobsTest var server = pair.Server; var prototypeManager = server.ResolveDependency(); - var fooStationProto = prototypeManager.Index("FooStation"); + var fooStationProto = prototypeManager.Index(StationMapId); var entSysMan = server.ResolveDependency().EntitySysManager; var stationJobs = entSysMan.GetEntitySystem(); var stationSystem = entSysMan.GetEntitySystem(); diff --git a/Content.IntegrationTests/Tests/Vending/VendingInteractionTest.cs b/Content.IntegrationTests/Tests/Vending/VendingInteractionTest.cs index bcaf4343b6..3645667737 100644 --- a/Content.IntegrationTests/Tests/Vending/VendingInteractionTest.cs +++ b/Content.IntegrationTests/Tests/Vending/VendingInteractionTest.cs @@ -5,6 +5,7 @@ using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; using Content.Shared.FixedPoint; using Content.Shared.VendingMachines; +using Robust.Shared.Prototypes; namespace Content.IntegrationTests.Tests.Vending; @@ -17,6 +18,7 @@ public sealed class VendingInteractionTest : InteractionTest private const string RestockBoxProtoId = "InteractionTestRestockBox"; private const string RestockBoxOtherProtoId = "InteractionTestRestockBoxOther"; + private static readonly ProtoId TestDamageType = "Blunt"; [TestPrototypes] private const string TestPrototypes = $@" @@ -196,7 +198,7 @@ public sealed class VendingInteractionTest : InteractionTest Assert.That(damageableComp.Damage.GetTotal(), Is.EqualTo(FixedPoint2.Zero), $"{VendingMachineProtoId} started with unexpected damage."); // Damage the vending machine to the point that it breaks - var damageType = ProtoMan.Index("Blunt"); + var damageType = ProtoMan.Index(TestDamageType); var damage = new DamageSpecifier(damageType, FixedPoint2.New(100)); await Server.WaitPost(() => damageableSys.TryChangeDamage(SEntMan.GetEntity(Target), damage, ignoreResistances: true)); await RunTicks(5); diff --git a/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs b/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs index 4644768901..f30eed0651 100644 --- a/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs +++ b/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs @@ -20,6 +20,8 @@ namespace Content.IntegrationTests.Tests [TestOf(typeof(VendingMachineSystem))] public sealed class VendingMachineRestockTest : EntitySystem { + private static readonly ProtoId TestDamageType = "Blunt"; + [TestPrototypes] private const string Prototypes = @" - type: entity @@ -293,7 +295,7 @@ namespace Content.IntegrationTests.Tests "Did not start with zero ramen."); restock = entityManager.SpawnEntity("TestRestockExplode", coordinates); - var damageSpec = new DamageSpecifier(prototypeManager.Index("Blunt"), 100); + var damageSpec = new DamageSpecifier(prototypeManager.Index(TestDamageType), 100); var damageResult = damageableSystem.TryChangeDamage(restock, damageSpec); #pragma warning disable NUnit2045 diff --git a/Content.Tests/Shared/DamageTest.cs b/Content.Tests/Shared/DamageTest.cs index 58fa8fbde3..27543e6533 100644 --- a/Content.Tests/Shared/DamageTest.cs +++ b/Content.Tests/Shared/DamageTest.cs @@ -15,6 +15,11 @@ namespace Content.Tests.Shared [TestOf(typeof(DamageGroupPrototype))] public sealed class DamageTest : ContentUnitTest { + private static readonly ProtoId BruteDamageGroup = "Brute"; + private static readonly ProtoId RadiationDamageType = "Radiation"; + private static readonly ProtoId SlashDamageType = "Slash"; + private static readonly ProtoId PiercingDamageType = "Piercing"; + private IPrototypeManager _prototypeManager; private DamageSpecifier _damageSpec; @@ -29,9 +34,9 @@ namespace Content.Tests.Shared _prototypeManager.ResolveResults(); // Create a damage data set - _damageSpec = new(_prototypeManager.Index("Brute"), 6); - _damageSpec += new DamageSpecifier(_prototypeManager.Index("Radiation"), 3); - _damageSpec += new DamageSpecifier(_prototypeManager.Index("Slash"), -1); // already exists in brute + _damageSpec = new(_prototypeManager.Index(BruteDamageGroup), 6); + _damageSpec += new DamageSpecifier(_prototypeManager.Index(RadiationDamageType), 3); + _damageSpec += new DamageSpecifier(_prototypeManager.Index(SlashDamageType), -1); // already exists in brute } //Check that DamageSpecifier will split groups and can do arithmetic operations @@ -100,7 +105,7 @@ namespace Content.Tests.Shared Assert.That(damage, Is.EqualTo(FixedPoint2.New(3))); // Lets also test the constructor with damage types and damage groups works properly. - damageSpec = new(_prototypeManager.Index("Brute"), 4); + damageSpec = new(_prototypeManager.Index(BruteDamageGroup), 4); Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage)); Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.33))); Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage)); @@ -108,7 +113,7 @@ namespace Content.Tests.Shared Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.34))); // doesn't divide evenly, so the 0.01 goes to the last one - damageSpec = new(_prototypeManager.Index("Piercing"), 4); + damageSpec = new(_prototypeManager.Index(PiercingDamageType), 4); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); Assert.That(damage, Is.EqualTo(FixedPoint2.New(4))); } @@ -121,7 +126,7 @@ namespace Content.Tests.Shared DamageSpecifier damageSpec = 10 * new DamageSpecifier(_damageSpec); // Create a modifier set - var modifierSet = _prototypeManager.Index("ModifierTestSet"); + var modifierSet = _prototypeManager.Index(ModifierTestSetId); //damage is initially 20 / 20 / 10 / 30 //Each time we subtract -5 / 0 / 8 / 0.5 @@ -142,8 +147,10 @@ namespace Content.Tests.Shared Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(65.62))); } + private const string ModifierTestSetId = "ModifierTestSet"; + // Default damage Yaml - private string _damagePrototypes = @" + private readonly string _damagePrototypes = $@" - type: damageType id: Blunt name: damage-type-blunt @@ -268,7 +275,7 @@ namespace Content.Tests.Shared Blunt: 5 - type: damageModifierSet - id: ModifierTestSet + id: {ModifierTestSetId} coefficients: Piercing: -2 Slash: 3 diff --git a/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs b/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs index b07b18efa0..77f001bfe1 100644 --- a/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs +++ b/Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs @@ -12,6 +12,8 @@ namespace Content.Tests.Shared; [TestOf(typeof(LocalizedDatasetPrototype))] public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest { + private const string TestDatasetId = "Test"; + private IPrototypeManager _prototypeManager; [OneTimeSetUp] @@ -24,9 +26,9 @@ public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest _prototypeManager.ResolveResults(); } - private const string TestPrototypes = @" + private const string TestPrototypes = $@" - type: localizedDataset - id: Test + id: {TestDatasetId} values: prefix: test-dataset- count: 4 @@ -35,7 +37,7 @@ public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest [Test] public void LocalizedDatasetTest() { - var testPrototype = _prototypeManager.Index("Test"); + var testPrototype = _prototypeManager.Index(TestDatasetId); var values = new ValueList(); foreach (var value in testPrototype.Values) {