55 lines
1.2 KiB
C#
55 lines
1.2 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);
|
|
}
|
|
|
|
[Test]
|
|
public void RunsSpawnMethodOnMessageRead()
|
|
{
|
|
var worldBuilder = new WorldBuilder();
|
|
worldBuilder.AddEngine(new MessageEmitter());
|
|
worldBuilder.AddEngine(new TestSpawner());
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
world.Update(0.01);
|
|
|
|
Assert.IsTrue(spawnResult);
|
|
}
|
|
}
|
|
}
|