Fix content.integration tests warnings (#17817)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
TemporalOroboros
2023-07-05 21:54:25 -07:00
committed by GitHub
parent 20c1754abd
commit ba91023a85
121 changed files with 3658 additions and 1961 deletions

View File

@@ -1,13 +1,10 @@
#nullable enable
using System.Threading.Tasks;
using Content.Server.Cuffs;
using Content.Shared.Body.Components;
using Content.Shared.Cuffs.Components;
using Content.Shared.Hands.Components;
using NUnit.Framework;
using Robust.Server.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -39,15 +36,18 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
public async Task Test()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{NoClient = true, ExtraPrototypes = Prototypes});
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
EntityUid human;
EntityUid otherHuman;
EntityUid cuffs;
EntityUid secondCuffs;
CuffableComponent cuffed;
HandsComponent hands;
CuffableComponent cuffed = default!;
HandsComponent hands = default!;
var entityManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
@@ -59,6 +59,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
var coordinates = new MapCoordinates(Vector2.Zero, mapId);
var cuffableSys = entityManager.System<CuffableSystem>();
var xformSys = entityManager.System<SharedTransformSystem>();
var xformQuery = entityManager.GetEntityQuery<TransformComponent>();
// Spawn the entities
human = entityManager.SpawnEntity("HumanDummy", coordinates);
@@ -66,38 +68,42 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
entityManager.GetComponent<TransformComponent>(human).WorldPosition =
entityManager.GetComponent<TransformComponent>(otherHuman).WorldPosition;
var coords = xformSys.GetWorldPosition(otherHuman, xformQuery);
xformSys.SetWorldPosition(human, coords, xformQuery);
// Test for components existing
Assert.True(entityManager.TryGetComponent(human, out cuffed!),
$"Human has no {nameof(CuffableComponent)}");
Assert.True(entityManager.TryGetComponent(human, out hands!), $"Human has no {nameof(HandsComponent)}");
Assert.True(entityManager.TryGetComponent(human, out BodyComponent? _), $"Human has no {nameof(BodyComponent)}");
Assert.True(entityManager.TryGetComponent(cuffs, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
Assert.True(entityManager.TryGetComponent(secondCuffs, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
Assert.Multiple(() =>
{
Assert.That(entityManager.TryGetComponent(human, out cuffed!), $"Human has no {nameof(CuffableComponent)}");
Assert.That(entityManager.TryGetComponent(human, out hands!), $"Human has no {nameof(HandsComponent)}");
Assert.That(entityManager.TryGetComponent(human, out BodyComponent? _), $"Human has no {nameof(BodyComponent)}");
Assert.That(entityManager.TryGetComponent(cuffs, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
Assert.That(entityManager.TryGetComponent(secondCuffs, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
});
// Test to ensure cuffed players register the handcuffs
cuffableSys.TryAddNewCuffs(human, human, cuffs, cuffed);
Assert.True(cuffed.CuffedHandCount > 0,
"Handcuffing a player did not result in their hands being cuffed");
Assert.That(cuffed.CuffedHandCount, Is.GreaterThan(0), "Handcuffing a player did not result in their hands being cuffed");
// Test to ensure a player with 4 hands will still only have 2 hands cuffed
AddHand(human, host);
AddHand(human, host);
Assert.That(cuffed.CuffedHandCount, Is.EqualTo(2));
Assert.That(hands.SortedHands.Count, Is.EqualTo(4));
Assert.Multiple(() =>
{
Assert.That(cuffed.CuffedHandCount, Is.EqualTo(2));
Assert.That(hands.SortedHands, Has.Count.EqualTo(4));
});
// Test to give a player with 4 hands 2 sets of cuffs
cuffableSys.TryAddNewCuffs(human, human, secondCuffs, cuffed);
Assert.True(cuffed.CuffedHandCount == 4, "Player doesn't have correct amount of hands cuffed");
Assert.That(cuffed.CuffedHandCount, Is.EqualTo(4), "Player doesn't have correct amount of hands cuffed");
});
await pairTracker.CleanReturnAsync();
}
private void AddHand(EntityUid to, IServerConsoleHost host)
private static void AddHand(EntityUid to, IServerConsoleHost host)
{
host.ExecuteCommand(null, $"addhand {to}");
}