encompass-cs/test/SpawnerTest.cs

47 lines
1.2 KiB
C#
Raw Normal View History

using Encompass;
2019-06-29 05:07:48 +00:00
using NUnit.Framework;
namespace Tests
{
public class SpawnerTest
{
struct TestComponent : IComponent { }
struct SpawnMessageA : IMessage { }
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)
{
SendMessage(new SpawnMessageA());
2019-06-29 05:57:18 +00:00
}
}
2019-12-24 03:04:26 +00:00
[WritesImmediate(typeof(TestComponent))]
[Writes(typeof(TestComponent))]
2019-06-29 05:07:48 +00:00
class TestSpawner : Spawner<SpawnMessageA>
{
protected override void Spawn(SpawnMessageA message)
{
resultEntity = CreateEntity();
SetComponent(resultEntity, new TestComponent());
2019-07-17 18:24:21 +00:00
Assert.Pass();
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);
}
}
}