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.
57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using NUnit.Framework;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.UnitTesting.Server;
|
|
|
|
namespace Robust.Server.IntegrationTests.GameObjects
|
|
{
|
|
[TestFixture]
|
|
internal sealed class ThrowingEntityDeletion_Test
|
|
{
|
|
private ISimulation _sim = default!;
|
|
|
|
const string PROTOTYPES = @"
|
|
- type: entity
|
|
id: throwInAdd
|
|
components:
|
|
- type: DebugExceptionOnAdd
|
|
- type: entity
|
|
id: throwsInInitialize
|
|
components:
|
|
- type: DebugExceptionInitialize
|
|
- type: entity
|
|
id: throwsInStartup
|
|
components:
|
|
- type: DebugExceptionStartup
|
|
";
|
|
[OneTimeSetUp]
|
|
public void Setup()
|
|
{
|
|
_sim = RobustServerSimulation.NewSimulation()
|
|
.RegisterComponents(f =>
|
|
{
|
|
f.RegisterClass<DebugExceptionOnAddComponent>();
|
|
f.RegisterClass<DebugExceptionInitializeComponent>();
|
|
f.RegisterClass<DebugExceptionStartupComponent>();
|
|
})
|
|
.RegisterEntitySystems(f => f.LoadExtraSystemType<DebugExceptionSystem>())
|
|
.RegisterPrototypes(protoMan => protoMan.LoadString(PROTOTYPES))
|
|
.InitializeInstance();
|
|
}
|
|
|
|
[TestCase("throwInAdd")]
|
|
[TestCase("throwsInInitialize")]
|
|
[TestCase("throwsInStartup")]
|
|
public void Test(string prototypeName)
|
|
{
|
|
var entMan = _sim.Resolve<IEntityManager>();
|
|
_sim.Resolve<IEntityManager>().System<SharedMapSystem>().CreateMap(out var map);
|
|
|
|
Assert.That(() => entMan.SpawnEntity(prototypeName, new MapCoordinates(0, 0, map)),
|
|
Throws.TypeOf<EntityCreationException>());
|
|
|
|
Assert.That(entMan.GetEntities().Where(p => entMan.GetComponent<MetaDataComponent>(p).EntityPrototype?.ID == prototypeName), Is.Empty);
|
|
}
|
|
}
|
|
}
|