Files
crystall-punk-14/Content.IntegrationTests/Tests/InventoryHelpersTest.cs

100 lines
3.4 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
2021-06-09 22:19:39 +02:00
using Content.Server.Inventory;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Server.Stunnable;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
2021-06-09 22:19:39 +02:00
using static Content.Shared.Inventory.EquipmentSlotDefines;
namespace Content.IntegrationTests.Tests
{
[TestFixture]
[TestOf(typeof(InventoryHelpers))]
public class InventoryHelpersTest : ContentIntegrationTest
{
private const string Prototypes = @"
- type: entity
name: InventoryStunnableDummy
id: InventoryStunnableDummy
components:
- type: Inventory
- type: StatusEffects
allowed:
- Stun
- type: entity
name: InventoryJumpsuitJanitorDummy
id: InventoryJumpsuitJanitorDummy
components:
- type: Clothing
Slots: [innerclothing]
- type: entity
name: InventoryIDCardDummy
id: InventoryIDCardDummy
components:
- type: Clothing
QuickEquip: false
Slots:
- idcard
- type: PDA
";
[Test]
public async Task SpawnItemInSlotTest()
{
var options = new ServerIntegrationOptions {ExtraPrototypes = Prototypes};
Add test pooling (#4961) * Add test pooling * WIP test pooling changes * Fix Destructible tests * Don't pool unpooled or dummy ticker instances * Change ServerPathfindingDebugSystem to replace existing entries * Fix SaveLoadSaveTest comment * Don't pool StartTest * Comment out global setup * Fix puddle tests * Move SolarPanelComponent initialize to PowerSolarSystem OnMapInit * Update RobustToolbox * Finish fixing tests, make test threads background threads * Bring back pooling * Fix nullable * Update RobustToolbox * Set cvars on server return * Un-pool tests with custom cvars * Update RobustToolbox * Update RobustToolbox * Change where the main tile coordinates are * Remove DisposalUnitTest grid check * Fix test pooling being a fickle bitch * Fix EntitySystemExtensionsTest * Update RobustToolbox * Update RobustToolbox * Make nullable pool settings true * Update RobustToolbox * Wait other way around * We are unitystation now * Update RobustToolbox * Create global setup * Pool some more tests * Fix not properly disconnecting clients before restarting the round * Give more info on ran tests * Standardize default test cvars * Update RobustToolbox * Update RobustToolbox * Pool clients * Fix test order issue * Fix cvars in character creation test not being set properly * Update RobustToolbox * Update RobustToolbox * Rider shut * Update RobustToolbox * Format tests ran better * Update RobustToolbox * Reset RobustToolbox * Reset RobustToolbox harder * Fix one instance of test order causing destructible tests to fail
2021-11-06 11:49:59 +01:00
var server = StartServer(options);
2021-12-05 18:09:01 +01:00
await server.WaitIdleAsync();
var sEntities = server.ResolveDependency<IEntityManager>();
EntityUid human = default;
InventoryComponent inventory = null;
2021-12-05 18:09:01 +01:00
await server.WaitAssertion(() =>
{
var mapMan = IoCManager.Resolve<IMapManager>();
mapMan.CreateNewMapEntity(MapId.Nullspace);
2021-12-05 18:09:01 +01:00
human = sEntities.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace);
inventory = sEntities.GetComponent<InventoryComponent>(human);
// Can't do the test if this human doesn't have the slots for it.
Assert.That(inventory.HasSlot(Slots.INNERCLOTHING));
Assert.That(inventory.HasSlot(Slots.IDCARD));
Assert.That(inventory.SpawnItemInSlot(Slots.INNERCLOTHING, "InventoryJumpsuitJanitorDummy", true));
// Do we actually have the uniform equipped?
Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform));
2021-12-05 18:09:01 +01:00
Assert.That(sEntities.GetComponent<MetaDataComponent>(uniform.Owner).EntityPrototype is
{
ID: "InventoryJumpsuitJanitorDummy"
});
Merge branch 'master' into 2021-12-03-remove-IEntity-komm-süsser-todd # Conflicts: # Content.Client/Crayon/CrayonDecalVisualizer.cs # Content.Client/Tabletop/TabletopSystem.cs # Content.IntegrationTests/Tests/InventoryHelpersTest.cs # Content.Server/AI/EntitySystems/AiSystem.cs # Content.Server/AI/Utility/AiLogic/UtilityAI.cs # Content.Server/AME/AMENodeGroup.cs # Content.Server/Administration/AdminVerbSystem.cs # Content.Server/Body/Systems/RespiratorSystem.cs # Content.Server/Chemistry/Components/InjectorComponent.cs # Content.Server/Chemistry/TileReactions/CleanTileReaction.cs # Content.Server/Chemistry/TileReactions/SpillTileReaction.cs # Content.Server/Crayon/CrayonComponent.cs # Content.Server/Doors/Components/ServerDoorComponent.cs # Content.Server/Explosion/EntitySystems/TriggerSystem.cs # Content.Server/Fluids/Components/MopComponent.cs # Content.Server/Fluids/Components/SpillExtensions.cs # Content.Server/Fluids/EntitySystems/PuddleSystem.cs # Content.Server/Instruments/InstrumentSystem.cs # Content.Server/Nutrition/EntitySystems/DrinkSystem.cs # Content.Server/Nutrition/EntitySystems/FoodSystem.cs # Content.Server/PneumaticCannon/PneumaticCannonSystem.cs # Content.Server/Storage/Components/EntityStorageComponent.cs # Content.Server/Storage/Components/StorageFillComponent.cs # Content.Server/Stunnable/StunbatonSystem.cs # Content.Server/Throwing/ThrowHelper.cs # Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs # Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs # Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs # Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs # Content.Shared/Damage/Components/DamageableComponent.cs # Content.Shared/Damage/Systems/DamageableSystem.cs # Content.Shared/MobState/Components/MobStateComponent.cs # Content.Shared/Slippery/SharedSlipperySystem.cs
2021-12-07 17:48:49 +01:00
EntitySystem.Get<StunSystem>().TryStun(human, TimeSpan.FromSeconds(1f), true);
// Since the mob is stunned, they can't equip this.
Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy", true), Is.False);
// Make sure we don't have the ID card equipped.
Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent _), Is.False);
// Let's try skipping the interaction check and see if it equips it!
Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy"));
Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent id));
2021-12-05 18:09:01 +01:00
Assert.That(sEntities.GetComponent<MetaDataComponent>(id.Owner).EntityPrototype is
{
ID: "InventoryIDCardDummy"
});
});
}
}
}