WireLayoutTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Content.Server.Doors;
  2. using Content.Server.Power;
  3. using Content.Server.Wires;
  4. using Robust.Shared.GameObjects;
  5. using Robust.Shared.IoC;
  6. using Robust.Shared.Map;
  7. namespace Content.IntegrationTests.Tests.Wires;
  8. [TestFixture]
  9. [Parallelizable(ParallelScope.All)]
  10. [TestOf(typeof(WiresSystem))]
  11. public sealed class WireLayoutTest
  12. {
  13. [TestPrototypes]
  14. public const string Prototypes = """
  15. - type: wireLayout
  16. id: WireLayoutTest
  17. dummyWires: 2
  18. wires:
  19. - !type:PowerWireAction
  20. - !type:DoorBoltWireAction
  21. - type: wireLayout
  22. id: WireLayoutTest2
  23. parent: WireLayoutTest
  24. wires:
  25. - !type:PowerWireAction
  26. - type: wireLayout
  27. id: WireLayoutTest3
  28. parent: WireLayoutTest
  29. - type: entity
  30. id: WireLayoutTest
  31. components:
  32. - type: Wires
  33. layoutId: WireLayoutTest
  34. - type: entity
  35. id: WireLayoutTest2
  36. components:
  37. - type: Wires
  38. layoutId: WireLayoutTest2
  39. - type: entity
  40. id: WireLayoutTest3
  41. components:
  42. - type: Wires
  43. layoutId: WireLayoutTest3
  44. """;
  45. [Test]
  46. public async Task TestLayoutInheritance()
  47. {
  48. await using var pair = await PoolManager.GetServerClient();
  49. var server = pair.Server;
  50. var testMap = await pair.CreateTestMap();
  51. await server.WaitAssertion(() =>
  52. {
  53. var wires = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<WiresSystem>();
  54. // Need to spawn these entities to make sure the wire layouts are initialized.
  55. var ent1 = SpawnWithComp<WiresComponent>(server.EntMan, "WireLayoutTest", testMap.MapCoords);
  56. var ent2 = SpawnWithComp<WiresComponent>(server.EntMan, "WireLayoutTest2", testMap.MapCoords);
  57. var ent3 = SpawnWithComp<WiresComponent>(server.EntMan, "WireLayoutTest3", testMap.MapCoords);
  58. // Assert.That(wires.TryGetLayout("WireLayoutTest", out var layout1));
  59. // Assert.That(wires.TryGetLayout("WireLayoutTest2", out var layout2));
  60. // Assert.That(wires.TryGetLayout("WireLayoutTest3", out var layout3));
  61. Assert.Multiple(() =>
  62. {
  63. // Entity 1.
  64. Assert.That(ent1.Comp.WiresList, Has.Count.EqualTo(4));
  65. Assert.That(ent1.Comp.WiresList, Has.Exactly(2).With.Property("Action").Null, "2 dummy wires");
  66. Assert.That(ent1.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<PowerWireAction>(), "1 power wire");
  67. Assert.That(ent1.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<DoorBoltWireAction>(), "1 door bolt wire");
  68. Assert.That(ent2.Comp.WiresList, Has.Count.EqualTo(5));
  69. Assert.That(ent2.Comp.WiresList, Has.Exactly(2).With.Property("Action").Null, "2 dummy wires");
  70. Assert.That(ent2.Comp.WiresList, Has.Exactly(2).With.Property("Action").InstanceOf<PowerWireAction>(), "2 power wire");
  71. Assert.That(ent2.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<DoorBoltWireAction>(), "1 door bolt wire");
  72. Assert.That(ent3.Comp.WiresList, Has.Count.EqualTo(4));
  73. Assert.That(ent3.Comp.WiresList, Has.Exactly(2).With.Property("Action").Null, "2 dummy wires");
  74. Assert.That(ent3.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<PowerWireAction>(), "1 power wire");
  75. Assert.That(ent3.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<DoorBoltWireAction>(), "1 door bolt wire");
  76. });
  77. });
  78. await pair.CleanReturnAsync();
  79. }
  80. private static Entity<T> SpawnWithComp<T>(IEntityManager entityManager, string prototype, MapCoordinates coords)
  81. where T : IComponent, new()
  82. {
  83. var ent = entityManager.Spawn(prototype, coords);
  84. var comp = entityManager.EnsureComponent<T>(ent);
  85. return new Entity<T>(ent, comp);
  86. }
  87. }