encompass-cs/test/SpawnerTest.cs

63 lines
1.5 KiB
C#

using NUnit.Framework;
using Encompass;
using Encompass.Engines;
namespace Tests
{
public class SpawnerTest
{
public struct TestComponent : IComponent { }
public struct SpawnMessageA : IMessage { }
static Entity resultEntity;
[Sends(typeof(SpawnMessageA))]
class MessageEmitter : Engine
{
public override void Update(double dt)
{
SendMessage(new SpawnMessageA());
}
}
static bool spawnResult = false;
[Activates(typeof(TestComponent))]
public class TestSpawner : Spawner<SpawnMessageA>
{
protected override void Spawn(SpawnMessageA message)
{
spawnResult = true;
}
}
interface TestSpawnerProtectedMembers
{
void Spawn(SpawnMessageA message);
}
[TestCase(true)]
[TestCase(false)]
public void RunsSpawnMethodOnMessageRead(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new MessageEmitter());
worldBuilder.AddEngine(new TestSpawner());
var world = worldBuilder.Build();
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsTrue(spawnResult);
}
}
}