encompass-cs/test/EntityTest.cs

97 lines
2.9 KiB
C#

using NUnit.Framework;
using System.Linq;
namespace Encompass
{
namespace Tests {
struct MockComponent : IComponent {
public string myString;
public int myInt;
}
public class EntityTest
{
[Test]
public void AddComponent()
{
var world = new World();
var entity = world.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
entity.AddComponent<MockComponent>(mockComponent);
world.Update();
Assert.IsTrue(entity.HasComponent<MockComponent>());
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
}
[Test]
public void GetComponents()
{
var world = new World();
var entity = world.CreateEntity();
MockComponent mockComponentA;
mockComponentA.myInt = 3;
mockComponentA.myString = "hello";
MockComponent mockComponentB;
mockComponentB.myInt = 5;
mockComponentB.myString = "wassup";
MockComponent mockComponentC;
mockComponentC.myInt = 1;
mockComponentC.myString = "howdy";
entity.AddComponent<MockComponent>(mockComponentA);
entity.AddComponent<MockComponent>(mockComponentB);
entity.AddComponent<MockComponent>(mockComponentC);
world.Update();
Assert.Contains(mockComponentA, entity.GetComponents<MockComponent>().ToList());
Assert.Contains(mockComponentB, entity.GetComponents<MockComponent>().ToList());
Assert.Contains(mockComponentC, entity.GetComponents<MockComponent>().ToList());
}
[Test]
public void GetComponent()
{
var world = new World();
var entity = world.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
entity.AddComponent<MockComponent>(mockComponent);
world.Update();
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
}
[Test]
public void HasComponent()
{
var world = new World();
var entity = world.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
entity.AddComponent<MockComponent>(mockComponent);
world.Update();
Assert.IsTrue(entity.HasComponent<MockComponent>());
}
}
}
}