| | 1 | | using NSubstitute; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.Events; |
| | 6 | |
|
| | 7 | | namespace Tests.BuildModeHUDControllers |
| | 8 | | { |
| | 9 | | public class InspectorControllerShould |
| | 10 | | { |
| | 11 | | private InspectorController inspectorController; |
| | 12 | |
|
| | 13 | | [SetUp] |
| | 14 | | public void SetUp() |
| | 15 | | { |
| 10 | 16 | | inspectorController = new InspectorController(); |
| 10 | 17 | | inspectorController.Initialize(Substitute.For<IInspectorView>()); |
| 10 | 18 | | } |
| | 19 | |
|
| | 20 | | [TearDown] |
| 20 | 21 | | public void TearDown() { inspectorController.Dispose(); } |
| | 22 | |
|
| | 23 | | [Test] |
| | 24 | | public void OpenEntityListCorrectly() |
| | 25 | | { |
| | 26 | | // Act |
| 1 | 27 | | inspectorController.OpenEntityList(); |
| | 28 | |
|
| | 29 | | // Assert |
| 1 | 30 | | inspectorController.inspectorView.Received(1).SetActive(true); |
| 1 | 31 | | } |
| | 32 | |
|
| | 33 | | [Test] |
| | 34 | | public void SetEntityListCorrectly() |
| | 35 | | { |
| | 36 | | // Arrange |
| 1 | 37 | | inspectorController.inspectorView.entityList = new GameObject("_EntityListView").AddComponent<EntityListView |
| 1 | 38 | | List<DCLBuilderInWorldEntity> testEntities = new List<DCLBuilderInWorldEntity>(); |
| | 39 | |
|
| | 40 | | // Act |
| 1 | 41 | | inspectorController.SetEntityList(testEntities); |
| | 42 | |
|
| | 43 | | // Assert |
| 1 | 44 | | inspectorController.inspectorView.Received(1).SetEntitiesList(testEntities); |
| 1 | 45 | | } |
| | 46 | |
|
| | 47 | | [Test] |
| | 48 | | public void ClearListCorrectly() |
| | 49 | | { |
| | 50 | | // Act |
| 1 | 51 | | inspectorController.ClearList(); |
| | 52 | |
|
| | 53 | | // Assert |
| 1 | 54 | | inspectorController.inspectorView.Received(1).ClearEntitiesList(); |
| 1 | 55 | | } |
| | 56 | |
|
| | 57 | | [Test] |
| | 58 | | public void CloseListCorrectly() |
| | 59 | | { |
| | 60 | | // Act |
| 1 | 61 | | inspectorController.CloseList(); |
| | 62 | |
|
| | 63 | | // Assert |
| 1 | 64 | | inspectorController.inspectorView.Received().SetActive(false); |
| 1 | 65 | | } |
| | 66 | |
|
| | 67 | | [Test] |
| | 68 | | [TestCase(EntityAction.SELECT)] |
| | 69 | | [TestCase(EntityAction.LOCK)] |
| | 70 | | [TestCase(EntityAction.DELETE)] |
| | 71 | | [TestCase(EntityAction.SHOW)] |
| | 72 | | public void InvokeEntityActionCorrectly(EntityAction actionToInvoke) |
| | 73 | | { |
| | 74 | | // Arrange |
| 4 | 75 | | EntityAction testAction = actionToInvoke; |
| 4 | 76 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 4 | 77 | | DCLBuilderInWorldEntity returnedEntity = null; |
| | 78 | |
|
| | 79 | | switch (actionToInvoke) |
| | 80 | | { |
| | 81 | | case EntityAction.SELECT: |
| | 82 | |
|
| 3 | 83 | | inspectorController.OnEntityClick += (entity) => { returnedEntity = entity; }; |
| 1 | 84 | | break; |
| | 85 | | case EntityAction.LOCK: |
| | 86 | |
|
| 3 | 87 | | inspectorController.OnEntityLock += (entity) => { returnedEntity = entity; }; |
| 1 | 88 | | break; |
| | 89 | | case EntityAction.DELETE: |
| | 90 | |
|
| 3 | 91 | | inspectorController.OnEntityDelete += (entity) => { returnedEntity = entity; }; |
| 1 | 92 | | break; |
| | 93 | | case EntityAction.SHOW: |
| 3 | 94 | | inspectorController.OnEntityChangeVisibility += (entity) => { returnedEntity = entity; }; |
| | 95 | | break; |
| | 96 | | } |
| | 97 | |
|
| | 98 | | // Act |
| 4 | 99 | | inspectorController.EntityActionInvoked(testAction, testEntity, null); |
| | 100 | |
|
| | 101 | | // Assert |
| 4 | 102 | | Assert.AreEqual(testEntity, returnedEntity, "The entity does not match!"); |
| 4 | 103 | | } |
| | 104 | |
|
| | 105 | | [Test] |
| | 106 | | public void EntityRenameCorrectly() |
| | 107 | | { |
| | 108 | | // Arrange |
| 1 | 109 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 1 | 110 | | string testText = "Test text"; |
| 1 | 111 | | DCLBuilderInWorldEntity returnedEntity = null; |
| 1 | 112 | | string returnedText = ""; |
| | 113 | |
|
| 1 | 114 | | inspectorController.OnEntityRename += (entity, name) => |
| | 115 | | { |
| 1 | 116 | | returnedEntity = entity; |
| 1 | 117 | | returnedText = name; |
| 1 | 118 | | }; |
| | 119 | |
|
| | 120 | | // Act |
| 1 | 121 | | inspectorController.EntityRename(testEntity, testText); |
| | 122 | |
|
| | 123 | | // Assert |
| 1 | 124 | | Assert.AreEqual(testEntity, returnedEntity, "The entity does not match!"); |
| 1 | 125 | | Assert.AreEqual(testText, returnedText, "The text does not match!"); |
| 1 | 126 | | } |
| | 127 | |
|
| | 128 | | [Test] |
| | 129 | | public void SetCloseButtonsActionCorrectly() |
| | 130 | | { |
| | 131 | | // Arrange |
| 1 | 132 | | UnityAction testAction = () => { }; |
| | 133 | |
|
| | 134 | | // Act |
| 1 | 135 | | inspectorController.SetCloseButtonsAction(testAction); |
| | 136 | |
|
| | 137 | | // Assert |
| 1 | 138 | | inspectorController.inspectorView.Received(1).SetCloseButtonsAction(testAction); |
| 1 | 139 | | } |
| | 140 | | } |
| | 141 | | } |