< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
ToggleCatalogExpanseCorrectly()0%110100%
QuickBarInputCorrectly(...)0%110100%
CatalogItemSelectedCorrectly()0%110100%
ResumeInputCorrectly()0%110100%
StopInputCorrectly()0%110100%
HideCatalogClickedCorrectly()0%110100%
GetAssetsListByCategoryCorrectly()0%110100%
SceneCatalogBackCorrectly(...)0%330100%
CheckIfCatalogIsOpenCorrectly()0%110100%
CheckIfCatalogIsExpandedCorrectly()0%110100%
ShowCategoriesCorrectly()0%110100%
ShowAssetsPacksCorrectly()0%110100%
OpenCatalogCorrectly()0%110100%
CloseCatalogCorrectly()0%110100%
SetActiveCorrectly(...)0%110100%

File(s)

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

#LineLine coverage
 1using DCL.Helpers;
 2using NSubstitute;
 3using NUnit.Framework;
 4using System.Collections.Generic;
 5using System.Linq;
 6
 7namespace Tests.BuildModeHUDControllers
 8{
 9    public class SceneCatalogControllerShould
 10    {
 11        private SceneCatalogController sceneCatalogController;
 12
 13        [SetUp]
 14        public void SetUp()
 15        {
 1916            sceneCatalogController = new SceneCatalogController();
 1917            sceneCatalogController.Initialize(
 18                Substitute.For<ISceneCatalogView>(),
 19                Substitute.For<IQuickBarController>());
 1920        }
 21
 22        [TearDown]
 3823        public void TearDown() { sceneCatalogController.Dispose(); }
 24
 25        [Test]
 26        public void ToggleCatalogExpanseCorrectly()
 27        {
 28            // Act
 129            sceneCatalogController.ToggleCatalogExpanse();
 30
 31            // Assert
 132            sceneCatalogController.sceneCatalogView.Received(1).ToggleCatalogExpanse();
 133        }
 34
 35        [Test]
 36        [TestCase(0)]
 37        [TestCase(1)]
 38        [TestCase(2)]
 39        public void QuickBarInputCorrectly(int quickBarSlot)
 40        {
 41            // Act
 342            sceneCatalogController.QuickBarInput(quickBarSlot);
 43
 44            // Assert
 345            sceneCatalogController.quickBarController.Received(1).QuickBarObjectSelected(quickBarSlot);
 346        }
 47
 48        [Test]
 49        public void CatalogItemSelectedCorrectly()
 50        {
 51            // Arrange
 152            CatalogItem testCatalogItem = new CatalogItem { id = "test id" };
 153            CatalogItem returnedCatalogItem = null;
 354            sceneCatalogController.OnCatalogItemSelected += (catalogItem) => { returnedCatalogItem = catalogItem; };
 55
 56            // Act
 157            sceneCatalogController.CatalogItemSelected(testCatalogItem);
 58
 59            // Assert
 160            Assert.AreEqual(testCatalogItem, returnedCatalogItem, "The catalog item does not match!");
 161        }
 62
 63        [Test]
 64        public void ResumeInputCorrectly()
 65        {
 66            // Arrange
 167            bool resumeInput = false;
 368            sceneCatalogController.OnResumeInput += () => { resumeInput = true; };
 69
 70            // Act
 171            sceneCatalogController.ResumeInput();
 72
 73            // Assert
 174            Assert.IsTrue(resumeInput, "The resumeInput is false!");
 175        }
 76
 77        [Test]
 78        public void StopInputCorrectly()
 79        {
 80            // Arrange
 181            bool stopInput = false;
 382            sceneCatalogController.OnStopInput += () => { stopInput = true; };
 83
 84            // Act
 185            sceneCatalogController.StopInput();
 86
 87            // Assert
 188            Assert.IsTrue(stopInput, "The stopInput is false!");
 189        }
 90
 91        [Test]
 92        public void HideCatalogClickedCorrectly()
 93        {
 94            // Arrange
 195            bool hideCatalogClicked = false;
 396            sceneCatalogController.OnHideCatalogClicked += () => { hideCatalogClicked = true; };
 97
 98            // Act
 199            sceneCatalogController.HideCatalogClicked();
 100
 101            // Assert
 1102            Assert.IsTrue(hideCatalogClicked, "The hideCatalogClicked is false!");
 1103        }
 104
 105        [Test]
 106        public void GetAssetsListByCategoryCorrectly()
 107        {
 108            // Arrange
 1109            string testCategoryA = "test category A";
 1110            string testCategoryB = "test category B";
 1111            CatalogItemPack testDceneAssetPack = new CatalogItemPack
 112            {
 113                assets = new List<CatalogItem>
 114                {
 115                    new CatalogItem { id = "testItemId1", categoryName = testCategoryA },
 116                    new CatalogItem { id = "testItemId2", categoryName = testCategoryA },
 117                    new CatalogItem { id = "testItemId3", categoryName = testCategoryB }
 118                }
 119            };
 120
 121            // Act
 1122            List<CatalogItem> result = sceneCatalogController.GetAssetsListByCategory(testCategoryA, testDceneAssetPack)
 123
 124            // Assert
 3125            Assert.AreEqual(2, result.Count(x => x.categoryName == testCategoryA), "The number of returned catalog items
 3126            Assert.AreEqual(0, result.Count(x => x.categoryName == testCategoryB), "The number of returned catalog items
 1127        }
 128
 129        [Test]
 130        [TestCase(true)]
 131        [TestCase(false)]
 132        public void SceneCatalogBackCorrectly(bool isShowingAssetPacks)
 133        {
 134            // Arrange
 2135            sceneCatalogController.isShowingAssetPacks = isShowingAssetPacks;
 136
 137            // Act
 2138            sceneCatalogController.SceneCatalogBack();
 139
 140            // Assert
 2141            sceneCatalogController.sceneCatalogView.Received(isShowingAssetPacks ? 1 : 0).CloseCatalog();
 2142        }
 143
 144        [Test]
 145        public void CheckIfCatalogIsOpenCorrectly()
 146        {
 147            // Act
 1148            sceneCatalogController.IsCatalogOpen();
 149
 150            // Assert
 1151            sceneCatalogController.sceneCatalogView.Received(1).IsCatalogOpen();
 1152        }
 153
 154        [Test]
 155        public void CheckIfCatalogIsExpandedCorrectly()
 156        {
 157            // Act
 1158            sceneCatalogController.IsCatalogExpanded();
 159
 160            // Assert
 1161            sceneCatalogController.sceneCatalogView.Received(1).IsCatalogExpanded();
 1162        }
 163
 164        [Test]
 165        public void ShowCategoriesCorrectly()
 166        {
 167            // Arrange
 1168            sceneCatalogController.isShowingAssetPacks = false;
 169
 170            // Act
 1171            sceneCatalogController.ShowCategories();
 172
 173            // Assert
 1174            Assert.IsTrue(sceneCatalogController.isShowingAssetPacks, "The isShowingAssetPacks is false!");
 1175            sceneCatalogController.sceneCatalogView.Received(1).SetCatalogTitle(Arg.Any<string>());
 1176            sceneCatalogController.sceneCatalogView.Received(1).ShowBackButton(false);
 1177        }
 178
 179        [Test]
 180        public void ShowAssetsPacksCorrectly()
 181        {
 182            // Arrange
 1183            sceneCatalogController.isShowingAssetPacks = false;
 184
 185            // Act
 1186            sceneCatalogController.ShowAssetsPacks();
 187
 188            // Assert
 1189            Assert.IsTrue(sceneCatalogController.isShowingAssetPacks, "The isShowingAssetPacks is false!");
 1190            sceneCatalogController.sceneCatalogView.Received(1).SetCatalogTitle(Arg.Any<string>());
 1191            sceneCatalogController.sceneCatalogView.Received(1).ShowBackButton(false);
 1192        }
 193
 194        [Test]
 195        public void OpenCatalogCorrectly()
 196        {
 197            // Arrange
 1198            Utils.LockCursor();
 199
 200            // Act
 1201            sceneCatalogController.OpenCatalog();
 202
 203            // Assert
 1204            Assert.IsFalse(Utils.isCursorLocked, "The cursor is locked!");
 1205            sceneCatalogController.sceneCatalogView.Received(1).SetActive(true);
 1206        }
 207
 208        [Test]
 209        public void CloseCatalogCorrectly()
 210        {
 211            // Act
 1212            sceneCatalogController.CloseCatalog();
 213
 214            // Assert
 1215            sceneCatalogController.sceneCatalogView.Received(1).CloseCatalog();
 1216        }
 217
 218        [Test]
 219        [TestCase(true)]
 220        [TestCase(false)]
 221        public void SetActiveCorrectly(bool isActive)
 222        {
 223            // Act
 2224            sceneCatalogController.SetActive(isActive);
 225
 226            // Assert
 2227            sceneCatalogController.sceneCatalogView.Received(1).SetActive(isActive);
 2228        }
 229    }
 230}