Files
RobustToolbox/Robust.Shared.IntegrationTests/Spawning/TrySpawnInContainerTest.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

48 lines
1.8 KiB
C#

using System.Threading.Tasks;
using NUnit.Framework;
namespace Robust.UnitTesting.Shared.Spawning;
[TestFixture]
internal sealed class TrySpawnInContainerTest : EntitySpawnHelpersTest
{
[Test]
public async Task Test()
{
await Setup();
// Spawning into a non-existent container does nothing.
await Server.WaitPost(() =>
{
int count = EntMan.EntityCount;
Assert.That(EntMan.TrySpawnInContainer(null, ChildA, "foo", out var uid), Is.False);
Assert.That(EntMan.EntityCount, Is.EqualTo(count));
Assert.That(EntMan.EntityExists(uid), Is.False);
Assert.That(EntMan.TrySpawnInContainer(null, GrandChildB, "foo", out uid), Is.False);
Assert.That(EntMan.EntityCount, Is.EqualTo(count));
Assert.That(EntMan.EntityExists(uid), Is.False);
});
// Spawning into a container works as expected.
await Server.WaitPost(() =>
{
Assert.That(EntMan.TrySpawnInContainer(null, ChildA, "grandChildA", out var uid));
Assert.That(EntMan.EntityExists(uid));
Assert.That(Xforms.GetParentUid(uid!.Value), Is.EqualTo(ChildA));
Assert.That(Container.IsEntityInContainer(uid.Value));
Assert.That(Container.GetContainer(ChildA, "grandChildA").Contains(uid.Value));
});
// Spawning another entity will fail as the container is now full
await Server.WaitPost(() =>
{
int count = EntMan.EntityCount;
Assert.That(EntMan.TrySpawnInContainer(null, ChildA, "grandChildA", out var uid), Is.False);
Assert.That(EntMan.EntityCount, Is.EqualTo(count));
Assert.That(EntMan.EntityExists(uid), Is.False);
});
await Server.WaitPost(() => MapSys.DeleteMap(MapId));
}
}