2019-06-20 01:01:08 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using Encompass;
|
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
2019-06-27 23:55:12 +00:00
|
|
|
|
public static class GeneralRendererTest
|
2019-06-20 01:01:08 +00:00
|
|
|
|
{
|
|
|
|
|
struct AComponent : IComponent { }
|
|
|
|
|
|
|
|
|
|
public class SingletonRead
|
|
|
|
|
{
|
2019-06-27 23:55:12 +00:00
|
|
|
|
static ValueTuple<Guid, AComponent> result;
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
|
|
|
|
class TestRenderer : GeneralRenderer
|
|
|
|
|
{
|
|
|
|
|
public override void Render()
|
|
|
|
|
{
|
|
|
|
|
result = ReadComponent<AComponent>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SingletonComponent()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 23:49:26 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
2019-06-27 23:55:12 +00:00
|
|
|
|
Assert.That(result, Is.EqualTo(new ValueTuple<Guid, AComponent>(componentID, aComponent)));
|
2019-06-20 01:01:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void MultipleComponents()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 23:49:26 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
|
2019-08-01 23:48:02 +00:00
|
|
|
|
world.Draw();
|
|
|
|
|
|
|
|
|
|
Assert.That(result, Is.EqualTo((componentID, aComponent)).Or.EqualTo((componentTwoID, aComponentTwo)));
|
2019-06-20 01:01:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|