< Summary

Class:Tests.BuildModeHUDControllers.EntityInformationControllerShould
Assembly:BuildModeHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Tests/EntityInformationControllerShould.cs
Covered lines:108
Uncovered lines:0
Coverable lines:108
Total lines:308
Line coverage:100% (108 of 108)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
PositionChangedCorrectly()0%110100%
RotationChangedCorrectly()0%110100%
ScaleChangedCorrectly()0%110100%
NameChangedCorrectly()0%110100%
ToggleDetailsInfoCorrectly()0%110100%
ToggleBasicInfoCorrectly()0%110100%
StartChangingNameCorrectly()0%110100%
EndChangingNameCorrectly()0%110100%
SetEntityCorrectly()0%110100%
GetThumbnailCorrectly()0%110100%
SetThumbnailCorrectly()0%110100%
UpdateEntityNameCorrectly()0%110100%
UpdateLimitsInformationCorrectly(...)0%880100%
SetEnableCorrectly()0%110100%
SetDisableCorrectly()0%110100%
UpdateInfoCorrectly()0%110100%
UpdateEntitiesSelectionCorrectly(...)0%110100%
SetTransparencyModeCorrectly(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Tests/EntityInformationControllerShould.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using NSubstitute;
 6using NUnit.Framework;
 7using UnityEngine;
 8
 9namespace Tests.BuildModeHUDControllers
 10{
 11    public class EntityInformationControllerShould
 12    {
 13        private EntityInformationController entityInformationController;
 14
 15        [SetUp]
 16        public void SetUp()
 17        {
 2118            entityInformationController = new EntityInformationController();
 2119            entityInformationController.Initialize(Substitute.For<IEntityInformationView>());
 2120            Environment.i.platform.webRequest.Initialize(
 21                genericWebRequest: new WebRequest(),
 22                assetBundleWebRequest: new WebRequestAssetBundle(),
 23                textureWebRequest: new WebRequestTexture(),
 24                audioWebRequest: new WebRequestAudio());
 2125        }
 26
 27        [TearDown]
 28        public void TearDown()
 29        {
 2130            entityInformationController.Dispose();
 2131            Environment.i.platform.webRequest.Dispose();
 2132        }
 33
 34        [Test]
 35        public void PositionChangedCorrectly()
 36        {
 37            // Arrange
 138            Vector3 testPos = new Vector3(5, 7, 0);
 139            Vector3 returnedPos = Vector3.zero;
 340            entityInformationController.OnPositionChange += (pos) => { returnedPos = pos; };
 41
 42            // Act
 143            entityInformationController.PositionChanged(testPos);
 44
 45            // Assert
 146            Assert.AreEqual(testPos, returnedPos, "The position does not match!");
 147        }
 48
 49        [Test]
 50        public void RotationChangedCorrectly()
 51        {
 52            // Arrange
 153            Vector3 testRot = new Vector3(5, 7, 0);
 154            Vector3 returnedRot = Vector3.zero;
 355            entityInformationController.OnRotationChange += (rot) => { returnedRot = rot; };
 56
 57            // Act
 158            entityInformationController.RotationChanged(testRot);
 59
 60            // Assert
 161            Assert.AreEqual(testRot, returnedRot, "The rotation does not match!");
 162        }
 63
 64        [Test]
 65        public void ScaleChangedCorrectly()
 66        {
 67            // Arrange
 168            Vector3 testScale = new Vector3(5, 7, 0);
 169            Vector3 returnedScale = Vector3.zero;
 370            entityInformationController.OnScaleChange += (scale) => { returnedScale = scale; };
 71
 72            // Act
 173            entityInformationController.ScaleChanged(testScale);
 74
 75            // Assert
 176            Assert.AreEqual(testScale, returnedScale, "The scale does not match!");
 177        }
 78
 79        [Test]
 80        public void NameChangedCorrectly()
 81        {
 82            // Arrange
 183            DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor
 184            string testText = "Test text";
 185            DCLBuilderInWorldEntity returnedEntity = null;
 186            string returnedText = "";
 187            entityInformationController.OnNameChange += (entity, name) =>
 88            {
 189                returnedEntity = entity;
 190                returnedText = name;
 191            };
 92
 93            // Act
 194            entityInformationController.NameChanged(testEntity, testText);
 95
 96            // Assert
 197            Assert.AreEqual(testEntity, returnedEntity, "The entity does not match!");
 198            Assert.AreEqual(testText, returnedText, "The text does not match!");
 199        }
 100
 101        [Test]
 102        public void ToggleDetailsInfoCorrectly()
 103        {
 104            // Act
 1105            entityInformationController.ToggleDetailsInfo();
 106
 107            // Assert
 1108            entityInformationController.entityInformationView.Received(1).ToggleDetailsInfo();
 1109        }
 110
 111        [Test]
 112        public void ToggleBasicInfoCorrectly()
 113        {
 114            // Act
 1115            entityInformationController.ToggleBasicInfo();
 116
 117            // Assert
 1118            entityInformationController.entityInformationView.Received(1).ToggleBasicInfo();
 1119        }
 120
 121        [Test]
 122        public void StartChangingNameCorrectly()
 123        {
 124            // Arrange
 1125            entityInformationController.isChangingName = false;
 126
 127            // Act
 1128            entityInformationController.StartChangingName();
 129
 130            // Assert
 1131            Assert.IsTrue(entityInformationController.isChangingName, "isChangingName is false!");
 1132        }
 133
 134        [Test]
 135        public void EndChangingNameCorrectly()
 136        {
 137            // Arrange
 1138            entityInformationController.isChangingName = true;
 139
 140            // Act
 1141            entityInformationController.EndChangingName();
 142
 143            // Assert
 1144            Assert.IsFalse(entityInformationController.isChangingName, "isChangingName is true!");
 1145        }
 146
 147        [Test]
 148        public void SetEntityCorrectly()
 149        {
 150            // Arrange
 1151            DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor
 1152            ParcelScene testScene = new GameObject("_ParcelScene").AddComponent<ParcelScene>();
 153
 154            // Act
 1155            entityInformationController.SetEntity(testEntity, testScene);
 156
 157            // Assert
 1158            entityInformationController.entityInformationView.Received(1).SetCurrentEntity(testEntity);
 1159            Assert.AreEqual(testScene, entityInformationController.parcelScene, "The parcel scene does not match!");
 1160            entityInformationController.entityInformationView.Received(1).SetEntityThumbnailEnable(false);
 1161        }
 162
 163        [Test]
 164        public void GetThumbnailCorrectly()
 165        {
 166            // Arrange
 1167            CatalogItem testCatalogItem = new CatalogItem();
 1168            testCatalogItem.thumbnailURL = "test url";
 1169            entityInformationController.loadedThumbnailPromise = null;
 170
 171            // Act
 1172            entityInformationController.GetThumbnail(testCatalogItem);
 173
 174            // Assert
 1175            Assert.IsNotNull(entityInformationController.loadedThumbnailPromise, "loadedThumbnailPromise is null!");
 1176        }
 177
 178        [Test]
 179        public void SetThumbnailCorrectly()
 180        {
 181            // Arrange
 1182            Asset_Texture testTexture = new Asset_Texture();
 1183            testTexture.texture = new Texture2D(20, 20);
 184
 185            // Act
 1186            entityInformationController.SetThumbnail(testTexture);
 187
 188            // Assert
 1189            entityInformationController.entityInformationView.Received(1).SetEntityThumbnailEnable(true);
 1190            entityInformationController.entityInformationView.Received(1).SetEntityThumbnailTexture(testTexture.texture)
 1191        }
 192
 193        [Test]
 194        public void UpdateEntityNameCorrectly()
 195        {
 196            // Arrange
 1197            DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor
 1198            entityInformationController.isChangingName = false;
 199
 200            // Act
 1201            entityInformationController.UpdateEntityName(testEntity);
 202
 203            // Assert
 1204            entityInformationController.entityInformationView.Received(1).SetNameIFText(Arg.Any<string>());
 1205        }
 206
 207        [Test]
 208        [TestCase(true)]
 209        [TestCase(false)]
 210        public void UpdateLimitsInformationCorrectly(bool isCatalogNull)
 211        {
 212            // Arrange
 2213            CatalogItem testCatalogItem = null;
 2214            if (!isCatalogNull)
 215            {
 1216                testCatalogItem = new CatalogItem();
 1217                testCatalogItem.metrics = new SceneObject.ObjectMetrics
 218                {
 219                    entities = 5,
 220                    bodies = 3,
 221                    triangles = 10,
 222                    textures = 2,
 223                    materials = 2,
 224                    meshes = 6
 225                };
 226            }
 227
 228            // Act
 2229            entityInformationController.UpdateLimitsInformation(testCatalogItem);
 230
 231            // Assert
 2232            entityInformationController.entityInformationView.Received(1).SeEntityLimitsText(isCatalogNull ? "" : Arg.An
 2233        }
 234
 235        [Test]
 236        public void SetEnableCorrectly()
 237        {
 238            // Arrange
 1239            entityInformationController.entityInformationView.SetActive(false);
 240
 241            // Act
 1242            entityInformationController.Enable();
 243
 244            // Assert
 1245            entityInformationController.entityInformationView.Received(1).SetActive(true);
 1246        }
 247
 248        [Test]
 249        public void SetDisableCorrectly()
 250        {
 251            // Arrange
 1252            bool hidden = false;
 1253            entityInformationController.entityInformationView.SetActive(true);
 254
 1255            entityInformationController.OnDisable += () =>
 256            {
 1257                hidden = true;
 1258            };
 259
 260            // Act
 1261            entityInformationController.Disable();
 262
 263            // Assert
 1264            entityInformationController.entityInformationView.Received(1).SetActive(false);
 1265            entityInformationController.entityInformationView.Received(1).SetCurrentEntity(null);
 1266            Assert.IsTrue(hidden);
 1267        }
 268
 269        [Test]
 270        public void UpdateInfoCorrectly()
 271        {
 272            // Arrange
 1273            DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor
 274
 275            // Act
 1276            entityInformationController.UpdateInfo(testEntity);
 277
 278            // Assert
 1279            entityInformationController.entityInformationView.Received(1).SetPositionAttribute(Arg.Any<Vector3>());
 1280            entityInformationController.entityInformationView.Received(1).SetRotationAttribute(Arg.Any<Vector3>());
 1281            entityInformationController.entityInformationView.Received(1).SetScaleAttribute(Arg.Any<Vector3>());
 1282        }
 283
 284        [Test]
 285        [TestCase(1)]
 286        [TestCase(5)]
 287        public void UpdateEntitiesSelectionCorrectly(int numberOfSelectedEntities)
 288        {
 289            // Act
 2290            entityInformationController.UpdateEntitiesSelection(numberOfSelectedEntities);
 291
 292            // Assert
 2293            entityInformationController.entityInformationView.Received(1).UpdateEntitiesSelection(numberOfSelectedEntiti
 2294        }
 295
 296        [Test]
 297        [TestCase(true)]
 298        [TestCase(false)]
 299        public void SetTransparencyModeCorrectly(bool isOn)
 300        {
 301            // Act
 2302            entityInformationController.SetTransparencyMode(isOn);
 303
 304            // Assert
 2305            entityInformationController.entityInformationView.Received(1).SetTransparencyMode(Arg.Any<float>(), !isOn);
 2306        }
 307    }
 308}