< Summary

Class:BIWCreatorShould
Assembly:BuilderInWorldTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Tests/BIWCreatorShould.cs
Covered lines:84
Uncovered lines:0
Coverable lines:84
Total lines:185
Line coverage:100% (84 of 84)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
CreateItem()0%220100%
CreateLastItem()0%330100%
LoadingGameObjectCreation()0%110100%
LoadingGameObjectDestruction()0%110100%
ErrorGameObjectCreation()0%110100%
ErrorGameObjectDestruction()0%110100%
CatalogItemAddMapings()0%440100%
TearDown()0%440100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Tests/BIWCreatorShould.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL;
 5using DCL.Components;
 6using DCL.Helpers;
 7using DCL.Models;
 8using NUnit.Framework;
 9using UnityEngine;
 10using UnityEngine.TestTools;
 11
 12public class BIWCreatorShould : IntegrationTestSuite_Legacy
 13{
 14    private BuilderInWorldEntityHandler entityHandler;
 15    private BuilderInWorldController controller;
 16    private BIWCreatorController biwCreatorController;
 17
 18    protected override IEnumerator SetUp()
 19    {
 720        yield return base.SetUp();
 721        controller = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0];
 22
 723        biwCreatorController = controller.biwCreatorController;
 724        biwCreatorController.Init();
 725        entityHandler = controller.builderInWorldEntityHandler;
 726        entityHandler.Init();
 27
 728        entityHandler.EnterEditMode(scene);
 729        biwCreatorController.EnterEditMode(scene);
 730    }
 31
 32    [Test]
 33    public void CreateItem()
 34    {
 35        //Arrange
 136        BIWCatalogManager.Init();
 137        BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject();
 138        CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 39
 40        //Act
 141        biwCreatorController.CreateCatalogItem(item);
 42
 43        //Assert
 444        foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
 45        {
 146            Assert.IsTrue(entity.GetCatalogItemAssociated().id == item.id);
 147            Assert.AreEqual(Vector3.zero, entity.GetEulerRotation());
 48        }
 149    }
 50
 51    [Test]
 52    public void CreateLastItem()
 53    {
 54        //Arrange
 155        BIWCatalogManager.Init();
 156        BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject();
 157        CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 58
 59        //Act
 160        biwCreatorController.CreateCatalogItem(item);
 161        biwCreatorController.CreateLastCatalogItem();
 62
 63        //Assert
 164        int cont = 0;
 665        foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
 66        {
 267            if (entity.GetCatalogItemAssociated().id == item.id)
 268                cont++;
 69        }
 170        Assert.AreEqual(cont, 2);
 171    }
 72
 73    [Test]
 74    public void LoadingGameObjectCreation()
 75    {
 76        //Arrange
 177        BIWCatalogManager.Init();
 178        BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject();
 179        CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 80
 81        //Act
 182        biwCreatorController.CreateCatalogItem(item);
 83
 84        //Assert
 185        DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault();
 186        Assert.IsTrue(biwCreatorController.ExistsLoadingGameObjectForEntity(entity.rootEntity.entityId));
 187    }
 88
 89    [Test]
 90    public void LoadingGameObjectDestruction()
 91    {
 92        //Arrange
 193        BIWCatalogManager.Init();
 194        BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject();
 195        CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 96
 97        //Act
 198        biwCreatorController.CreateCatalogItem(item);
 199        DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault();
 1100        biwCreatorController.RemoveLoadingObject(entity.rootEntity.entityId);
 101
 102        //Assert
 1103        Assert.IsFalse(biwCreatorController.ExistsLoadingGameObjectForEntity(entity.rootEntity.entityId));
 1104    }
 105
 106    [Test]
 107    public void ErrorGameObjectCreation()
 108    {
 109        //Arrange
 1110        BIWCatalogManager.Init();
 1111        BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject();
 1112        CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 1113        biwCreatorController.CreateCatalogItem(item);
 1114        DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault();
 115
 116        //Act
 1117        biwCreatorController.CreateErrorOnEntity(entity);
 118
 119        //Assert
 1120        Assert.IsTrue(biwCreatorController.IsAnyErrorOnEntities());
 1121    }
 122
 123    [Test]
 124    public void ErrorGameObjectDestruction()
 125    {
 126        //Arrange
 1127        BIWCatalogManager.Init();
 1128        BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject();
 1129        CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 1130        biwCreatorController.CreateCatalogItem(item);
 1131        DCLBuilderInWorldEntity entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault();
 1132        biwCreatorController.CreateErrorOnEntity(entity);
 133
 134        //Act
 1135        biwCreatorController.DeleteErrorOnEntity(entity);
 136
 137        //Assert
 1138        Assert.IsFalse(biwCreatorController.IsAnyErrorOnEntities());
 1139    }
 140
 141    [Test]
 142    public void CatalogItemAddMapings()
 143    {
 144        //Arrange
 1145        BIWCatalogManager.Init();
 1146        BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject();
 1147        CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 148
 149        //Act
 1150        biwCreatorController.CreateCatalogItem(item);
 151
 152        //Assert
 1153        LoadParcelScenesMessage.UnityParcelScene data = scene.sceneData;
 4154        foreach (KeyValuePair<string, string> content in item.contents)
 155        {
 1156            ContentServerUtils.MappingPair mappingPair = new ContentServerUtils.MappingPair();
 1157            mappingPair.file = content.Key;
 1158            mappingPair.hash = content.Value;
 1159            bool found = false;
 3160            foreach (ContentServerUtils.MappingPair mappingPairToCheck in data.contents)
 161            {
 1162                if (mappingPairToCheck.file == mappingPair.file)
 163                {
 1164                    found = true;
 1165                    break;
 166                }
 167            }
 1168            Assert.IsTrue(found);
 169        }
 1170    }
 171
 172    protected override IEnumerator TearDown()
 173    {
 7174        BIWCatalogManager.ClearCatalog();
 7175        BuilderInWorldNFTController.i.ClearNFTs();
 7176        controller.CleanItems();
 30177        foreach (var placeHolder in GameObject.FindObjectsOfType<BIWLoadingPlaceHolder>())
 178        {
 8179            placeHolder.Dispose();
 180        }
 7181        biwCreatorController.Clean();
 182
 7183        yield return base.TearDown();
 7184    }
 185}