encompass-cs/test/EntityTest.cs

97 lines
2.8 KiB
C#

using NUnit.Framework;
using System.Linq;
using Encompass;
namespace Tests {
struct MockComponent : IComponent {
public string myString;
public int myInt;
}
public class EntityTest
{
[Test]
public void AddComponent()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
entity.AddComponent<MockComponent>(mockComponent);
var world = worldBuilder.Build();
// world.Update();
Assert.IsTrue(entity.HasComponent<MockComponent>());
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
}
[Test]
public void GetComponents()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.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);
var world = worldBuilder.Build();
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 worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
entity.AddComponent<MockComponent>(mockComponent);
var world = worldBuilder.Build();
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
}
[Test]
public void HasComponent()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
entity.AddComponent<MockComponent>(mockComponent);
var world = worldBuilder.Build();
Assert.IsTrue(entity.HasComponent<MockComponent>());
}
}
}