2019-07-26 08:17:39 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
2019-06-29 05:07:48 +00:00
|
|
|
|
using Encompass;
|
|
|
|
|
using Encompass.Engines;
|
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
|
|
|
|
public class SpawnerTest
|
|
|
|
|
{
|
2019-07-26 08:17:39 +00:00
|
|
|
|
public struct TestComponent : IComponent { }
|
|
|
|
|
public struct SpawnMessageA : IMessage { }
|
2019-06-29 05:07:48 +00:00
|
|
|
|
|
|
|
|
|
static Entity resultEntity;
|
|
|
|
|
|
2019-07-19 01:20:38 +00:00
|
|
|
|
[Sends(typeof(SpawnMessageA))]
|
2019-06-29 05:57:18 +00:00
|
|
|
|
class MessageEmitter : Engine
|
|
|
|
|
{
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
|
{
|
2019-07-19 03:31:31 +00:00
|
|
|
|
SendMessage(new SpawnMessageA());
|
2019-06-29 05:57:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 08:17:39 +00:00
|
|
|
|
static bool spawnResult = false;
|
|
|
|
|
|
2019-07-18 21:02:57 +00:00
|
|
|
|
[Activates(typeof(TestComponent))]
|
2019-07-26 08:17:39 +00:00
|
|
|
|
public class TestSpawner : Spawner<SpawnMessageA>
|
2019-06-29 05:07:48 +00:00
|
|
|
|
{
|
2019-07-26 08:17:39 +00:00
|
|
|
|
protected override void Spawn(SpawnMessageA message)
|
2019-06-29 05:07:48 +00:00
|
|
|
|
{
|
2019-07-26 08:17:39 +00:00
|
|
|
|
spawnResult = true;
|
2019-06-29 05:07:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 08:17:39 +00:00
|
|
|
|
interface TestSpawnerProtectedMembers
|
|
|
|
|
{
|
|
|
|
|
void Spawn(SpawnMessageA message);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 05:07:48 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void RunsSpawnMethodOnMessageRead()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-29 05:57:18 +00:00
|
|
|
|
worldBuilder.AddEngine(new MessageEmitter());
|
2019-06-29 05:07:48 +00:00
|
|
|
|
worldBuilder.AddEngine(new TestSpawner());
|
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01);
|
2019-07-26 08:17:39 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsTrue(spawnResult);
|
2019-06-29 05:07:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|