83 lines
2.3 KiB
C#
83 lines
2.3 KiB
C#
using NUnit.Framework;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using Encompass;
|
|
|
|
namespace Tests
|
|
{
|
|
public static class GeneralRendererTest
|
|
{
|
|
struct AComponent : IComponent { }
|
|
|
|
public class SingletonRead
|
|
{
|
|
static ValueTuple<Guid, AComponent> result;
|
|
|
|
class TestRenderer : GeneralRenderer
|
|
{
|
|
public override void Render()
|
|
{
|
|
result = ReadComponent<AComponent>();
|
|
}
|
|
}
|
|
|
|
[TestCase(true)]
|
|
[TestCase(false)]
|
|
public void SingletonComponent(bool parallelUpdate)
|
|
{
|
|
var worldBuilder = new WorldBuilder();
|
|
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
|
|
|
|
AComponent aComponent;
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
var componentID = worldBuilder.AddComponent(entity, aComponent);
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
if (parallelUpdate)
|
|
{
|
|
world.ParallelUpdate(0.01);
|
|
}
|
|
else
|
|
{
|
|
world.Update(0.01);
|
|
}
|
|
|
|
world.Draw();
|
|
|
|
Assert.That(result, Is.EqualTo(new ValueTuple<Guid, AComponent>(componentID, aComponent)));
|
|
}
|
|
|
|
[TestCase(true)]
|
|
[TestCase(false)]
|
|
public void MultipleComponents(bool parallelUpdate)
|
|
{
|
|
var worldBuilder = new WorldBuilder();
|
|
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
|
|
|
|
AComponent aComponent;
|
|
AComponent aComponentTwo;
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
var componentID = worldBuilder.AddComponent(entity, aComponent);
|
|
var componentTwoID = worldBuilder.AddComponent(entity, aComponentTwo);
|
|
var world = worldBuilder.Build();
|
|
|
|
if (parallelUpdate)
|
|
{
|
|
world.ParallelUpdate(0.01);
|
|
}
|
|
else
|
|
{
|
|
world.Update(0.01);
|
|
}
|
|
|
|
Assert.Throws<InvalidOperationException>(() => world.Draw());
|
|
}
|
|
}
|
|
}
|
|
}
|