< Summary

Class:BIWEntityShould
Assembly:BuilderInWorldTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Tests/BIWEntityShould.cs
Covered lines:53
Uncovered lines:1
Coverable lines:54
Total lines:130
Line coverage:98.1% (53 of 54)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
LockValue()0%110100%
DescriptiveName()0%110100%
SetRotation()0%110100%
AddRotation()0%110100%
SmartItemComponent()0%22096.43%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Tests/BIWEntityShould.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL.Components;
 5using DCL.Helpers;
 6using DCL.Models;
 7using NUnit.Framework;
 8using UnityEngine;
 9
 10public 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    {
 518        yield return base.SetUp();
 519        BuilderInWorldController controller = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0];
 520        entityHandler = controller.builderInWorldEntityHandler;
 521        entityHandler.Init();
 22
 523        TestHelpers.CreateSceneEntity(scene, ENTITY_ID);
 524        entityHandler.EnterEditMode(scene);
 525        entity = entityHandler.GetAllEntitiesFromCurrentScene().FirstOrDefault();
 526    }
 27
 28    [Test]
 29    public void LockValue()
 30    {
 31        //Arrange
 132        bool isLocked =  true;
 33
 34        //Act
 135        entity.SetIsLockedValue(isLocked);
 36
 37        //Assert
 138        Assert.AreEqual(entity.IsLocked , isLocked);
 139    }
 40
 41    [Test]
 42    public void DescriptiveName()
 43    {
 44        //Arrange
 145        string newName = "testingName";
 46
 47        //Act
 148        entity.SetDescriptiveName(newName);
 49
 50        //Assert
 151        Assert.AreEqual(entity.GetDescriptiveName() , newName);
 152    }
 53
 54    [Test]
 55    public void SetRotation()
 56    {
 57        //Arrange
 158        Vector3 startRotation = Vector3.right * 180;
 59
 60        //Act
 161        entity.SetRotation(startRotation);
 62
 63        //Assert
 164        Assert.AreEqual(startRotation, entity.GetEulerRotation());
 165    }
 66
 67    [Test]
 68    public void AddRotation()
 69    {
 70        //Arrange
 171        Vector3 startRotation = Vector3.right * 180;
 172        Vector3 addRotation = Vector3.right * 90;
 173        entity.SetRotation(startRotation);
 74
 75        //Act
 176        entity.AddRotation(addRotation);
 77
 78        //Assert
 179        Assert.AreEqual(startRotation + addRotation, entity.GetEulerRotation());
 180    }
 81
 82    [Test]
 83    public void SmartItemComponent()
 84    {
 185        SmartItemComponent.Model model = new SmartItemComponent.Model();
 86
 187        string testFloatKey = "TestFloat";
 188        float testFloat = 20f;
 89
 190        string intKey = "Speed";
 191        int testInt = 10;
 92
 193        string stringKey = "TextExample";
 194        string testString = "unit test example";
 95
 196        string onClickKey = "OnClick";
 97
 98
 199        Dictionary<object, object> onClickDict = new Dictionary<object, object>();
 1100        onClickDict.Add(testFloatKey, testFloat);
 101
 1102        model.values = new Dictionary<object, object>();
 1103        model.values.Add(intKey, testInt);
 1104        model.values.Add(testFloatKey, testFloat);
 1105        model.values.Add(stringKey, testString);
 1106        model.values.Add(onClickKey, onClickDict);
 107
 1108        SmartItemComponent smartItemComponent = null;
 109
 1110        scene.EntityComponentCreateOrUpdateWithModel(ENTITY_ID, CLASS_ID_COMPONENT.SMART_ITEM, model);
 111
 1112        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
 1115            smartItemComponent = ((SmartItemComponent) baseComponent);
 1116            smartItemComponent.UpdateFromModel(model);
 1117        }
 118        else
 119        {
 0120            Assert.Fail("Smart Component not found");
 121        }
 122
 1123        Assert.AreEqual(testInt, smartItemComponent.GetValues()[intKey]);
 1124        Assert.AreEqual(testFloat, smartItemComponent.GetValues()[testFloatKey]);
 1125        Assert.AreEqual(testString, smartItemComponent.GetValues()[stringKey]);
 126
 1127        Dictionary<object, object> onClickDictFromComponent = (Dictionary<object, object>) smartItemComponent.GetValues(
 1128        Assert.AreEqual(testFloat, onClickDictFromComponent[testFloatKey]);
 1129    }
 130}