encompass-cs/test/GeneralRendererTest.cs

83 lines
2.3 KiB
C#
Raw Normal View History

2019-06-20 01:01:08 +00:00
using NUnit.Framework;
using System;
using System.Collections.Generic;
using Encompass;
namespace Tests
{
public static class GeneralRendererTest
2019-06-20 01:01:08 +00:00
{
struct AComponent : IComponent { }
public class SingletonRead
{
static ValueTuple<Guid, AComponent> result;
2019-06-20 01:01:08 +00:00
class TestRenderer : GeneralRenderer
{
public override void Render()
{
result = ReadComponent<AComponent>();
}
}
[TestCase(true)]
[TestCase(false)]
public void SingletonComponent(bool parallelUpdate)
2019-06-20 01:01:08 +00:00
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
2019-06-20 01:01:08 +00:00
AComponent aComponent;
var entity = worldBuilder.CreateEntity();
2019-07-17 18:24:21 +00:00
var componentID = worldBuilder.AddComponent(entity, aComponent);
2019-06-20 01:01:08 +00:00
var world = worldBuilder.Build();
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
2019-06-20 01:01:08 +00:00
world.Draw();
Assert.That(result, Is.EqualTo(new ValueTuple<Guid, AComponent>(componentID, aComponent)));
2019-06-20 01:01:08 +00:00
}
[TestCase(true)]
[TestCase(false)]
public void MultipleComponents(bool parallelUpdate)
2019-06-20 01:01:08 +00:00
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
2019-06-20 01:01:08 +00:00
AComponent aComponent;
AComponent aComponentTwo;
var entity = worldBuilder.CreateEntity();
2019-07-17 18:24:21 +00:00
var componentID = worldBuilder.AddComponent(entity, aComponent);
var componentTwoID = worldBuilder.AddComponent(entity, aComponentTwo);
2019-06-20 01:01:08 +00:00
var world = worldBuilder.Build();
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
2019-06-20 01:01:08 +00:00
Assert.Throws<InvalidOperationException>(() => world.Draw());
}
}
}
}