more entity tests

pull/5/head
Evan Hemsley 2019-06-19 18:10:39 -07:00
parent 1375adf63d
commit 116f424262
1 changed files with 55 additions and 7 deletions

View File

@ -1,8 +1,6 @@
using NUnit.Framework; using NUnit.Framework;
using FluentAssertions; using FluentAssertions;
using System.Linq;
using Encompass; using Encompass;
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
@ -27,10 +25,9 @@ namespace Tests
mockComponent.myInt = 3; mockComponent.myInt = 3;
mockComponent.myString = "hello"; mockComponent.myString = "hello";
entity.AddComponent<MockComponent>(mockComponent); entity.AddComponent(mockComponent);
var world = worldBuilder.Build(); var world = worldBuilder.Build();
// world.Update();
Assert.IsTrue(entity.HasComponent<MockComponent>()); Assert.IsTrue(entity.HasComponent<MockComponent>());
Assert.That(entity.GetComponent<MockComponent>().Value, Is.EqualTo(mockComponent)); Assert.That(entity.GetComponent<MockComponent>().Value, Is.EqualTo(mockComponent));
@ -54,9 +51,9 @@ namespace Tests
mockComponentC.myInt = 1; mockComponentC.myInt = 1;
mockComponentC.myString = "howdy"; mockComponentC.myString = "howdy";
var componentAID = entity.AddComponent<MockComponent>(mockComponentA); var componentAID = entity.AddComponent(mockComponentA);
var componentBID = entity.AddComponent<MockComponent>(mockComponentB); var componentBID = entity.AddComponent(mockComponentB);
var componentCID = entity.AddComponent<MockComponent>(mockComponentC); var componentCID = entity.AddComponent(mockComponentC);
var world = worldBuilder.Build(); var world = worldBuilder.Build();
@ -120,5 +117,56 @@ namespace Tests
Assert.IsFalse(entity.HasComponent<MockComponent>()); Assert.IsFalse(entity.HasComponent<MockComponent>());
} }
[Test]
public void RemoveComponent()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
var componentID = entity.AddComponent(mockComponent);
var world = worldBuilder.Build();
entity.RemoveComponent(componentID);
world.Update(0.01f);
Assert.IsFalse(entity.HasComponent<MockComponent>());
Assert.IsEmpty(entity.GetComponents<MockComponent>());
}
[Test]
public void ReactivateComponent()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
MockComponent mockComponent;
mockComponent.myInt = 3;
mockComponent.myString = "hello";
var componentID = entity.AddComponent(mockComponent);
var world = worldBuilder.Build();
entity.DeactivateComponent(componentID);
world.Update(0.01f);
Assert.IsFalse(entity.HasComponent<MockComponent>());
Assert.IsEmpty(entity.GetComponents<MockComponent>());
entity.ActivateComponent(componentID);
world.Update(0.01f);
Assert.IsTrue(entity.HasComponent<MockComponent>());
Assert.IsNotEmpty(entity.GetComponents<MockComponent>());
}
} }
} }