1
0

MachineBoardTest.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Content.Server.Construction.Components;
  4. using Content.Shared.Construction.Components;
  5. using Robust.Shared.GameObjects;
  6. using Robust.Shared.Prototypes;
  7. namespace Content.IntegrationTests.Tests;
  8. public sealed class MachineBoardTest
  9. {
  10. /// <summary>
  11. /// A list of machine boards that can be ignored by this test.
  12. /// </summary>
  13. private readonly HashSet<string> _ignoredPrototypes = new()
  14. {
  15. //These have their own construction thing going on here
  16. "MachineParticleAcceleratorEndCapCircuitboard",
  17. "MachineParticleAcceleratorFuelChamberCircuitboard",
  18. "MachineParticleAcceleratorFuelChamberCircuitboard",
  19. "MachineParticleAcceleratorPowerBoxCircuitboard",
  20. "MachineParticleAcceleratorEmitterStarboardCircuitboard",
  21. "MachineParticleAcceleratorEmitterForeCircuitboard",
  22. "MachineParticleAcceleratorEmitterPortCircuitboard",
  23. "ParticleAcceleratorComputerCircuitboard"
  24. };
  25. /// <summary>
  26. /// Ensures that every single machine board's corresponding entity
  27. /// is a machine and can be properly deconstructed.
  28. /// </summary>
  29. [Test]
  30. public async Task TestMachineBoardHasValidMachine()
  31. {
  32. await using var pair = await PoolManager.GetServerClient();
  33. var server = pair.Server;
  34. var protoMan = server.ResolveDependency<IPrototypeManager>();
  35. var compFact = server.ResolveDependency<IComponentFactory>();
  36. await server.WaitAssertion(() =>
  37. {
  38. foreach (var p in protoMan.EnumeratePrototypes<EntityPrototype>()
  39. .Where(p => !p.Abstract)
  40. .Where(p => !pair.IsTestPrototype(p))
  41. .Where(p => !_ignoredPrototypes.Contains(p.ID)))
  42. {
  43. if (!p.TryGetComponent<MachineBoardComponent>(out var mbc, compFact))
  44. continue;
  45. var mId = mbc.Prototype;
  46. Assert.Multiple(() =>
  47. {
  48. Assert.That(protoMan.TryIndex<EntityPrototype>(mId, out var mProto),
  49. $"Machine board {p.ID}'s corresponding machine has an invalid prototype.");
  50. Assert.That(mProto.TryGetComponent<MachineComponent>(out var mComp, compFact),
  51. $"Machine board {p.ID}'s corresponding machine {mId} does not have MachineComponent");
  52. Assert.That(mComp.Board, Is.EqualTo(p.ID),
  53. $"Machine {mId}'s BoardPrototype is not equal to it's corresponding machine board, {p.ID}");
  54. });
  55. }
  56. });
  57. await pair.CleanReturnAsync();
  58. }
  59. /// <summary>
  60. /// Ensures that every single computer board's corresponding entity
  61. /// is a computer that can be properly deconstructed to the correct board
  62. /// </summary>
  63. [Test]
  64. public async Task TestComputerBoardHasValidComputer()
  65. {
  66. await using var pair = await PoolManager.GetServerClient();
  67. var server = pair.Server;
  68. var protoMan = server.ResolveDependency<IPrototypeManager>();
  69. var compFact = server.ResolveDependency<IComponentFactory>();
  70. await server.WaitAssertion(() =>
  71. {
  72. foreach (var p in protoMan.EnumeratePrototypes<EntityPrototype>()
  73. .Where(p => !p.Abstract)
  74. .Where(p => !pair.IsTestPrototype(p))
  75. .Where(p => !_ignoredPrototypes.Contains(p.ID)))
  76. {
  77. if (!p.TryGetComponent<ComputerBoardComponent>(out var cbc, compFact))
  78. continue;
  79. var cId = cbc.Prototype;
  80. Assert.Multiple(() =>
  81. {
  82. Assert.That(cId, Is.Not.Null, $"Computer board \"{p.ID}\" does not have a corresponding computer.");
  83. Assert.That(protoMan.TryIndex<EntityPrototype>(cId, out var cProto),
  84. $"Computer board \"{p.ID}\"'s corresponding computer has an invalid prototype.");
  85. Assert.That(cProto.TryGetComponent<ComputerComponent>(out var cComp, compFact),
  86. $"Computer board {p.ID}'s corresponding computer \"{cId}\" does not have ComputerComponent");
  87. Assert.That(cComp.BoardPrototype, Is.EqualTo(p.ID),
  88. $"Computer \"{cId}\"'s BoardPrototype is not equal to it's corresponding computer board, \"{p.ID}\"");
  89. });
  90. }
  91. });
  92. await pair.CleanReturnAsync();
  93. }
  94. /// <summary>
  95. /// Ensures that every single computer board's corresponding entity
  96. /// is a computer that can be properly deconstructed to the correct board
  97. /// </summary>
  98. [Test]
  99. public async Task TestValidateBoardComponentRequirements()
  100. {
  101. await using var pair = await PoolManager.GetServerClient();
  102. var server = pair.Server;
  103. var entMan = server.ResolveDependency<IEntityManager>();
  104. var protoMan = server.ResolveDependency<IPrototypeManager>();
  105. await server.WaitAssertion(() =>
  106. {
  107. foreach (var p in protoMan.EnumeratePrototypes<EntityPrototype>()
  108. .Where(p => !p.Abstract)
  109. .Where(p => !pair.IsTestPrototype(p))
  110. .Where(p => !_ignoredPrototypes.Contains(p.ID)))
  111. {
  112. if (!p.TryGetComponent<MachineBoardComponent>(out var board, entMan.ComponentFactory))
  113. continue;
  114. Assert.Multiple(() =>
  115. {
  116. foreach (var component in board.ComponentRequirements.Keys)
  117. {
  118. Assert.That(entMan.ComponentFactory.TryGetRegistration(component, out _), $"Invalid component requirement {component} specified on machine board entity {p}");
  119. }
  120. });
  121. }
  122. });
  123. await pair.CleanReturnAsync();
  124. }
  125. }