]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Validate `ProtoId`s in tests (#38745)
authorTayrtahn <tayrtahn@gmail.com>
Fri, 4 Jul 2025 20:48:55 +0000 (16:48 -0400)
committerGitHub <noreply@github.com>
Fri, 4 Jul 2025 20:48:55 +0000 (22:48 +0200)
* 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

17 files changed:
Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs
Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs
Content.IntegrationTests/Tests/Commands/SuicideCommandTests.cs
Content.IntegrationTests/Tests/Construction/Interaction/WindowRepair.cs
Content.IntegrationTests/Tests/Damageable/DamageableTest.cs
Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs
Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs
Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs
Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs
Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs
Content.IntegrationTests/Tests/Minds/MindTests.cs
Content.IntegrationTests/Tests/PostMapInitTest.cs
Content.IntegrationTests/Tests/Station/StationJobsTest.cs
Content.IntegrationTests/Tests/Vending/VendingInteractionTest.cs
Content.IntegrationTests/Tests/VendingMachineRestockTest.cs
Content.Tests/Shared/DamageTest.cs
Content.Tests/Shared/LocalizedDatasetPrototypeTest.cs

index 064b4f9a2d9115fc3c925d157d267bef57e2c994..b74c35ba11170f25e49b7475c96ed1a577da6aab 100644 (file)
@@ -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<IPrototypeManager>();
             AtmosAlarmThreshold threshold = default!;
 
-            var proto = prototypeManager.Index<AtmosAlarmThresholdPrototype>("AlarmThresholdTestDummy");
+            var proto = prototypeManager.Index<AtmosAlarmThresholdPrototype>(AlarmThresholdTestDummyId);
             threshold = new(proto);
 
             await server.WaitAssertion(() =>
index cfc80073066979628e6168479ca755e2e6dd247f..e4ec7e907a494d03d4628831b67895f4c75db17d 100644 (file)
@@ -15,6 +15,8 @@ namespace Content.IntegrationTests.Tests.Commands
     [TestOf(typeof(RejuvenateSystem))]
     public sealed class RejuvenateTest
     {
+        private static readonly ProtoId<DamageGroupPrototype> 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<DamageGroupPrototype>("Toxin"), FixedPoint2.New(10000000));
+                DamageSpecifier damage = new(prototypeManager.Index(TestDamageGroup), FixedPoint2.New(10000000));
 
                 damSystem.TryChangeDamage(human, damage, true);
 
index b53b87dd5c1c7713c716479a360f263f13ce725b..61b8d544484dfdc6f2e7a68a91dbe242a28fe9ab 100644 (file)
@@ -53,6 +53,8 @@ public sealed class SuicideCommandTests
   components:
   - type: MaterialReclaimer";
     private static readonly ProtoId<TagPrototype> CannotSuicideTag = "CannotSuicide";
+    private static readonly ProtoId<DamageTypePrototype> DamageType = "Slash";
+
     /// <summary>
     /// 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<MobThresholdsComponent>(player);
             damageableComp = entManager.GetComponent<DamageableComponent>(player);
 
-            if (protoMan.TryIndex<DamageTypePrototype>("Slash", out var slashProto))
+            if (protoMan.TryIndex(DamageType, out var slashProto))
                 damageableSystem.TryChangeDamage(player, new DamageSpecifier(slashProto, FixedPoint2.New(46.5)));
         });
 
