| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL; |
| | 5 | | using DCL.Components; |
| | 6 | | using DCL.Helpers; |
| | 7 | | using DCL.Models; |
| | 8 | | using NUnit.Framework; |
| | 9 | | using UnityEngine; |
| | 10 | | using UnityEngine.TestTools; |
| | 11 | |
|
| | 12 | | public class BIWCreatorShould : IntegrationTestSuite_Legacy |
| | 13 | | { |
| | 14 | | private BuilderInWorldEntityHandler entityHandler; |
| | 15 | | private BuilderInWorldController controller; |
| | 16 | | private BIWCreatorController biwCreatorController; |
| | 17 | |
|
| | 18 | | protected override IEnumerator SetUp() |
| | 19 | | { |
| 7 | 20 | | yield return base.SetUp(); |
| 7 | 21 | | controller = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0]; |
| | 22 | |
|
| 7 | 23 | | biwCreatorController = controller.biwCreatorController; |
| 7 | 24 | | biwCreatorController.Init(); |
| 7 | 25 | | entityHandler = controller.builderInWorldEntityHandler; |
| 7 | 26 | | entityHandler.Init(); |
| | 27 | |
|
| 7 | 28 | | entityHandler.EnterEditMode(scene); |
| 7 | 29 | | biwCreatorController.EnterEditMode(scene); |
| 7 | 30 | | } |
| | 31 | |
|
| | 32 | | [Test] |
| | 33 | | public void CreateItem() |
| | 34 | | { |
| | 35 | | //Arrange |
| 1 | 36 | | BIWCatalogManager.Init(); |
| 1 | 37 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 38 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 39 | |
|
| | 40 | | //Act |
| 1 | 41 | | biwCreatorController.CreateCatalogItem(item); |
| | 42 | |
|
| | 43 | | //Assert |
| 4 | 44 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 45 | | { |
| 1 | 46 | | Assert.IsTrue(entity.GetCatalogItemAssociated().id == item.id); |
| 1 | 47 | | Assert.AreEqual(Vector3.zero, entity.GetEulerRotation()); |
| | 48 | | } |
| 1 | 49 | | } |
| | 50 | |
|
| | 51 | | [Test] |
| | 52 | | public void CreateLastItem() |
| | 53 | | { |
| | 54 | | //Arrange |
| 1 | 55 | | BIWCatalogManager.Init(); |
| 1 | 56 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 57 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 58 | |
|
| | 59 | | //Act |
| 1 | 60 | | biwCreatorController.CreateCatalogItem(item); |
| 1 | 61 | | biwCreatorController.CreateLastCatalogItem(); |
| | 62 | |
|
| | 63 | | //Assert |
| 1 | 64 | | int cont = 0; |
| 6 | 65 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 66 | | { |
| 2 | 67 | | if (entity.GetCatalogItemAssociated().id == item.id) |
| 2 | 68 | | cont++; |
| | 69 | | } |
| 1 | 70 | | Assert.AreEqual(cont, 2); |
| 1 | 71 | | } |
| | 72 | |
|
| | 73 | | [Test] |
| | 74 | | public void LoadingGameObjectCreation() |
| | 75 | | { |
| | 76 | | //Arrange |
| 1 | 77 | | BIWCatalogManager.Init(); |
| 1 | 78 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 79 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 80 | |
|
| | 81 | | //Act |
| 1 | 82 | | biwCreatorController.CreateCatalogItem(item); |
| | 83 | |
|
| | 84 | | //Assert |
| 1 | 85 | | DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault(); |
| 1 | 86 | | Assert.IsTrue(biwCreatorController.ExistsLoadingGameObjectForEntity(entity.rootEntity.entityId)); |
| 1 | 87 | | } |
| | 88 | |
|
| | 89 | | [Test] |
| | 90 | | public void LoadingGameObjectDestruction() |
| | 91 | | { |
| | 92 | | //Arrange |
| 1 | 93 | | BIWCatalogManager.Init(); |
| 1 | 94 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 95 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 96 | |
|
| | 97 | | //Act |
| 1 | 98 | | biwCreatorController.CreateCatalogItem(item); |
| 1 | 99 | | DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault(); |
| 1 | 100 | | biwCreatorController.RemoveLoadingObject(entity.rootEntity.entityId); |
| | 101 | |
|
| | 102 | | //Assert |
| 1 | 103 | | Assert.IsFalse(biwCreatorController.ExistsLoadingGameObjectForEntity(entity.rootEntity.entityId)); |
| 1 | 104 | | } |
| | 105 | |
|
| | 106 | | [Test] |
| | 107 | | public void ErrorGameObjectCreation() |
| | 108 | | { |
| | 109 | | //Arrange |
| 1 | 110 | | BIWCatalogManager.Init(); |
| 1 | 111 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 112 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| 1 | 113 | | biwCreatorController.CreateCatalogItem(item); |
| 1 | 114 | | DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault(); |
| | 115 | |
|
| | 116 | | //Act |
| 1 | 117 | | biwCreatorController.CreateErrorOnEntity(entity); |
| | 118 | |
|
| | 119 | | //Assert |
| 1 | 120 | | Assert.IsTrue(biwCreatorController.IsAnyErrorOnEntities()); |
| 1 | 121 | | } |
| | 122 | |
|
| | 123 | | [Test] |
| | 124 | | public void ErrorGameObjectDestruction() |
| | 125 | | { |
| | 126 | | //Arrange |
| 1 | 127 | | BIWCatalogManager.Init(); |
| 1 | 128 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 129 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| 1 | 130 | | biwCreatorController.CreateCatalogItem(item); |
| 1 | 131 | | DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault(); |
| 1 | 132 | | biwCreatorController.CreateErrorOnEntity(entity); |
| | 133 | |
|
| | 134 | | //Act |
| 1 | 135 | | biwCreatorController.DeleteErrorOnEntity(entity); |
| | 136 | |
|
| | 137 | | //Assert |
| 1 | 138 | | Assert.IsFalse(biwCreatorController.IsAnyErrorOnEntities()); |
| 1 | 139 | | } |
| | 140 | |
|
| | 141 | | [Test] |
| | 142 | | public void CatalogItemAddMapings() |
| | 143 | | { |
| | 144 | | //Arrange |
| 1 | 145 | | BIWCatalogManager.Init(); |
| 1 | 146 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 147 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 148 | |
|
| | 149 | | //Act |
| 1 | 150 | | biwCreatorController.CreateCatalogItem(item); |
| | 151 | |
|
| | 152 | | //Assert |
| 1 | 153 | | LoadParcelScenesMessage.UnityParcelScene data = scene.sceneData; |
| 4 | 154 | | foreach (KeyValuePair<string, string> content in item.contents) |
| | 155 | | { |
| 1 | 156 | | ContentServerUtils.MappingPair mappingPair = new ContentServerUtils.MappingPair(); |
| 1 | 157 | | mappingPair.file = content.Key; |
| 1 | 158 | | mappingPair.hash = content.Value; |
| 1 | 159 | | bool found = false; |
| 3 | 160 | | foreach (ContentServerUtils.MappingPair mappingPairToCheck in data.contents) |
| | 161 | | { |
| 1 | 162 | | if (mappingPairToCheck.file == mappingPair.file) |
| | 163 | | { |
| 1 | 164 | | found = true; |
| 1 | 165 | | break; |
| | 166 | | } |
| | 167 | | } |
| 1 | 168 | | Assert.IsTrue(found); |
| | 169 | | } |
| 1 | 170 | | } |
| | 171 | |
|
| | 172 | | protected override IEnumerator TearDown() |
| | 173 | | { |
| 7 | 174 | | BIWCatalogManager.ClearCatalog(); |
| 7 | 175 | | BuilderInWorldNFTController.i.ClearNFTs(); |
| 7 | 176 | | controller.CleanItems(); |
| 30 | 177 | | foreach (var placeHolder in GameObject.FindObjectsOfType<BIWLoadingPlaceHolder>()) |
| | 178 | | { |
| 8 | 179 | | placeHolder.Dispose(); |
| | 180 | | } |
| 7 | 181 | | biwCreatorController.Clean(); |
| | 182 | |
|
| 7 | 183 | | yield return base.TearDown(); |
| 7 | 184 | | } |
| | 185 | | } |