public void TestCreateEntity()
        {
            // Test if unique IDs are being created.
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();

            Assert.IsNotNull(entity, "Creating entity failed.");
        }
        public void TestGetEntitiesByTagUnhappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "TagA";
            var foundEntities = manager.GetEntitiesByTag ("TagB");

            Assert.IsTrue(foundEntities.ToArray().Length == 0, "Retrieving existing entities by invalid tag failed.");
        }
        public void TestGetEntitiesByComponentTypeUnhappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.AddComponent (new MoveComponent());
            var foundEntities = manager.GetEntitiesByComponentType (typeof(HealthComponent));

            Assert.IsTrue(foundEntities.ToArray().Length == 0, "Retrieving entities by not existing component type failed.");
        }
Пример #4
0
        public void TestEntityGetComponentsByTypeUnhappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";
            entity.AddComponent (new MoveComponent());

            var a = entity.GetComponentsByType<HealthComponent>();
            Assert.IsTrue(a.ToArray().Length == 0, "Getting non-existing entity component by type failed.");
        }
Пример #5
0
        public void TestEntityGetFirstComponentOfTypeHappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";
            entity.AddComponent (new MoveComponent());
            entity.AddComponent (new HealthComponent());

            MoveComponent o = entity.GetFirstComponentOfType<MoveComponent>() as MoveComponent;
            Assert.IsTrue(o != null && o.GetType() == typeof(MoveComponent), "Getting existing entity component of type failed.");
        }
Пример #6
0
        public void TestUpdate()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";
            entity.AddComponent (new MoveComponent());
            entity.AddComponent (new HealthComponent(10));

            var system = new HealthSystem (manager);
            system.Update (0f);
            var healthComponent = entity.GetFirstComponentOfType<HealthComponent>() as HealthComponent;
            healthComponent.CurrentHealthPoints = -1;
            system.Update (1f);
            Assert.IsFalse (healthComponent.IsAlive, "Updating health system failed.");
        }
Пример #7
0
        public void TestEntityAddComponent()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";

            // Add two move components.
            entity.AddComponent (new MoveComponent ());
            entity.AddComponent (new MoveComponent ());

            // Add one health component.
            entity.AddComponent (new HealthComponent ());

            Assert.IsTrue(entity.GetComponentsByType<MoveComponent>().ToArray().Length == 2 && entity.GetComponentsByType<HealthComponent>().ToArray().Length == 1, "Adding components failed.");
        }
        public void TestGetEntityByIDHappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            var checkEntity = manager.GetEntityByID (entity.UniqueId);

            Assert.IsTrue(entity == checkEntity, "Retrieving existing entity by ID failed.");
        }
 public void TestHasEntityWithIDUnhappyPath()
 {
     var manager = new DemoEntityManager ();
     var entity = manager.CreateEntity ();
     Console.WriteLine ("Added entiry: " + entity.UniqueId);
     IComparable nonExistingID = DemoEntity.RandomGuid ();
     bool b = manager.HasEntityWithID (nonExistingID);
     Console.WriteLine ("Looking up " + nonExistingID + "; " + b);
     Assert.IsFalse(b, "Checking for non existing entity ID failed.");
 }
        public void TestHasEntityWithIDHappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            bool b = manager.HasEntityWithID (entity.UniqueId);

            Assert.IsTrue(b, "Checking for existing entity ID failed.");
        }
 public void TestGetEntityByIDUnhappyPath()
 {
     var manager = new DemoEntityManager ();
     var entity = manager.CreateEntity ();
     IComparable nonExistingID = DemoEntity.RandomGuid ();
     var checkEntity = manager.GetEntityByID (nonExistingID);
     Console.WriteLine ("CHECK: " + entity);
     Console.WriteLine ("CHECK: " + nonExistingID);
     Console.WriteLine ("CHECK: " + checkEntity);
     Assert.IsNull(checkEntity, "Retrieving non existing entity by ID failed.");
 }
Пример #12
0
        public void TestEntityGetFirstComponentOfTypeUnhappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";
            entity.AddComponent (new MoveComponent());

            var o = entity.GetFirstComponentOfType<HealthComponent>();
            Assert.IsTrue(o == null, "Getting non-existing entity component of type failed.");
        }
Пример #13
0
        public void TestEntityTag()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";

            Assert.IsTrue(((string)entity.Tag) == "A string tag", "Reading entity tag failed.");
        }
Пример #14
0
        public void TestEntityRemoveComponent()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";

            var move1 = new MoveComponent ()
            {
                dX = 1f,
                dY = 1f
            };

            var move2 = new MoveComponent ()
            {
                dX = 2f,
                dY = 2f
            };

            // Add two move components.
            entity.AddComponent (move1);
            entity.AddComponent (move2);

            // Add one health component.
            entity.AddComponent (new HealthComponent ());

            bool b = entity.RemoveComponent (move2);

            // Asure that the move2 component has been removed and move1 is still in the entity.
            var move1Compare = entity.GetFirstComponentOfType<MoveComponent>() as MoveComponent;
            // Also assure that move2 is really gone and only one move component is left.
            var remainingMoveComponents = entity.GetComponentsByType<MoveComponent>().ToArray();

            Assert.IsTrue(b && move1Compare.dX == move1.dX && remainingMoveComponents.Length == 1, "Removing component failed.");
        }
Пример #15
0
        public void TestEntityHasComponentByTypeUnhappyPath()
        {
            var manager = new DemoEntityManager ();
            var entity = manager.CreateEntity ();
            entity.Tag = "A string tag";
            entity.AddComponent (new MoveComponent());

            bool b = entity.HasComponentOfType<HealthComponent>();
            Assert.IsFalse(b, "Getting non-existing entity component by type failed.");
        }