InventoryHelpersTest.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Content.Server.Stunnable;
  2. using Content.Shared.Inventory;
  3. using Robust.Shared.GameObjects;
  4. using Robust.Shared.IoC;
  5. using Robust.Shared.Map;
  6. namespace Content.IntegrationTests.Tests
  7. {
  8. [TestFixture]
  9. public sealed class InventoryHelpersTest
  10. {
  11. [TestPrototypes]
  12. private const string Prototypes = @"
  13. - type: entity
  14. name: InventoryStunnableDummy
  15. id: InventoryStunnableDummy
  16. components:
  17. - type: Inventory
  18. - type: ContainerContainer
  19. - type: StatusEffects
  20. allowed:
  21. - Stun
  22. - type: entity
  23. name: InventoryJumpsuitJanitorDummy
  24. id: InventoryJumpsuitJanitorDummy
  25. components:
  26. - type: Clothing
  27. slots: [innerclothing]
  28. - type: entity
  29. name: InventoryIDCardDummy
  30. id: InventoryIDCardDummy
  31. components:
  32. - type: Clothing
  33. QuickEquip: false
  34. slots:
  35. - idcard
  36. - type: Pda
  37. ";
  38. [Test]
  39. public async Task SpawnItemInSlotTest()
  40. {
  41. await using var pair = await PoolManager.GetServerClient();
  42. var server = pair.Server;
  43. var sEntities = server.ResolveDependency<IEntityManager>();
  44. var systemMan = sEntities.EntitySysManager;
  45. await server.WaitAssertion(() =>
  46. {
  47. var human = sEntities.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace);
  48. var invSystem = systemMan.GetEntitySystem<InventorySystem>();
  49. Assert.Multiple(() =>
  50. {
  51. // Can't do the test if this human doesn't have the slots for it.
  52. Assert.That(invSystem.HasSlot(human, "jumpsuit"));
  53. Assert.That(invSystem.HasSlot(human, "id"));
  54. });
  55. Assert.That(invSystem.SpawnItemInSlot(human, "jumpsuit", "InventoryJumpsuitJanitorDummy", true));
  56. #pragma warning disable NUnit2045
  57. // Do we actually have the uniform equipped?
  58. Assert.That(invSystem.TryGetSlotEntity(human, "jumpsuit", out var uniform));
  59. Assert.That(sEntities.GetComponent<MetaDataComponent>(uniform.Value).EntityPrototype is
  60. {
  61. ID: "InventoryJumpsuitJanitorDummy"
  62. });
  63. #pragma warning restore NUnit2045
  64. systemMan.GetEntitySystem<StunSystem>().TryStun(human, TimeSpan.FromSeconds(1f), true);
  65. #pragma warning disable NUnit2045
  66. // Since the mob is stunned, they can't equip this.
  67. Assert.That(invSystem.SpawnItemInSlot(human, "id", "InventoryIDCardDummy", true), Is.False);
  68. // Make sure we don't have the ID card equipped.
  69. Assert.That(invSystem.TryGetSlotEntity(human, "item", out _), Is.False);
  70. // Let's try skipping the interaction check and see if it equips it!
  71. Assert.That(invSystem.SpawnItemInSlot(human, "id", "InventoryIDCardDummy", true, true));
  72. Assert.That(invSystem.TryGetSlotEntity(human, "id", out var idUid));
  73. Assert.That(sEntities.GetComponent<MetaDataComponent>(idUid.Value).EntityPrototype is
  74. {
  75. ID: "InventoryIDCardDummy"
  76. });
  77. #pragma warning restore NUnit2045
  78. sEntities.DeleteEntity(human);
  79. });
  80. await pair.CleanReturnAsync();
  81. }
  82. }
  83. }