From 2cae1ac641697210e600e61f1e518ed9b24add1b Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Wed, 18 Nov 2020 14:38:27 +0100 Subject: [PATCH] Add test for being unable to pull anchored entities (#2476) * Add test for being unable to pull anchored entities * Change resolve to server.ResolveDependency * Add extra prototypes * Fix not waiting before resolving dependencies * Fix missing physics component for the puller --- .../Tests/Pulling/PullTest.cs | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Content.IntegrationTests/Tests/Pulling/PullTest.cs diff --git a/Content.IntegrationTests/Tests/Pulling/PullTest.cs b/Content.IntegrationTests/Tests/Pulling/PullTest.cs new file mode 100644 index 0000000000..fbd430dce8 --- /dev/null +++ b/Content.IntegrationTests/Tests/Pulling/PullTest.cs @@ -0,0 +1,81 @@ +using System.Threading.Tasks; +using Content.Server.GameObjects.Components.Pulling; +using Content.Shared.GameObjects.Components.Pulling; +using Content.Shared.Physics.Pull; +using NUnit.Framework; +using Robust.Shared.GameObjects.Components; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Map; +using Robust.Shared.Map; + +namespace Content.IntegrationTests.Tests.Pulling +{ + [TestFixture] + [TestOf(typeof(SharedPullableComponent))] + [TestOf(typeof(SharedPullerComponent))] + [TestOf(typeof(PullController))] + public class PullTest : ContentIntegrationTest + { + private const string PROTOTYPES = @" +- type: entity + name: PullTestPullerDummy + id: PullTestPullerDummy + components: + - type: Puller + - type: Physics + +- type: entity + name: PullTestPullableDummy + id: PullTestPullableDummy + components: + - type: Pullable + - type: Physics +"; + + [Test] + public async Task AnchoredNoPullTest() + { + var options = new ServerContentIntegrationOption {ExtraPrototypes = PROTOTYPES}; + var server = StartServerDummyTicker(options); + + await server.WaitIdleAsync(); + + var mapManager = server.ResolveDependency(); + var entityManager = server.ResolveDependency(); + + await server.WaitAssertion(() => + { + mapManager.CreateNewMapEntity(MapId.Nullspace); + + var pullerEntity = entityManager.SpawnEntity("PullTestPullerDummy", MapCoordinates.Nullspace); + var pullableEntity = entityManager.SpawnEntity("PullTestPullableDummy", MapCoordinates.Nullspace); + + var puller = pullerEntity.GetComponent(); + var pullable = pullableEntity.GetComponent(); + var pullablePhysics = pullableEntity.GetComponent(); + + pullablePhysics.Anchored = false; + + Assert.That(pullable.TryStartPull(puller.Owner)); + Assert.That(pullable.Puller, Is.EqualTo(puller.Owner)); + Assert.That(pullable.BeingPulled); + + Assert.That(puller.Pulling, Is.EqualTo(pullable.Owner)); + + Assert.That(pullable.TryStopPull); + Assert.That(pullable.Puller, Is.Null); + Assert.That(pullable.BeingPulled, Is.False); + + Assert.That(puller.Pulling, Is.Null); + + pullablePhysics.Anchored = true; + + Assert.That(pullable.TryStartPull(puller.Owner), Is.False); + Assert.That(pullable.Puller, Is.Null); + Assert.That(pullable.BeingPulled, Is.False); + + Assert.That(puller.Pulling, Is.Null); + }); + } + } +}