encompass-cs/test/EntityTest.cs

97 lines
2.8 KiB
C#
Raw Normal View History

2019-06-13 02:51:36 +00:00
using NUnit.Framework;
2019-06-14 03:41:21 +00:00
using System.Linq;
2019-06-13 02:51:36 +00:00
2019-06-15 00:03:56 +00:00
using Encompass;
namespace Tests {
struct MockComponent : IComponent {
public string myString;
public int myInt;
}
2019-06-13 02:51:36 +00:00
2019-06-15 00:03:56 +00:00
public class EntityTest
{
[Test]
public void AddComponent()
2019-06-13 02:51:36 +00:00
{
2019-06-15 00:03:56 +00:00
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
2019-06-15 00:03:56 +00:00
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
2019-06-14 05:15:15 +00:00
2019-06-15 00:03:56 +00:00
entity.AddComponent<MockComponent>(mockComponent);
2019-06-13 02:51:36 +00:00
2019-06-15 00:03:56 +00:00
var world = worldBuilder.Build();
// world.Update();
2019-06-15 00:03:56 +00:00
Assert.IsTrue(entity.HasComponent<MockComponent>());
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
}
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
[Test]
public void GetComponents()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
MockComponent mockComponentA;
mockComponentA.myInt = 3;
mockComponentA.myString = "hello";
2019-06-14 05:15:15 +00:00
2019-06-15 00:03:56 +00:00
MockComponent mockComponentB;
mockComponentB.myInt = 5;
mockComponentB.myString = "wassup";
2019-06-14 05:15:15 +00:00
2019-06-15 00:03:56 +00:00
MockComponent mockComponentC;
mockComponentC.myInt = 1;
mockComponentC.myString = "howdy";
2019-06-14 05:15:15 +00:00
2019-06-15 00:03:56 +00:00
entity.AddComponent<MockComponent>(mockComponentA);
entity.AddComponent<MockComponent>(mockComponentB);
entity.AddComponent<MockComponent>(mockComponentC);
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
var world = worldBuilder.Build();
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
Assert.Contains(mockComponentA, entity.GetComponents<MockComponent>().ToList());
Assert.Contains(mockComponentB, entity.GetComponents<MockComponent>().ToList());
Assert.Contains(mockComponentC, entity.GetComponents<MockComponent>().ToList());
}
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
[Test]
public void GetComponent()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
2019-06-14 05:15:15 +00:00
2019-06-15 00:03:56 +00:00
entity.AddComponent<MockComponent>(mockComponent);
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
var world = worldBuilder.Build();
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
}
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
[Test]
public void HasComponent()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
2019-06-14 05:15:15 +00:00
2019-06-15 00:03:56 +00:00
entity.AddComponent<MockComponent>(mockComponent);
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
var world = worldBuilder.Build();
2019-06-14 03:41:21 +00:00
2019-06-15 00:03:56 +00:00
Assert.IsTrue(entity.HasComponent<MockComponent>());
2019-06-13 02:51:36 +00:00
}
}
}