index 6eea519af3b50729654d8df0252022bbaa668761..192604edfd54ae1cc96fc869a73a7dd389ea185c 100644 (file)
@@ -8,6 +8,8 @@ namespace Content.IntegrationTests.Tests.Construction.Interaction;
 
 public sealed class WindowRepair : InteractionTest
 {
+    private static readonly ProtoId<DamageTypePrototype> BluntDamageType = "Blunt";
+
     [Test]
     public async Task RepairReinforcedWindow()
     {
@@ -16,7 +18,7 @@ public sealed class WindowRepair : InteractionTest
         // Damage the entity.
         var sys = SEntMan.System<DamageableSystem>();
         var comp = Comp<DamageableComponent>();
-        var damageType = Server.ResolveDependency<IPrototypeManager>().Index<DamageTypePrototype>("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));
index 69069fc82fee28573379dc0d9ca05fd447ce42b1..f610ab732e99853a8830e682025cf073878d1d5d 100644 (file)
@@ -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<DamageableComponent>(sDamageableEntity);
                 sDamageableSystem = sEntitySystemManager.GetEntitySystem<DamageableSystem>();
 
-                group1 = sPrototypeManager.Index<DamageGroupPrototype>("TestGroup1");
-                group2 = sPrototypeManager.Index<DamageGroupPrototype>("TestGroup2");
-                group3 = sPrototypeManager.Index<DamageGroupPrototype>("TestGroup3");
+                group1 = sPrototypeManager.Index<DamageGroupPrototype>(TestGroup1);
+                group2 = sPrototypeManager.Index<DamageGroupPrototype>(TestGroup2);
+                group3 = sPrototypeManager.Index<DamageGroupPrototype>(TestGroup3);
 
-                type1 = sPrototypeManager.Index<DamageTypePrototype>("TestDamage1");
-                type2a = sPrototypeManager.Index<DamageTypePrototype>("TestDamage2a");
-                type2b = sPrototypeManager.Index<DamageTypePrototype>("TestDamage2b");
-                type3a = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3a");
-                type3b = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3b");
-                type3c = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3c");
+                type1 = sPrototypeManager.Index<DamageTypePrototype>(TestDamage1);
+                type2a = sPrototypeManager.Index<DamageTypePrototype>(TestDamage2a);
+                type2b = sPrototypeManager.Index<DamageTypePrototype>(TestDamage2b);
+                type3a = sPrototypeManager.Index<DamageTypePrototype>(TestDamage3a);
+                type3b = sPrototypeManager.Index<DamageTypePrototype>(TestDamage3b);
+                type3c = sPrototypeManager.Index<DamageTypePrototype>(TestDamage3c);
             });
 
             await server.WaitRunTicks(5);
index d37de7a50448294351b5c9bbac33fd09e56bf038..0da07ad5a16a94cac23496a82875b1ead36f17f9 100644 (file)
@@ -54,8 +54,8 @@ namespace Content.IntegrationTests.Tests.Destructible
 
             await server.WaitAssertion(() =>
             {
-                var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
-                var burnDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBurn");
+                var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>(TestBruteDamageGroupId);
+                var burnDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>(TestBurnDamageGroupId);
 
                 DamageSpecifier bruteDamage = new(bruteDamageGroup, FixedPoint2.New(5));
                 DamageSpecifier burnDamage = new(burnDamageGroup, FixedPoint2.New(5));
index 69891cbd895e955715427dec7ebc9daa40a46ff4..ccd459668b2bf4b2c88c76ed51c2a9a0b99cd920 100644 (file)
@@ -49,8 +49,8 @@ namespace Content.IntegrationTests.Tests.Destructible
 
             await server.WaitAssertion(() =>
             {
-                var bluntDamageType = protoManager.Index<DamageTypePrototype>("TestBlunt");
-                var slashDamageType = protoManager.Index<DamageTypePrototype>("TestSlash");
+                var bluntDamageType = protoManager.Index<DamageTypePrototype>(TestBluntDamageTypeId);
+                var slashDamageType = protoManager.Index<DamageTypePrototype>(TestSlashDamageTypeId);
 
                 var bluntDamage = new DamageSpecifier(bluntDamageType, 5);
                 var slashDamage = new DamageSpecifier(slashDamageType, 5);
index a50238d8f50d720b4fc6dd1df4b201fae21669c3..4e169e7dfa58f043731f26bc1c7fe9f7eb212a79 100644 (file)
@@ -39,7 +39,7 @@ namespace Content.IntegrationTests.Tests.Destructible
             await server.WaitAssertion(() =>
             {
                 var coordinates = sEntityManager.GetComponent<TransformComponent>(sDestructibleEntity).Coordinates;
-                var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
+                var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>(TestBruteDamageGroupId);
                 DamageSpecifier bruteDamage = new(bruteDamageGroup, 50);
 
 #pragma warning disable NUnit2045 // Interdependent assertions.
index 7ff92423984ffab4f7b9924c7776735a183e4764..872e414ac358dbb61c7ea0cbb03def8bb5b8954a 100644 (file)
@@ -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";
     }
 }
index 80f750c715c1d89caec54728966ff3ec5d5c9b52..af86e406efd01702d14cd1b5344e30d48471a635 100644 (file)
@@ -61,7 +61,7 @@ namespace Content.IntegrationTests.Tests.Destructible
 
             await server.WaitAssertion(() =>
             {
-                var bluntDamage = new DamageSpecifier(sPrototypeManager.Index<DamageTypePrototype>("TestBlunt"), 10);
+                var bluntDamage = new DamageSpecifier(sPrototypeManager.Index<DamageTypePrototype>(TestBluntDamageTypeId), 10);
 
                 sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage, true);
 
index d4d551f4e0aad0573390ec96f256c3edfa3b0831..60e98b69fe25048347ed580653b18e4068f79ba8 100644 (file)
@@ -24,6 +24,8 @@ namespace Content.IntegrationTests.Tests.Minds;
 [TestFixture]
 public sealed partial class MindTests
 {
+    private static readonly ProtoId<DamageTypePrototype> 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<DamageableComponent>(entity);
-            if (!protoMan.TryIndex<DamageTypePrototype>("Blunt", out var prototype))
+            if (!protoMan.TryIndex(BluntDamageType, out var prototype))
             {
                 return;
             }
index 97be2b87055f3c3da64103c75f6830aa63d27fc6..a7a50a5270fb5e603684aaba7ecee505428c8140 100644 (file)
@@ -77,6 +77,8 @@ namespace Content.IntegrationTests.Tests
             "Exo",
         };
 
+        private static readonly ProtoId<EntityCategoryPrototype> DoNotMapCategory = "DoNotMap";
+
         /// <summary>
         /// Asserts that specific files have been saved as grids and not maps.
         /// </summary>
@@ -254,7 +256,7 @@ namespace Content.IntegrationTests.Tests
                 return;
 
             var yamlEntities = node["entities"];
-            if (!protoManager.TryIndex<EntityCategoryPrototype>("DoNotMap", out var dnmCategory))
+            if (!protoManager.TryIndex(DoNotMapCategory, out var dnmCategory))
                 return;
 
             Assert.Multiple(() =>
index d68fdafb769e51e3173b30544a636d07dd8ed975..3fee4a146ce0f5c97dd8a3dad8bccc78e890969a 100644 (file)
@@ -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<IPrototypeManager>();
-        var fooStationProto = prototypeManager.Index<GameMapPrototype>("FooStation");
+        var fooStationProto = prototypeManager.Index<GameMapPrototype>(StationMapId);
         var entSysMan = server.ResolveDependency<IEntityManager>().EntitySysManager;
         var stationJobs = entSysMan.GetEntitySystem<StationJobsSystem>();
         var stationSystem = entSysMan.GetEntitySystem<StationSystem>();
@@ -161,7 +163,7 @@ public sealed class StationJobsTest
         var server = pair.Server;
 
         var prototypeManager = server.ResolveDependency<IPrototypeManager>();
-        var fooStationProto = prototypeManager.Index<GameMapPrototype>("FooStation");
+        var fooStationProto = prototypeManager.Index<GameMapPrototype>(StationMapId);
         var entSysMan = server.ResolveDependency<IEntityManager>().EntitySysManager;
         var stationJobs = entSysMan.GetEntitySystem<StationJobsSystem>();
         var stationSystem = entSysMan.GetEntitySystem<StationSystem>();
index bcaf4343b62237d4d17439f57618ee3f05161472..3645667737a03d35b2413693b354afd60fbe7e92 100644 (file)
@@ -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<DamageTypePrototype> 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<DamageTypePrototype>("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);
index 46447689010f361f52a2e76c3d904cbbabc82a57..f30eed0651e977c54de7ccc60b66dd6f5e7e114f 100644 (file)
@@ -20,6 +20,8 @@ namespace Content.IntegrationTests.Tests
     [TestOf(typeof(VendingMachineSystem))]
     public sealed class VendingMachineRestockTest : EntitySystem
     {
+        private static readonly ProtoId<DamageTypePrototype> 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<DamageTypePrototype>("Blunt"), 100);
+                var damageSpec = new DamageSpecifier(prototypeManager.Index(TestDamageType), 100);
                 var damageResult = damageableSystem.TryChangeDamage(restock, damageSpec);
 
 #pragma warning disable NUnit2045
index 58fa8fbde39dcc81720fc18a2c2c15930ce0a87a..27543e653334981803f171734411552927ca0c77 100644 (file)
@@ -15,6 +15,11 @@ namespace Content.Tests.Shared
     [TestOf(typeof(DamageGroupPrototype))]
     public sealed class DamageTest : ContentUnitTest
     {
+        private static readonly ProtoId<DamageGroupPrototype> BruteDamageGroup = "Brute";
+        private static readonly ProtoId<DamageTypePrototype> RadiationDamageType = "Radiation";
+        private static readonly ProtoId<DamageTypePrototype> SlashDamageType = "Slash";
+        private static readonly ProtoId<DamageTypePrototype> 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<DamageGroupPrototype>("Brute"), 6);
-            _damageSpec += new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Radiation"), 3);
-            _damageSpec += new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("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<DamageGroupPrototype>("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<DamageTypePrototype>("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<DamageModifierSetPrototype>("ModifierTestSet");
+            var modifierSet = _prototypeManager.Index<DamageModifierSetPrototype>(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
index b07b18efa0a99668c94c8277f0961ffafe4530e7..77f001bfe1cad803fae3e86e686a6450bb564723 100644 (file)
@@ -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<LocalizedDatasetPrototype>("Test");
+        var testPrototype = _prototypeManager.Index<LocalizedDatasetPrototype>(TestDatasetId);
         var values = new ValueList<string>();
         foreach (var value in testPrototype.Values)
         {