< Summary

Class:AssetPromiseKeeper_AssetBundle_GameObject_Tests.APK_AB_GameObject_Promise_Should
Assembly:AssetPromiseKeeper_AssetBundle_GameObject_Tests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/AB_GameObject/Tests/APK_AB_GameObject_Promise_Should.cs
Covered lines:74
Uncovered lines:0
Coverable lines:74
Total lines:147
Line coverage:100% (74 of 74)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CreatePromise(...)0%220100%
BeSetupCorrectlyAfterLoad()0%440100%
ForceNewInstanceIsOff()0%330100%
ForceNewInstanceIsOffMultipleTimes()0%550100%
ForceNewInstanceIsOn()0%330100%
ForceNewInstanceIsOnMultipleTimes()0%550100%
FailCorrectlyWhenLoadingABWithoutGameObjects()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/AB_GameObject/Tests/APK_AB_GameObject_Promise_Should.cs

#LineLine coverage
 1using AssetPromiseKeeper_Tests;
 2using DCL;
 3using DCL.Helpers;
 4using System.Collections;
 5using System.Collections.Generic;
 6using UnityEngine;
 7using UnityEngine.Assertions;
 8using UnityEngine.TestTools;
 9
 10namespace AssetPromiseKeeper_AssetBundle_GameObject_Tests
 11{
 12    public class APK_AB_GameObject_Promise_Should : TestsBase_APK<AssetPromiseKeeper_AB_GameObject,
 13        AssetPromise_AB_GameObject,
 14        Asset_AB_GameObject,
 15        AssetLibrary_AB_GameObject>
 16    {
 17        protected AssetPromise_AB_GameObject CreatePromise(string hash = null)
 18        {
 2419            string contentUrl = TestAssetsUtils.GetPath() + "/AssetBundles/";
 2420            hash = hash ?? "QmNS4K7GaH63T9rhAfkrra7ADLXSEeco8FTGknkPnAVmKM";
 2421            var prom = new AssetPromise_AB_GameObject(contentUrl, hash);
 2422            return prom;
 23        }
 24
 25
 26        [UnityTest]
 27        public IEnumerator BeSetupCorrectlyAfterLoad()
 28        {
 129            var prom = CreatePromise();
 130            Asset_AB_GameObject loadedAsset = null;
 31
 132            prom.OnSuccessEvent +=
 33                (x) =>
 34                {
 135                    Debug.Log("Success is called");
 136                    loadedAsset = x;
 137                }
 38                ;
 39
 140            prom.OnFailEvent += (x) => { Debug.Log("Fail is called"); };
 41
 142            Vector3 initialPos = Vector3.one;
 143            Quaternion initialRot = Quaternion.LookRotation(Vector3.right, Vector3.up);
 144            Vector3 initialScale = Vector3.one * 2;
 45
 146            prom.settings.initialLocalPosition = initialPos;
 147            prom.settings.initialLocalRotation = initialRot;
 148            prom.settings.initialLocalScale = initialScale;
 49
 150            keeper.Keep(prom);
 51
 152            yield return prom;
 53
 154            Assert.IsTrue(PoolManager.i.ContainsPool(loadedAsset.id), "Not in pool after loaded!");
 55
 156            Pool pool = PoolManager.i.GetPool(loadedAsset.id);
 57
 158            Assert.AreEqual(0, pool.unusedObjectsCount, "incorrect inactive objects in pool");
 159            Assert.AreEqual(1, pool.usedObjectsCount, "incorrect active objects in pool");
 160            Assert.IsTrue(pool.original != loadedAsset.container, "In pool, the original gameObject must NOT be the load
 61
 62            //NOTE(Brian): If the following asserts fail, check that ApplySettings_LoadStart() is called from AssetPromi
 163            Assert.AreEqual(initialPos.ToString(), loadedAsset.container.transform.localPosition.ToString(), "initial po
 164            Assert.AreEqual(initialRot.ToString(), loadedAsset.container.transform.localRotation.ToString(), "initial ro
 165            Assert.AreEqual(initialScale.ToString(), loadedAsset.container.transform.localScale.ToString(), "initial sca
 66
 167            Assert.IsTrue(loadedAsset != null);
 168            Assert.IsTrue(keeper.library.Contains(loadedAsset));
 169            Assert.AreEqual(1, keeper.library.masterAssets.Count);
 170        }
 71
 72        [UnityTest]
 73        public IEnumerator ForceNewInstanceIsOff()
 74        {
 175            var prom = CreatePromise();
 176            prom.settings.forceNewInstance = false;
 177            keeper.Keep(prom);
 178            yield return prom;
 79
 180            var poolableObjectComponent = PoolManager.i.GetPoolable(prom.asset.container);
 181            Assert.IsNotNull(poolableObjectComponent);
 182        }
 83
 84        [UnityTest]
 85        public IEnumerator ForceNewInstanceIsOffMultipleTimes()
 86        {
 187            var poolableComponents = new List<PoolableObject>();
 88
 2289            for (int i = 0; i < 10; i++)
 90            {
 1091                var prom = CreatePromise();
 1092                prom.settings.forceNewInstance = false;
 1093                keeper.Keep(prom);
 1094                yield return prom;
 1095                poolableComponents.Add(PoolManager.i.GetPoolable(prom.asset.container));
 1096                keeper.Forget(prom);
 1097            }
 98
 1199            Assert.IsTrue(poolableComponents.TrueForAll(x => x != null));
 1100        }
 101
 102        [UnityTest]
 103        public IEnumerator ForceNewInstanceIsOn()
 104        {
 1105            var prom = CreatePromise();
 1106            prom.settings.forceNewInstance = true;
 1107            keeper.Keep(prom);
 1108            yield return prom;
 109
 1110            var poolableObjectComponent = PoolManager.i.GetPoolable(prom.asset.container);
 1111            Assert.IsNull(poolableObjectComponent);
 1112        }
 113
 114        [UnityTest]
 115        public IEnumerator ForceNewInstanceIsOnMultipleTimes()
 116        {
 1117            var poolableComponents = new List<PoolableObject>();
 118
 22119            for (int i = 0; i < 10; i++)
 120            {
 10121                var prom = CreatePromise();
 10122                prom.settings.forceNewInstance = true;
 10123                keeper.Keep(prom);
 10124                yield return prom;
 10125                poolableComponents.Add(PoolManager.i.GetPoolable(prom.asset.container));
 10126                keeper.Forget(prom);
 10127            }
 128
 11129            Assert.IsTrue(poolableComponents.TrueForAll(x => x == null));
 1130        }
 131
 132
 133        [UnityTest]
 134        public IEnumerator FailCorrectlyWhenLoadingABWithoutGameObjects()
 135        {
 1136            var prom = CreatePromise("Broken_paladin_AB");
 137
 1138            bool failed = false;
 3139            prom.OnFailEvent += (x) => { failed = true; };
 1140            keeper.Keep(prom);
 141
 1142            yield return prom;
 143
 1144            Assert.IsTrue(failed == true, "The broken paladin AssetBundle contains no GameObjects and should fail!");
 1145        }
 146    }
 147}