From 1f1e95f5351decadeae653c048974b565cde67b7 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Fri, 21 Aug 2020 14:54:50 +0200 Subject: [PATCH] Add integration test for entity deletion. --- .../Tests/DeleteInventoryTest.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Content.IntegrationTests/Tests/DeleteInventoryTest.cs diff --git a/Content.IntegrationTests/Tests/DeleteInventoryTest.cs b/Content.IntegrationTests/Tests/DeleteInventoryTest.cs new file mode 100644 index 0000000000..4c3782b7fe --- /dev/null +++ b/Content.IntegrationTests/Tests/DeleteInventoryTest.cs @@ -0,0 +1,51 @@ +using System.Threading.Tasks; +using Content.Server.GameObjects.Components.GUI; +using Content.Server.GameObjects.Components.Items.Clothing; +using NUnit.Framework; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Map; +using Robust.Shared.IoC; +using Robust.Shared.Map; +using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; + +namespace Content.IntegrationTests.Tests +{ + [TestFixture] + public class DeleteInventoryTest : ContentIntegrationTest + { + // Test that when deleting an entity with an InventoryComponent, + // any equipped items also get deleted. + [Test] + public async Task Test() + { + var server = StartServerDummyTicker(); + + server.Assert(() => + { + // Spawn everything. + var mapMan = IoCManager.Resolve(); + + mapMan.CreateNewMapEntity(MapId.Nullspace); + + var entMgr = IoCManager.Resolve(); + var container = entMgr.SpawnEntity(null, MapCoordinates.Nullspace); + var inv = container.AddComponent(); + + var child = entMgr.SpawnEntity(null, MapCoordinates.Nullspace); + var item = child.AddComponent(); + item.SlotFlags = SlotFlags.HEAD; + + // Equip item. + Assert.That(inv.Equip(Slots.HEAD, item, false), Is.True); + + // Delete parent. + container.Delete(); + + // Assert that child item was also deleted. + Assert.That(item.Deleted, Is.True); + }); + + await server.WaitIdleAsync(); + } + } +}