mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
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.
65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System.Numerics;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Reflection;
|
|
using Robust.UnitTesting.Server;
|
|
using Is = Robust.UnitTesting.Is;
|
|
|
|
namespace Robust.Server.IntegrationTests.GameObjects;
|
|
|
|
[TestFixture]
|
|
internal sealed partial class ComponentMapInitTest
|
|
{
|
|
/// <summary>
|
|
/// Asserts whether a component added after an entity has fully initialized has MapInit called.
|
|
/// </summary>
|
|
[Test]
|
|
public void ComponentMapInit()
|
|
{
|
|
var simFactory = RobustServerSimulation.NewSimulation();
|
|
simFactory.RegisterComponents(fac =>
|
|
{
|
|
fac.RegisterClass<MapInitTestComponent>();
|
|
}).RegisterEntitySystems(fac =>
|
|
{
|
|
fac.LoadExtraSystemType<MapInitTestSystem>();
|
|
});
|
|
|
|
var sim = simFactory.InitializeInstance();
|
|
var entManager = sim.Resolve<IEntityManager>();
|
|
var mapSystem = entManager.System<SharedMapSystem>();
|
|
mapSystem.CreateMap(out var mapId);
|
|
|
|
var ent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId));
|
|
Assert.That(entManager.GetComponent<MetaDataComponent>(ent).EntityLifeStage, Is.EqualTo(EntityLifeStage.MapInitialized));
|
|
|
|
var comp = entManager.AddComponent<MapInitTestComponent>(ent);
|
|
|
|
Assert.That(comp.Count, Is.EqualTo(1));
|
|
|
|
mapSystem.DeleteMap(mapId);
|
|
}
|
|
|
|
[Reflect(false)]
|
|
private sealed class MapInitTestSystem : EntitySystem
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<MapInitTestComponent, MapInitEvent>(OnMapInitTestMapInit);
|
|
}
|
|
|
|
private void OnMapInitTestMapInit(EntityUid uid, MapInitTestComponent component, MapInitEvent args)
|
|
{
|
|
component.Count += 1;
|
|
}
|
|
}
|
|
|
|
[Reflect(false)]
|
|
private sealed partial class MapInitTestComponent : Component
|
|
{
|
|
public int Count = 0;
|
|
}
|
|
}
|