mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 02:41:18 +03:00
93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
using System.Linq;
|
|
using Content.IntegrationTests.Fixtures;
|
|
using Content.IntegrationTests.Fixtures.Attributes;
|
|
using Content.Shared.Body;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.IntegrationTests.Tests.Body;
|
|
|
|
[TestFixture]
|
|
[TestOf(typeof(OrganRelationSystem))]
|
|
public sealed class OrganRelationSystemTest : GameTest
|
|
{
|
|
[TestPrototypes]
|
|
private const string Prototypes = @"
|
|
- type: entity
|
|
id: OrganRelationTestOrgan
|
|
components:
|
|
- type: Organ
|
|
- type: ParentOrgan
|
|
- type: ChildOrgan
|
|
";
|
|
|
|
[SidedDependency(Side.Server)] private OrganRelationSystem _organRelation = default!;
|
|
|
|
[Test]
|
|
[RunOnSide(Side.Server)]
|
|
public void RelateAndOrphan()
|
|
{
|
|
var parent = SSpawn("OrganRelationTestOrgan");
|
|
var child = SSpawn("OrganRelationTestOrgan");
|
|
|
|
_organRelation.Relate(parent, child);
|
|
|
|
var parentComp = SComp<ParentOrganComponent>(parent);
|
|
var childComp = SComp<ChildOrganComponent>(child);
|
|
|
|
Assert.That(parentComp.Children, Does.Contain(child));
|
|
Assert.That(childComp.Parent, Is.EqualTo(parent));
|
|
|
|
_organRelation.Orphan(child);
|
|
|
|
Assert.That(parentComp.Children, Does.Not.Contain(child));
|
|
Assert.That(childComp.Parent, Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
[RunOnSide(Side.Server)]
|
|
public void Traversal()
|
|
{
|
|
var grandParent = SSpawn("OrganRelationTestOrgan");
|
|
var parent = SSpawn("OrganRelationTestOrgan");
|
|
var child = SSpawn("OrganRelationTestOrgan");
|
|
|
|
_organRelation.Relate(grandParent, parent);
|
|
_organRelation.Relate(parent, child);
|
|
|
|
var allChildren = _organRelation.AllChildren(grandParent).Select(e => e.Owner).ToList();
|
|
Assert.That(allChildren, Is.EquivalentTo(new[] { parent, child }));
|
|
|
|
var allParents = _organRelation.AllParents(child).Select(e => e.Owner).ToList();
|
|
Assert.That(allParents, Is.EquivalentTo(new[] { parent, grandParent }));
|
|
}
|
|
|
|
[Test]
|
|
[RunOnSide(Side.Server)]
|
|
public void ParentDeletion()
|
|
{
|
|
var parent = SSpawn("OrganRelationTestOrgan");
|
|
var child = SSpawn("OrganRelationTestOrgan");
|
|
|
|
_organRelation.Relate(parent, child);
|
|
|
|
SDeleteNow(parent);
|
|
|
|
Assert.That(SEntMan.Deleted(child), Is.False);
|
|
Assert.That(SComp<ChildOrganComponent>(child).Parent, Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
[RunOnSide(Side.Server)]
|
|
public void ChildDeletion()
|
|
{
|
|
var parent = SSpawn("OrganRelationTestOrgan");
|
|
var child = SSpawn("OrganRelationTestOrgan");
|
|
|
|
_organRelation.Relate(parent, child);
|
|
|
|
SDeleteNow(child);
|
|
|
|
Assert.That(SComp<ParentOrganComponent>(parent).Children, Does.Not.Contain(child));
|
|
}
|
|
}
|