From 116f424262e90ee6720e625477f1753412ccbf85 Mon Sep 17 00:00:00 2001 From: Evan Hemsley <2342303+ehemsley@users.noreply.github.com> Date: Wed, 19 Jun 2019 18:10:39 -0700 Subject: [PATCH] more entity tests --- test/EntityTest.cs | 62 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/test/EntityTest.cs b/test/EntityTest.cs index 3eb8ffc..445bc51 100644 --- a/test/EntityTest.cs +++ b/test/EntityTest.cs @@ -1,8 +1,6 @@ using NUnit.Framework; using FluentAssertions; -using System.Linq; - using Encompass; using System.Collections.Generic; using System; @@ -27,10 +25,9 @@ namespace Tests mockComponent.myInt = 3; mockComponent.myString = "hello"; - entity.AddComponent(mockComponent); + entity.AddComponent(mockComponent); var world = worldBuilder.Build(); - // world.Update(); Assert.IsTrue(entity.HasComponent()); Assert.That(entity.GetComponent().Value, Is.EqualTo(mockComponent)); @@ -54,9 +51,9 @@ namespace Tests mockComponentC.myInt = 1; mockComponentC.myString = "howdy"; - var componentAID = entity.AddComponent(mockComponentA); - var componentBID = entity.AddComponent(mockComponentB); - var componentCID = entity.AddComponent(mockComponentC); + var componentAID = entity.AddComponent(mockComponentA); + var componentBID = entity.AddComponent(mockComponentB); + var componentCID = entity.AddComponent(mockComponentC); var world = worldBuilder.Build(); @@ -120,5 +117,56 @@ namespace Tests Assert.IsFalse(entity.HasComponent()); } + + [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()); + Assert.IsEmpty(entity.GetComponents()); + } + + [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()); + Assert.IsEmpty(entity.GetComponents()); + + entity.ActivateComponent(componentID); + + world.Update(0.01f); + + Assert.IsTrue(entity.HasComponent()); + Assert.IsNotEmpty(entity.GetComponents()); + } } }