encompass-cs/test/SpawnerTest.cs

56 lines
1.3 KiB
C#
Raw Normal View History

2019-06-29 05:07:48 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using Encompass;
using Encompass.Engines;
using NUnit.Framework;
namespace Tests
{
public class SpawnerTest
{
struct TestComponent : IComponent { }
struct SpawnMessageA : IMessage { }
static Entity resultEntity;
2019-06-29 05:57:18 +00:00
[Emits(typeof(SpawnMessageA))]
class MessageEmitter : Engine
{
public override void Update(double dt)
{
EmitMessage(new SpawnMessageA());
}
}
2019-06-29 05:07:48 +00:00
class TestSpawner : Spawner<SpawnMessageA>
{
protected override void Spawn(SpawnMessageA message)
{
resultEntity = CreateEntity();
resultEntity.AddComponent(new TestComponent());
}
}
[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);
Assert.That(resultEntity.HasComponent<TestComponent>(), Is.True);
var id = resultEntity.id;
world.Update(0.01);
2019-06-29 05:57:18 +00:00
Assert.That(resultEntity.id, Is.Not.EqualTo(id));
2019-06-29 05:07:48 +00:00
}
}
}