| | 1 | | using DCL.Helpers; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections; |
| | 4 | | using 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 | |
|
| | 13 | | namespace Tests |
| | 14 | | { |
| | 15 | | public class EntityTests : IntegrationTestSuite_Legacy |
| | 16 | | { |
| | 17 | | [Test] |
| | 18 | | public void EntityCreation() |
| | 19 | | { |
| | 20 | | // Create first entity |
| 1 | 21 | | string entityId = "1"; |
| | 22 | |
|
| 1 | 23 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 1 | 24 | | var entityObject = scene.entities[entityId]; |
| | 25 | |
|
| 1 | 26 | | Assert.IsTrue(entityObject != null); |
| | 27 | |
|
| 1 | 28 | | Assert.AreEqual(entityId, entityObject.entityId); |
| | 29 | |
|
| | 30 | | // Create second entity |
| 1 | 31 | | entityObject = null; |
| 1 | 32 | | entityId = "2"; |
| | 33 | |
|
| 1 | 34 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 1 | 35 | | scene.entities.TryGetValue(entityId, out entityObject); |
| | 36 | |
|
| 1 | 37 | | Assert.IsTrue(entityObject != null); |
| | 38 | |
|
| 1 | 39 | | Assert.AreEqual(entityId, entityObject.entityId); |
| 1 | 40 | | } |
| | 41 | |
|
| | 42 | | [Test] |
| | 43 | | public void EntityParenting() |
| | 44 | | { |
| 1 | 45 | | string entityId = "2"; |
| 1 | 46 | | string parentEntityId = "3"; |
| | 47 | |
|
| 1 | 48 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 1 | 49 | | TestHelpers.CreateSceneEntity(scene, parentEntityId); |
| | 50 | |
|
| 1 | 51 | | Assert.IsTrue( |
| | 52 | | scene.entities[entityId].gameObject.transform.parent == scene.gameObject.transform, |
| | 53 | | "parent is set to the scene root" |
| | 54 | | ); |
| | 55 | |
|
| 1 | 56 | | var parentEntityObject = scene.entities[parentEntityId]; |
| | 57 | |
|
| 1 | 58 | | TestHelpers.SetEntityParent(scene, entityId, parentEntityId); |
| | 59 | |
|
| 1 | 60 | | Assert.IsTrue( |
| | 61 | | scene.entities[entityId].gameObject.transform.parent == parentEntityObject.gameObject.transform, |
| | 62 | | "parent is set to parentId" |
| | 63 | | ); |
| | 64 | |
|
| 1 | 65 | | TestHelpers.SetEntityParent(scene, entityId, "0"); |
| | 66 | |
|
| 1 | 67 | | Assert.IsTrue( |
| | 68 | | scene.entities[entityId].gameObject.transform.parent == scene.gameObject.transform, |
| | 69 | | "parent is set back to the scene root" |
| | 70 | | ); |
| 1 | 71 | | } |
| | 72 | |
|
| | 73 | | [UnityTest] |
| | 74 | | public IEnumerator EntityRemoval() |
| | 75 | | { |
| 1 | 76 | | Assert.IsTrue(scene != null); |
| | 77 | |
|
| 1 | 78 | | string entityId = "2"; |
| | 79 | |
|
| 1 | 80 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 81 | |
|
| 1 | 82 | | Assert.IsTrue(scene.entities.ContainsKey(entityId)); |
| | 83 | |
|
| 1 | 84 | | var gameObjectReference = scene.entities[entityId].gameObject; |
| | 85 | |
|
| 1 | 86 | | TestHelpers.RemoveSceneEntity(scene, entityId); |
| | 87 | |
|
| 1 | 88 | | yield return null; |
| | 89 | |
|
| 1 | 90 | | Assert.IsFalse(scene.entities.ContainsKey(entityId)); |
| | 91 | |
|
| 1 | 92 | | bool isDestroyedOrPooled = gameObjectReference == null || !gameObjectReference.activeSelf; |
| 1 | 93 | | Assert.IsTrue(isDestroyedOrPooled, "Entity gameobject reference is not getting destroyed nor pooled."); |
| 1 | 94 | | } |
| | 95 | | } |
| | 96 | | } |