| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using NSubstitute; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | public class BIWSearchBarShould : MonoBehaviour |
| | 8 | | { |
| | 9 | | private SceneCatalogController sceneCatalogController; |
| | 10 | | private BIWSearchBarController biwSearchBarController; |
| | 11 | | private GameObject gameObjectToUse; |
| | 12 | |
|
| | 13 | | [SetUp] |
| | 14 | | public void SetUp() |
| | 15 | | { |
| 9 | 16 | | BIWCatalogManager.Init(); |
| 9 | 17 | | sceneCatalogController = new SceneCatalogController(); |
| 9 | 18 | | sceneCatalogController.Initialize( |
| | 19 | | Substitute.For<ISceneCatalogView>(), |
| | 20 | | Substitute.For<IQuickBarController>()); |
| 9 | 21 | | biwSearchBarController = sceneCatalogController.biwSearchBarController; |
| 9 | 22 | | gameObjectToUse = new GameObject("_TestObject"); |
| 9 | 23 | | gameObjectToUse.AddComponent<AssetCatalogBridge>(); |
| 9 | 24 | | } |
| | 25 | |
|
| | 26 | | [TearDown] |
| | 27 | | public void TearDown() |
| | 28 | | { |
| 9 | 29 | | AssetCatalogBridge.i.ClearCatalog(); |
| 9 | 30 | | BIWCatalogManager.ClearCatalog(); |
| 9 | 31 | | BIWCatalogManager.Dispose(); |
| 9 | 32 | | sceneCatalogController.Dispose(); |
| 9 | 33 | | if (gameObjectToUse != null) |
| 9 | 34 | | GameObject.Destroy(gameObjectToUse); |
| 9 | 35 | | } |
| | 36 | |
|
| | 37 | | [Test] |
| | 38 | | public void AddNewSceneObjectCategoryToFilterCorrectly() |
| | 39 | | { |
| | 40 | | // Arrange |
| 1 | 41 | | string testCategory = "testCategory"; |
| | 42 | |
|
| 1 | 43 | | CatalogItem testCatalogItem = new CatalogItem { category = testCategory }; |
| 1 | 44 | | biwSearchBarController.filterObjects.Clear(); |
| | 45 | |
|
| | 46 | | // Act |
| 1 | 47 | | biwSearchBarController.AddNewSceneObjectCategoryToFilter(testCatalogItem); |
| | 48 | |
|
| | 49 | | // Assert |
| 1 | 50 | | Assert.AreEqual(1, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 51 | | Assert.IsTrue(biwSearchBarController.filterObjects[0].ContainsKey(testCategory), "The test category has not been |
| 1 | 52 | | } |
| | 53 | |
|
| | 54 | | [Test] |
| | 55 | | public void FilterByName() |
| | 56 | | { |
| | 57 | | // Arrange |
| 1 | 58 | | string nameToFilter = "dirt"; |
| 1 | 59 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 60 | |
|
| | 61 | | // Act |
| 1 | 62 | | biwSearchBarController.FilterAssets(nameToFilter); |
| | 63 | |
|
| | 64 | | // Assert |
| 1 | 65 | | Assert.AreEqual(1, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 66 | | } |
| | 67 | |
|
| | 68 | | [Test] |
| | 69 | | public void FilterByNameNoResult() |
| | 70 | | { |
| | 71 | | // Arrange |
| 1 | 72 | | string nameToFilter = "sand"; |
| 1 | 73 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 74 | |
|
| | 75 | | // Act |
| 1 | 76 | | biwSearchBarController.FilterAssets(nameToFilter); |
| | 77 | |
|
| | 78 | | // Assert |
| 1 | 79 | | Assert.AreEqual(0, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 80 | | } |
| | 81 | |
|
| | 82 | | [Test] |
| | 83 | | public void FilterByCategory() |
| | 84 | | { |
| | 85 | | // Arrange |
| 1 | 86 | | string nameToFilter = "decorations"; |
| 1 | 87 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 88 | |
|
| | 89 | | // Act |
| 1 | 90 | | biwSearchBarController.FilterAssets(nameToFilter); |
| | 91 | |
|
| | 92 | | // Assert |
| 1 | 93 | | Assert.AreEqual(1, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 94 | | } |
| | 95 | |
|
| | 96 | | [Test] |
| | 97 | | public void FilterByCategoryNoResult() |
| | 98 | | { |
| | 99 | | // Arrange |
| 1 | 100 | | string nameToFilter = "structure"; |
| 1 | 101 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 102 | |
|
| | 103 | | // Act |
| 1 | 104 | | biwSearchBarController.FilterAssets(nameToFilter); |
| | 105 | |
|
| | 106 | | // Assert |
| 1 | 107 | | Assert.AreEqual(0, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 108 | | } |
| | 109 | |
|
| | 110 | | [Test] |
| | 111 | | public void FilterByTag() |
| | 112 | | { |
| | 113 | | // Arrange |
| 1 | 114 | | string nameToFilter = "fantasy"; |
| 1 | 115 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 116 | |
|
| | 117 | | // Act |
| 1 | 118 | | biwSearchBarController.FilterAssets(nameToFilter); |
| | 119 | |
|
| | 120 | | // Assert |
| 1 | 121 | | Assert.AreEqual(1, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 122 | | } |
| | 123 | |
|
| | 124 | | [Test] |
| | 125 | | public void FilterByTagNoResult() |
| | 126 | | { |
| | 127 | | // Arrange |
| 1 | 128 | | string nameToFilter = "wood"; |
| 1 | 129 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 130 | |
|
| | 131 | | // Act |
| 1 | 132 | | biwSearchBarController.FilterAssets(nameToFilter); |
| | 133 | |
|
| | 134 | | // Assert |
| 1 | 135 | | Assert.AreEqual(0, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 136 | | } |
| | 137 | |
|
| | 138 | | [Test] |
| | 139 | | public void FilterBySmartItem() |
| | 140 | | { |
| | 141 | | // Arrange |
| 1 | 142 | | BuilderInWorldTestHelper.CreateTestSmartItemCatalogLocalSingleObject(); |
| | 143 | |
|
| | 144 | | // Act |
| 1 | 145 | | biwSearchBarController.ChangeSmartItemFilter(); |
| | 146 | |
|
| | 147 | | //TODO: SmartItems implement again the test after kernel implement smart items |
| | 148 | | // Assert |
| | 149 | | //Assert.AreEqual(1, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!") |
| 1 | 150 | | } |
| | 151 | |
|
| | 152 | | [Test] |
| | 153 | | public void FilterBySmartItemNoResult() |
| | 154 | | { |
| | 155 | | // Arrange |
| 1 | 156 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 157 | |
|
| | 158 | | // Act |
| 1 | 159 | | biwSearchBarController.ChangeSmartItemFilter(); |
| | 160 | |
|
| | 161 | | // Assert |
| 1 | 162 | | Assert.AreEqual(0, biwSearchBarController.filterObjects.Count, "The number of filter objects does not match!"); |
| 1 | 163 | | } |
| | 164 | | } |