Files
RobustToolbox/Robust.UnitTesting/Shared/GameObjects/EntitySystemManager_Tests.cs
T
Pieter-Jan Briers 67efd69679 Add explicit update dependency specification between entity systems.
This allows a system to say "I want to update after this other system does".

Based on @chairbender's work with the input binding stuff.
2020-06-19 00:18:59 +02:00

72 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Robust.UnitTesting.Shared.GameObjects
{
[TestFixture, TestOf(typeof(EntitySystemManager))]
public class EntitySystemManager_Tests: RobustUnitTest
{
public abstract class ESystemBase : IEntitySystem
{
public virtual IEnumerable<Type> UpdatesAfter => Enumerable.Empty<Type>();
public virtual IEnumerable<Type> UpdatesBefore => Enumerable.Empty<Type>();
public void Initialize() { }
public void Shutdown() { }
public void Update(float frameTime) { }
public void FrameUpdate(float frameTime) { }
}
public class ESystemA : ESystemBase { }
public class ESystemC : ESystemA { }
public abstract class ESystemBase2 : ESystemBase { }
public class ESystemB : ESystemBase2 { }
/*
ESystemBase (Abstract)
- ESystemA
- ESystemC
- EsystemBase2 (Abstract)
- ESystemB
*/
[Test]
public void GetsByTypeOrSupertype()
{
var esm = IoCManager.Resolve<IEntitySystemManager>();
esm.Initialize();
// getting type by the exact type should work fine
Assert.AreEqual(esm.GetEntitySystem<ESystemB>().GetType(), typeof(ESystemB));
// getting type by an abstract supertype should work fine
// because there are no other subtypes of that supertype it would conflict with
// it should return the only concrete subtype
Assert.AreEqual(esm.GetEntitySystem<ESystemBase2>().GetType(), typeof(ESystemB));
// getting ESystemA type by its exact type should work fine,
// even though EsystemC is a subtype - it should return an instance of ESystemA
var esysA = esm.GetEntitySystem<ESystemA>();
Assert.AreEqual(esysA.GetType(), typeof(ESystemA));
Assert.AreNotEqual(esysA.GetType(), typeof(ESystemC));
var esysC = esm.GetEntitySystem<ESystemC>();
Assert.AreEqual(esysC.GetType(), typeof(ESystemC));
// this should not work - it's abstract and there are multiple
// concrete subtypes
Assert.Throws<InvalidEntitySystemException>(() =>
{
esm.GetEntitySystem<ESystemBase>();
});
}
}
}