Files
RobustToolbox/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs
6d46d3f4a5 Cleanup most warnings in unit tests (#5946)
* 2 warnings in JointDeletion_Test

* 1 warning in Collision_Test

* 2 warnings in Color_Test (deleted test of deprecated HCY color space)

* 1 warning in MapVelocity_Test

* 2 warnings in MapManager_Tests

* 2 warnings in MapPauseTests

* 1 warning in NetDisconnectMessageTest

* 1 warning in ContainerTests

* Suppress 1 warning in EntityEventBusTests.ComponentEvent

* 4 warnings in MapGridMap_Tests

* 1 warning in GridDeletion_Test

* Remove TryGetContainingContainer foolishness

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2025-05-29 00:12:58 +10:00

84 lines
2.7 KiB
C#

using System.Numerics;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.UnitTesting.Server;
namespace Robust.UnitTesting.Shared.Map
{
[TestFixture, TestOf(typeof(MapManager))]
public sealed class MapManagerTests
{
private static ISimulation SimulationFactory()
{
var sim = RobustServerSimulation
.NewSimulation()
.InitializeInstance();
return sim;
}
/// <summary>
/// When the map manager is restarted, the maps are deleted.
/// </summary>
[Test]
public void Restart_ExistingMap_IsRemoved()
{
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var entMan = sim.Resolve<IEntityManager>();
var mapSys = entMan.System<SharedMapSystem>();
var mapID = sim.CreateMap().MapId;
mapMan.Restart();
Assert.That(mapSys.MapExists(mapID), Is.False);
}
/// <summary>
/// When the map manager is restarted, the grids are removed.
/// </summary>
[Test]
public void Restart_ExistingGrid_IsRemoved()
{
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var entMan = sim.Resolve<IEntityManager>();
var mapID = sim.CreateMap().MapId;
var grid = mapMan.CreateGridEntity(mapID);
mapMan.Restart();
Assert.That(entMan.HasComponent<MapGridComponent>(grid), Is.False);
}
/// <summary>
/// When entities are flushed check nullsapce is also culled.
/// </summary>
[Test]
public void Restart_NullspaceMap_IsEmptied()
{
var sim = SimulationFactory();
var entMan = sim.Resolve<IEntityManager>();
var oldEntity = entMan.CreateEntityUninitialized(null, MapCoordinates.Nullspace);
entMan.InitializeEntity(oldEntity);
entMan.FlushEntities();
Assert.That(entMan.Deleted(oldEntity), Is.True);
}
[Test]
public void Restart_MapEntity_IsRemoved()
{
var sim = SimulationFactory();
var entMan = sim.Resolve<IEntityManager>();
var mapMan = sim.Resolve<IMapManager>();
var entity = entMan.System<SharedMapSystem>().CreateMap();
mapMan.Restart();
Assert.That((!entMan.EntityExists(entity) ? EntityLifeStage.Deleted : entMan.GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted, Is.True);
}
}
}