| | 1 | | using DCL.Helpers; |
| | 2 | | using NSubstitute; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | |
|
| | 7 | | namespace Tests.BuildModeHUDControllers |
| | 8 | | { |
| | 9 | | public class SceneCatalogControllerShould |
| | 10 | | { |
| | 11 | | private SceneCatalogController sceneCatalogController; |
| | 12 | |
|
| | 13 | | [SetUp] |
| | 14 | | public void SetUp() |
| | 15 | | { |
| 19 | 16 | | sceneCatalogController = new SceneCatalogController(); |
| 19 | 17 | | sceneCatalogController.Initialize( |
| | 18 | | Substitute.For<ISceneCatalogView>(), |
| | 19 | | Substitute.For<IQuickBarController>()); |
| 19 | 20 | | } |
| | 21 | |
|
| | 22 | | [TearDown] |
| 38 | 23 | | public void TearDown() { sceneCatalogController.Dispose(); } |
| | 24 | |
|
| | 25 | | [Test] |
| | 26 | | public void ToggleCatalogExpanseCorrectly() |
| | 27 | | { |
| | 28 | | // Act |
| 1 | 29 | | sceneCatalogController.ToggleCatalogExpanse(); |
| | 30 | |
|
| | 31 | | // Assert |
| 1 | 32 | | sceneCatalogController.sceneCatalogView.Received(1).ToggleCatalogExpanse(); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | [TestCase(0)] |
| | 37 | | [TestCase(1)] |
| | 38 | | [TestCase(2)] |
| | 39 | | public void QuickBarInputCorrectly(int quickBarSlot) |
| | 40 | | { |
| | 41 | | // Act |
| 3 | 42 | | sceneCatalogController.QuickBarInput(quickBarSlot); |
| | 43 | |
|
| | 44 | | // Assert |
| 3 | 45 | | sceneCatalogController.quickBarController.Received(1).QuickBarObjectSelected(quickBarSlot); |
| 3 | 46 | | } |
| | 47 | |
|
| | 48 | | [Test] |
| | 49 | | public void CatalogItemSelectedCorrectly() |
| | 50 | | { |
| | 51 | | // Arrange |
| 1 | 52 | | CatalogItem testCatalogItem = new CatalogItem { id = "test id" }; |
| 1 | 53 | | CatalogItem returnedCatalogItem = null; |
| 3 | 54 | | sceneCatalogController.OnCatalogItemSelected += (catalogItem) => { returnedCatalogItem = catalogItem; }; |
| | 55 | |
|
| | 56 | | // Act |
| 1 | 57 | | sceneCatalogController.CatalogItemSelected(testCatalogItem); |
| | 58 | |
|
| | 59 | | // Assert |
| 1 | 60 | | Assert.AreEqual(testCatalogItem, returnedCatalogItem, "The catalog item does not match!"); |
| 1 | 61 | | } |
| | 62 | |
|
| | 63 | | [Test] |
| | 64 | | public void ResumeInputCorrectly() |
| | 65 | | { |
| | 66 | | // Arrange |
| 1 | 67 | | bool resumeInput = false; |
| 3 | 68 | | sceneCatalogController.OnResumeInput += () => { resumeInput = true; }; |
| | 69 | |
|
| | 70 | | // Act |
| 1 | 71 | | sceneCatalogController.ResumeInput(); |
| | 72 | |
|
| | 73 | | // Assert |
| 1 | 74 | | Assert.IsTrue(resumeInput, "The resumeInput is false!"); |
| 1 | 75 | | } |
| | 76 | |
|
| | 77 | | [Test] |
| | 78 | | public void StopInputCorrectly() |
| | 79 | | { |
| | 80 | | // Arrange |
| 1 | 81 | | bool stopInput = false; |
| 3 | 82 | | sceneCatalogController.OnStopInput += () => { stopInput = true; }; |
| | 83 | |
|
| | 84 | | // Act |
| 1 | 85 | | sceneCatalogController.StopInput(); |
| | 86 | |
|
| | 87 | | // Assert |
| 1 | 88 | | Assert.IsTrue(stopInput, "The stopInput is false!"); |
| 1 | 89 | | } |
| | 90 | |
|
| | 91 | | [Test] |
| | 92 | | public void HideCatalogClickedCorrectly() |
| | 93 | | { |
| | 94 | | // Arrange |
| 1 | 95 | | bool hideCatalogClicked = false; |
| 3 | 96 | | sceneCatalogController.OnHideCatalogClicked += () => { hideCatalogClicked = true; }; |
| | 97 | |
|
| | 98 | | // Act |
| 1 | 99 | | sceneCatalogController.HideCatalogClicked(); |
| | 100 | |
|
| | 101 | | // Assert |
| 1 | 102 | | Assert.IsTrue(hideCatalogClicked, "The hideCatalogClicked is false!"); |
| 1 | 103 | | } |
| | 104 | |
|
| | 105 | | [Test] |
| | 106 | | public void GetAssetsListByCategoryCorrectly() |
| | 107 | | { |
| | 108 | | // Arrange |
| 1 | 109 | | string testCategoryA = "test category A"; |
| 1 | 110 | | string testCategoryB = "test category B"; |
| 1 | 111 | | 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 |
| 1 | 122 | | List<CatalogItem> result = sceneCatalogController.GetAssetsListByCategory(testCategoryA, testDceneAssetPack) |
| | 123 | |
|
| | 124 | | // Assert |
| 3 | 125 | | Assert.AreEqual(2, result.Count(x => x.categoryName == testCategoryA), "The number of returned catalog items |
| 3 | 126 | | Assert.AreEqual(0, result.Count(x => x.categoryName == testCategoryB), "The number of returned catalog items |
| 1 | 127 | | } |
| | 128 | |
|
| | 129 | | [Test] |
| | 130 | | [TestCase(true)] |
| | 131 | | [TestCase(false)] |
| | 132 | | public void SceneCatalogBackCorrectly(bool isShowingAssetPacks) |
| | 133 | | { |
| | 134 | | // Arrange |
| 2 | 135 | | sceneCatalogController.isShowingAssetPacks = isShowingAssetPacks; |
| | 136 | |
|
| | 137 | | // Act |
| 2 | 138 | | sceneCatalogController.SceneCatalogBack(); |
| | 139 | |
|
| | 140 | | // Assert |
| 2 | 141 | | sceneCatalogController.sceneCatalogView.Received(isShowingAssetPacks ? 1 : 0).CloseCatalog(); |
| 2 | 142 | | } |
| | 143 | |
|
| | 144 | | [Test] |
| | 145 | | public void CheckIfCatalogIsOpenCorrectly() |
| | 146 | | { |
| | 147 | | // Act |
| 1 | 148 | | sceneCatalogController.IsCatalogOpen(); |
| | 149 | |
|
| | 150 | | // Assert |
| 1 | 151 | | sceneCatalogController.sceneCatalogView.Received(1).IsCatalogOpen(); |
| 1 | 152 | | } |
| | 153 | |
|
| | 154 | | [Test] |
| | 155 | | public void CheckIfCatalogIsExpandedCorrectly() |
| | 156 | | { |
| | 157 | | // Act |
| 1 | 158 | | sceneCatalogController.IsCatalogExpanded(); |
| | 159 | |
|
| | 160 | | // Assert |
| 1 | 161 | | sceneCatalogController.sceneCatalogView.Received(1).IsCatalogExpanded(); |
| 1 | 162 | | } |
| | 163 | |
|
| | 164 | | [Test] |
| | 165 | | public void ShowCategoriesCorrectly() |
| | 166 | | { |
| | 167 | | // Arrange |
| 1 | 168 | | sceneCatalogController.isShowingAssetPacks = false; |
| | 169 | |
|
| | 170 | | // Act |
| 1 | 171 | | sceneCatalogController.ShowCategories(); |
| | 172 | |
|
| | 173 | | // Assert |
| 1 | 174 | | Assert.IsTrue(sceneCatalogController.isShowingAssetPacks, "The isShowingAssetPacks is false!"); |
| 1 | 175 | | sceneCatalogController.sceneCatalogView.Received(1).SetCatalogTitle(Arg.Any<string>()); |
| 1 | 176 | | sceneCatalogController.sceneCatalogView.Received(1).ShowBackButton(false); |
| 1 | 177 | | } |
| | 178 | |
|
| | 179 | | [Test] |
| | 180 | | public void ShowAssetsPacksCorrectly() |
| | 181 | | { |
| | 182 | | // Arrange |
| 1 | 183 | | sceneCatalogController.isShowingAssetPacks = false; |
| | 184 | |
|
| | 185 | | // Act |
| 1 | 186 | | sceneCatalogController.ShowAssetsPacks(); |
| | 187 | |
|
| | 188 | | // Assert |
| 1 | 189 | | Assert.IsTrue(sceneCatalogController.isShowingAssetPacks, "The isShowingAssetPacks is false!"); |
| 1 | 190 | | sceneCatalogController.sceneCatalogView.Received(1).SetCatalogTitle(Arg.Any<string>()); |
| 1 | 191 | | sceneCatalogController.sceneCatalogView.Received(1).ShowBackButton(false); |
| 1 | 192 | | } |
| | 193 | |
|
| | 194 | | [Test] |
| | 195 | | public void OpenCatalogCorrectly() |
| | 196 | | { |
| | 197 | | // Arrange |
| 1 | 198 | | Utils.LockCursor(); |
| | 199 | |
|
| | 200 | | // Act |
| 1 | 201 | | sceneCatalogController.OpenCatalog(); |
| | 202 | |
|
| | 203 | | // Assert |
| 1 | 204 | | Assert.IsFalse(Utils.isCursorLocked, "The cursor is locked!"); |
| 1 | 205 | | sceneCatalogController.sceneCatalogView.Received(1).SetActive(true); |
| 1 | 206 | | } |
| | 207 | |
|
| | 208 | | [Test] |
| | 209 | | public void CloseCatalogCorrectly() |
| | 210 | | { |
| | 211 | | // Act |
| 1 | 212 | | sceneCatalogController.CloseCatalog(); |
| | 213 | |
|
| | 214 | | // Assert |
| 1 | 215 | | sceneCatalogController.sceneCatalogView.Received(1).CloseCatalog(); |
| 1 | 216 | | } |
| | 217 | |
|
| | 218 | | [Test] |
| | 219 | | [TestCase(true)] |
| | 220 | | [TestCase(false)] |
| | 221 | | public void SetActiveCorrectly(bool isActive) |
| | 222 | | { |
| | 223 | | // Act |
| 2 | 224 | | sceneCatalogController.SetActive(isActive); |
| | 225 | |
|
| | 226 | | // Assert |
| 2 | 227 | | sceneCatalogController.sceneCatalogView.Received(1).SetActive(isActive); |
| 2 | 228 | | } |
| | 229 | | } |
| | 230 | | } |