read component tests

pull/5/head
Evan Hemsley 2019-06-14 18:13:24 -07:00
parent 40763d2559
commit 4b9610762a
1 changed files with 57 additions and 2 deletions

View File

@ -3,13 +3,15 @@ using System.Linq;
using Encompass;
using System.Collections.Generic;
using System;
namespace Tests {
public class EngineTest
{
static IEnumerable<MockComponent> components;
static MockComponent component;
public class TestEngine : Engine
public class ReadComponentsTestEngine : Engine
{
public override void Update(float dt)
{
@ -17,11 +19,19 @@ namespace Tests {
}
}
public class ReadComponentTestEngine : Engine
{
public override void Update(float dt)
{
component = this.ReadComponent<MockComponent>();
}
}
[Test]
public void ReadComponents()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine<TestEngine>();
worldBuilder.AddEngine<ReadComponentsTestEngine>();
var entity = worldBuilder.CreateEntity();
@ -43,5 +53,50 @@ namespace Tests {
Assert.Contains(mockComponent, components.ToList());
Assert.Contains(mockComponentB, components.ToList());
}
[Test]
public void ReadComponent()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine<ReadComponentTestEngine>();
var entity = worldBuilder.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 0;
mockComponent.myString = "hello";
entity.AddComponent(mockComponent);
var world = worldBuilder.Build();
world.Update(0.01f);
Assert.AreEqual(mockComponent, component);
}
[Test]
public void ReadComponentWhenMultipleComponents()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine<ReadComponentTestEngine>();
var entity = worldBuilder.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 0;
mockComponent.myString = "hello";
MockComponent mockComponentB;
mockComponentB.myInt = 1;
mockComponentB.myString = "howdy";
entity.AddComponent(mockComponent);
entity.AddComponent(mockComponentB);
var world = worldBuilder.Build();
Assert.Throws<InvalidOperationException>(() => world.Update(0.01f));
}
}
}