Files
RobustToolbox/Robust.Shared.IntegrationTests/GameObjects/EntityManagerIsDefaultTests.cs
metalgearslothandGitHub 45f3caaac4 Fastpath EntityManager.IsDefault (#6735)
* Slim it down

Had the spawn mess included.

* fixes

* build fix
2026-07-24 01:07:57 +10:00

77 lines
2.4 KiB
C#

using System.Collections.Generic;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Spawners;
using Robust.UnitTesting.Server;
namespace Robust.UnitTesting.Shared.GameObjects;
[TestFixture]
internal sealed partial class EntityManagerIsDefaultTests
{
private const string PrototypeId = "IsDefaultTestEntity";
private const string Prototypes = $"""
- type: entity
id: {PrototypeId}
name: test entity
description: test description
components:
- type: TimedDespawn
lifetime: 5
""";
[Test]
public void IsDefaultComparesAgainstPrototypeData()
{
var sim = RobustServerSimulation
.NewSimulation()
.RegisterComponents(factory =>
{
factory.RegisterClass<TimedDespawnComponent>();
factory.RegisterClass<PlacementReplacementComponent>();
})
.RegisterPrototypes(prototypes =>
{
prototypes.LoadString(Prototypes);
prototypes.ResolveResults();
})
.InitializeInstance();
var entMan = (EntityManager) sim.Resolve<IEntityManager>();
var map = sim.CreateMap().Uid;
var coords = new EntityCoordinates(map, default);
var entity = entMan.SpawnEntity(PrototypeId, coords);
Assert.That(entMan.IsDefault(entity), Is.True);
entMan.GetComponent<TimedDespawnComponent>(entity).Lifetime = 10;
Assert.That(entMan.IsDefault(entity), Is.False);
Assert.That(entMan.IsDefault(entity, new HashSet<string> { "TimedDespawn" }), Is.True);
entMan.GetComponent<TimedDespawnComponent>(entity).Lifetime = 5;
entMan.AddComponent<PlacementReplacementComponent>(entity);
Assert.That(entMan.IsDefault(entity), Is.False);
}
[Test]
public void DataFieldEqualsComparesHashSetsAsSets()
{
var sim = RobustServerSimulation
.NewSimulation()
.InitializeInstance();
var serialization = sim.Resolve<ISerializationManager>();
Assert.That(serialization.DataFieldEquals(
new HashSet<int> { 1, 2, 3 },
new HashSet<int> { 3, 2, 1 }), Is.True);
Assert.That(serialization.DataFieldEquals(
new HashSet<int> { 1, 2, 3 },
new HashSet<int> { 1, 2, 4 }), Is.False);
}
}