69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System;
|
|
|
|
using NUnit.Framework;
|
|
using FluentAssertions;
|
|
using Encompass;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Tests
|
|
{
|
|
public class OrderedRendererTest
|
|
{
|
|
struct AComponent : IComponent { }
|
|
struct BComponent : IComponent { }
|
|
struct CComponent : IComponent { }
|
|
|
|
struct TestDrawComponent : IComponent { }
|
|
|
|
class TestRenderer : OrderedRenderer<TestDrawComponent>
|
|
{
|
|
public override void Render(Guid drawComponentID, TestDrawComponent testDrawComponent) { }
|
|
}
|
|
|
|
static bool called = false;
|
|
class DeactivatedRenderer : TestRenderer
|
|
{
|
|
public override void Render(Guid drawComponentID, TestDrawComponent testDrawComponent)
|
|
{
|
|
called = true;
|
|
}
|
|
}
|
|
|
|
static bool calledOnDraw = false;
|
|
static ValueTuple<Guid, TestDrawComponent> resultComponent;
|
|
|
|
class CalledRenderer : OrderedRenderer<TestDrawComponent>
|
|
{
|
|
public override void Render(Guid drawComponentID, TestDrawComponent testDrawComponent)
|
|
{
|
|
resultComponent = (drawComponentID, testDrawComponent);
|
|
calledOnDraw = true;
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void RenderMethodCalledOnWorldDraw()
|
|
{
|
|
var worldBuilder = new WorldBuilder();
|
|
var renderer = worldBuilder.AddOrderedRenderer(new CalledRenderer());
|
|
|
|
AComponent aComponent;
|
|
CComponent cComponent;
|
|
TestDrawComponent testDrawComponent;
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
worldBuilder.AddComponent(entity, aComponent);
|
|
worldBuilder.AddComponent(entity, cComponent);
|
|
var testDrawComponentID = worldBuilder.AddDrawComponent(entity, testDrawComponent, 2);
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
world.Update(0.01f);
|
|
world.Draw();
|
|
|
|
Assert.IsTrue(calledOnDraw);
|
|
resultComponent.Should().BeEquivalentTo((testDrawComponentID, testDrawComponent));
|
|
}
|
|
}
|
|
}
|