< Summary

Class:Tests.EntityTests
Assembly:EntityTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/EntityTests/EntityTests.cs
Covered lines:34
Uncovered lines:0
Coverable lines:34
Total lines:96
Line coverage:100% (34 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EntityCreation()0%110100%
EntityParenting()0%110100%
EntityRemoval()0%440100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/EntityTests/EntityTests.cs

#LineLine coverage
 1using DCL.Helpers;
 2using NUnit.Framework;
 3using System.Collections;
 4using UnityEngine.TestTools;
 5
 6/*
 7* Play Mode Testing Highlights:
 8* - All Monobehaviour methods are invoked
 9* - Tests run in a standalone window
 10* - Tests may run slower, depending on the build target
 11*/
 12
 13namespace Tests
 14{
 15    public class EntityTests : IntegrationTestSuite_Legacy
 16    {
 17        [Test]
 18        public void EntityCreation()
 19        {
 20            // Create first entity
 121            string entityId = "1";
 22
 123            TestHelpers.CreateSceneEntity(scene, entityId);
 124            var entityObject = scene.entities[entityId];
 25
 126            Assert.IsTrue(entityObject != null);
 27
 128            Assert.AreEqual(entityId, entityObject.entityId);
 29
 30            // Create second entity
 131            entityObject = null;
 132            entityId = "2";
 33
 134            TestHelpers.CreateSceneEntity(scene, entityId);
 135            scene.entities.TryGetValue(entityId, out entityObject);
 36
 137            Assert.IsTrue(entityObject != null);
 38
 139            Assert.AreEqual(entityId, entityObject.entityId);
 140        }
 41
 42        [Test]
 43        public void EntityParenting()
 44        {
 145            string entityId = "2";
 146            string parentEntityId = "3";
 47
 148            TestHelpers.CreateSceneEntity(scene, entityId);
 149            TestHelpers.CreateSceneEntity(scene, parentEntityId);
 50
 151            Assert.IsTrue(
 52                scene.entities[entityId].gameObject.transform.parent == scene.gameObject.transform,
 53                "parent is set to the scene root"
 54            );
 55
 156            var parentEntityObject = scene.entities[parentEntityId];
 57
 158            TestHelpers.SetEntityParent(scene, entityId, parentEntityId);
 59
 160            Assert.IsTrue(
 61                scene.entities[entityId].gameObject.transform.parent == parentEntityObject.gameObject.transform,
 62                "parent is set to parentId"
 63            );
 64
 165            TestHelpers.SetEntityParent(scene, entityId, "0");
 66
 167            Assert.IsTrue(
 68                scene.entities[entityId].gameObject.transform.parent == scene.gameObject.transform,
 69                "parent is set back to the scene root"
 70            );
 171        }
 72
 73        [UnityTest]
 74        public IEnumerator EntityRemoval()
 75        {
 176            Assert.IsTrue(scene != null);
 77
 178            string entityId = "2";
 79
 180            TestHelpers.CreateSceneEntity(scene, entityId);
 81
 182            Assert.IsTrue(scene.entities.ContainsKey(entityId));
 83
 184            var gameObjectReference = scene.entities[entityId].gameObject;
 85
 186            TestHelpers.RemoveSceneEntity(scene, entityId);
 87
 188            yield return null;
 89
 190            Assert.IsFalse(scene.entities.ContainsKey(entityId));
 91
 192            bool isDestroyedOrPooled = gameObjectReference == null || !gameObjectReference.activeSelf;
 193            Assert.IsTrue(isDestroyedOrPooled, "Entity gameobject reference is not getting destroyed nor pooled.");
 194        }
 95    }
 96}