Files
RobustToolbox/Robust.Server.IntegrationTests/GameObjects/Components/TransformIntegration_Test.cs
PJB3005 788e9386fd Split up test project
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests.

Tests are now split into separate projects as appropriate, and the API side has also been split off.
2025-12-16 01:36:53 +01:00

59 lines
2.1 KiB
C#

using System.Numerics;
using NUnit.Framework;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.UnitTesting.Server;
namespace Robust.Server.IntegrationTests.GameObjects.Components;
[TestFixture]
internal sealed class TransformIntegration_Test
{
/// <summary>
/// Asserts that calling SetWorldPosition while in a container correctly removes the entity from its container.
/// </summary>
[Test]
public void WorldPositionContainerSet()
{
var factory = RobustServerSimulation.NewSimulation();
var sim = factory.InitializeInstance();
var entManager = sim.Resolve<IEntityManager>();
var containerSystem = entManager.System<SharedContainerSystem>();
var xformSystem = entManager.System<SharedTransformSystem>();
var map1 = sim.CreateMap().Uid;
var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
var ent2 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
var ent3 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
var container = containerSystem.EnsureContainer<ContainerSlot>(ent1, "a");
// Assert that setting worldpos updates parent correctly.
containerSystem.Insert(ent2, container, force: true);
Assert.That(containerSystem.IsEntityInContainer(ent2));
xformSystem.SetWorldPosition(ent2, Vector2.One);
Assert.That(!containerSystem.IsEntityInContainer(ent2));
Assert.That(xformSystem.GetWorldPosition(ent2), Is.EqualTo(Vector2.One));
// Assert that you can set recursively contained (but not directly contained) entities correctly.
containerSystem.Insert(ent2, container);
xformSystem.SetParent(ent3, ent2);
Assert.That(xformSystem.GetParentUid(ent3), Is.EqualTo(ent2));
xformSystem.SetWorldPosition(ent3, Vector2.One);
Assert.That(xformSystem.GetParentUid(ent3), Is.EqualTo(map1));
Assert.That(xformSystem.GetWorldPosition(ent3).Equals(Vector2.One));
// Cleanup
entManager.DeleteEntity(map1);
}
}