| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL.Components; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using DCL.Models; |
| | 7 | | using NUnit.Framework; |
| | 8 | | using UnityEngine; |
| | 9 | |
|
| | 10 | | public class BIWEntityShould : IntegrationTestSuite_Legacy |
| | 11 | | { |
| | 12 | | private const string ENTITY_ID = "1"; |
| | 13 | | DCLBuilderInWorldEntity entity; |
| | 14 | | BuilderInWorldEntityHandler entityHandler; |
| | 15 | |
|
| | 16 | | protected override IEnumerator SetUp() |
| | 17 | | { |
| 5 | 18 | | yield return base.SetUp(); |
| 5 | 19 | | BuilderInWorldController controller = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0]; |
| 5 | 20 | | entityHandler = controller.builderInWorldEntityHandler; |
| 5 | 21 | | entityHandler.Init(); |
| | 22 | |
|
| 5 | 23 | | TestHelpers.CreateSceneEntity(scene, ENTITY_ID); |
| 5 | 24 | | entityHandler.EnterEditMode(scene); |
| 5 | 25 | | entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault(); |
| 5 | 26 | | } |
| | 27 | |
|
| | 28 | | [Test] |
| | 29 | | public void LockValue() |
| | 30 | | { |
| | 31 | | //Arrange |
| 1 | 32 | | bool isLocked = true; |
| | 33 | |
|
| | 34 | | //Act |
| 1 | 35 | | entity.SetIsLockedValue(isLocked); |
| | 36 | |
|
| | 37 | | //Assert |
| 1 | 38 | | Assert.AreEqual(entity.IsLocked , isLocked); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | [Test] |
| | 42 | | public void DescriptiveName() |
| | 43 | | { |
| | 44 | | //Arrange |
| 1 | 45 | | string newName = "testingName"; |
| | 46 | |
|
| | 47 | | //Act |
| 1 | 48 | | entity.SetDescriptiveName(newName); |
| | 49 | |
|
| | 50 | | //Assert |
| 1 | 51 | | Assert.AreEqual(entity.GetDescriptiveName() , newName); |
| 1 | 52 | | } |
| | 53 | |
|
| | 54 | | [Test] |
| | 55 | | public void SetRotation() |
| | 56 | | { |
| | 57 | | //Arrange |
| 1 | 58 | | Vector3 startRotation = Vector3.right * 180; |
| | 59 | |
|
| | 60 | | //Act |
| 1 | 61 | | entity.SetRotation(startRotation); |
| | 62 | |
|
| | 63 | | //Assert |
| 1 | 64 | | Assert.AreEqual(startRotation, entity.GetEulerRotation()); |
| 1 | 65 | | } |
| | 66 | |
|
| | 67 | | [Test] |
| | 68 | | public void AddRotation() |
| | 69 | | { |
| | 70 | | //Arrange |
| 1 | 71 | | Vector3 startRotation = Vector3.right * 180; |
| 1 | 72 | | Vector3 addRotation = Vector3.right * 90; |
| 1 | 73 | | entity.SetRotation(startRotation); |
| | 74 | |
|
| | 75 | | //Act |
| 1 | 76 | | entity.AddRotation(addRotation); |
| | 77 | |
|
| | 78 | | //Assert |
| 1 | 79 | | Assert.AreEqual(startRotation + addRotation, entity.GetEulerRotation()); |
| 1 | 80 | | } |
| | 81 | |
|
| | 82 | | [Test] |
| | 83 | | public void SmartItemComponent() |
| | 84 | | { |
| 1 | 85 | | SmartItemComponent.Model model = new SmartItemComponent.Model(); |
| | 86 | |
|
| 1 | 87 | | string testFloatKey = "TestFloat"; |
| 1 | 88 | | float testFloat = 20f; |
| | 89 | |
|
| 1 | 90 | | string intKey = "Speed"; |
| 1 | 91 | | int testInt = 10; |
| | 92 | |
|
| 1 | 93 | | string stringKey = "TextExample"; |
| 1 | 94 | | string testString = "unit test example"; |
| | 95 | |
|
| 1 | 96 | | string onClickKey = "OnClick"; |
| | 97 | |
|
| | 98 | |
|
| 1 | 99 | | Dictionary<object, object> onClickDict = new Dictionary<object, object>(); |
| 1 | 100 | | onClickDict.Add(testFloatKey, testFloat); |
| | 101 | |
|
| 1 | 102 | | model.values = new Dictionary<object, object>(); |
| 1 | 103 | | model.values.Add(intKey, testInt); |
| 1 | 104 | | model.values.Add(testFloatKey, testFloat); |
| 1 | 105 | | model.values.Add(stringKey, testString); |
| 1 | 106 | | model.values.Add(onClickKey, onClickDict); |
| | 107 | |
|
| 1 | 108 | | SmartItemComponent smartItemComponent = null; |
| | 109 | |
|
| 1 | 110 | | scene.EntityComponentCreateOrUpdateWithModel(ENTITY_ID, CLASS_ID_COMPONENT.SMART_ITEM, model); |
| | 111 | |
|
| 1 | 112 | | if (scene.entities[ENTITY_ID].TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent baseCompon |
| | 113 | | { |
| | 114 | | //Note (Adrian): We can't wait to set the component 1 frame in production, so we set it like production |
| 1 | 115 | | smartItemComponent = ((SmartItemComponent) baseComponent); |
| 1 | 116 | | smartItemComponent.UpdateFromModel(model); |
| 1 | 117 | | } |
| | 118 | | else |
| | 119 | | { |
| 0 | 120 | | Assert.Fail("Smart Component not found"); |
| | 121 | | } |
| | 122 | |
|
| 1 | 123 | | Assert.AreEqual(testInt, smartItemComponent.GetValues()[intKey]); |
| 1 | 124 | | Assert.AreEqual(testFloat, smartItemComponent.GetValues()[testFloatKey]); |
| 1 | 125 | | Assert.AreEqual(testString, smartItemComponent.GetValues()[stringKey]); |
| | 126 | |
|
| 1 | 127 | | Dictionary<object, object> onClickDictFromComponent = (Dictionary<object, object>) smartItemComponent.GetValues( |
| 1 | 128 | | Assert.AreEqual(testFloat, onClickDictFromComponent[testFloatKey]); |
| 1 | 129 | | } |
| | 130 | | } |