68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
|
using NUnit.Framework;
|
|||
|
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
using Encompass;
|
|||
|
|
|||
|
namespace Tests
|
|||
|
{
|
|||
|
public class GeneralRendererTest
|
|||
|
{
|
|||
|
struct AComponent : IComponent { }
|
|||
|
|
|||
|
public class SingletonRead
|
|||
|
{
|
|||
|
static KeyValuePair<Guid, AComponent> result;
|
|||
|
|
|||
|
class TestRenderer : GeneralRenderer
|
|||
|
{
|
|||
|
public new int Layer { get { return 1; } }
|
|||
|
|
|||
|
public override void Render()
|
|||
|
{
|
|||
|
result = ReadComponent<AComponent>();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void SingletonComponent()
|
|||
|
{
|
|||
|
var worldBuilder = new WorldBuilder();
|
|||
|
worldBuilder.AddRenderer<TestRenderer>();
|
|||
|
|
|||
|
AComponent aComponent;
|
|||
|
|
|||
|
var entity = worldBuilder.CreateEntity();
|
|||
|
var componentID = entity.AddComponent(aComponent);
|
|||
|
|
|||
|
var world = worldBuilder.Build();
|
|||
|
|
|||
|
world.Update(0.01f);
|
|||
|
world.Draw();
|
|||
|
|
|||
|
Assert.That(result, Is.EqualTo(new KeyValuePair<Guid, AComponent>(componentID, aComponent)));
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void MultipleComponents()
|
|||
|
{
|
|||
|
var worldBuilder = new WorldBuilder();
|
|||
|
worldBuilder.AddRenderer<TestRenderer>();
|
|||
|
|
|||
|
AComponent aComponent;
|
|||
|
AComponent aComponentTwo;
|
|||
|
|
|||
|
var entity = worldBuilder.CreateEntity();
|
|||
|
var componentID = entity.AddComponent(aComponent);
|
|||
|
var componentTwoID = entity.AddComponent(aComponentTwo);
|
|||
|
var world = worldBuilder.Build();
|
|||
|
|
|||
|
world.Update(0.01f);
|
|||
|
|
|||
|
Assert.Throws<InvalidOperationException>(() => world.Draw());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|