encompass-cs/test/RendererTest.cs

72 lines
2.0 KiB
C#
Raw Normal View History

2019-06-20 01:01:08 +00:00
using NUnit.Framework;
using Encompass;
namespace Tests
{
public static class GeneralRendererTest
2019-06-20 01:01:08 +00:00
{
struct AComponent { }
2019-06-20 01:01:08 +00:00
public class SingletonRead
{
2019-11-21 03:01:29 +00:00
static (AComponent, Entity) result;
2019-06-20 01:01:08 +00:00
class TestRenderer : Renderer
2019-06-20 01:01:08 +00:00
{
2021-03-24 00:50:05 +00:00
public override void Render(double dt, double alpha)
2019-06-20 01:01:08 +00:00
{
2020-03-23 02:10:28 +00:00
ref readonly var entity = ref ReadEntity<AComponent>();
result = (GetComponent<AComponent>(entity), entity);
2019-06-20 01:01:08 +00:00
}
}
[Test]
public void SingletonComponent()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddRenderer(new TestRenderer());
2019-06-20 01:01:08 +00:00
AComponent aComponent;
var entity = worldBuilder.CreateEntity();
2019-11-21 03:01:29 +00:00
worldBuilder.SetComponent(entity, aComponent);
2019-06-20 01:01:08 +00:00
var world = worldBuilder.Build();
world.Update(0.01f);
2021-03-24 00:50:05 +00:00
world.Draw(0.01f, 0);
2019-06-20 01:01:08 +00:00
world.Update(0.01);
2021-03-24 00:50:05 +00:00
world.Draw(0.01f, 0);
2019-11-21 03:01:29 +00:00
Assert.That(result, Is.EqualTo((aComponent, entity)));
2019-06-20 01:01:08 +00:00
}
[Test]
public void MultipleComponents()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddRenderer(new TestRenderer());
2019-06-20 01:01:08 +00:00
AComponent aComponent;
AComponent aComponentTwo;
var entity = worldBuilder.CreateEntity();
2019-11-21 03:01:29 +00:00
worldBuilder.SetComponent(entity, aComponent);
var entityB = worldBuilder.CreateEntity();
2019-11-21 03:01:29 +00:00
worldBuilder.SetComponent(entityB, aComponentTwo);
2019-06-20 01:01:08 +00:00
var world = worldBuilder.Build();
world.Update(0.01f);
2021-03-24 00:50:05 +00:00
world.Draw(0.01f, 0);
2019-06-20 01:01:08 +00:00
world.Update(0.01f);
2021-03-24 00:50:05 +00:00
world.Draw(0.01f, 0);
2019-08-01 23:48:02 +00:00
2019-11-21 03:01:29 +00:00
Assert.That(result, Is.EqualTo((aComponent, entity)).Or.EqualTo((aComponentTwo, entityB)));
2019-06-20 01:01:08 +00:00
}
}
}
}