< Summary

Class:AssetPromiseKeeper_GLTF_Tests.BlockedAndMasterPromisesShould
Assembly:AssetPromiseKeeper_GLTF_Tests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTF/Tests/BlockedAndMasterPromisesShould.cs
Covered lines:68
Uncovered lines:0
Coverable lines:68
Total lines:115
Line coverage:100% (68 of 68)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SucceedWhenMastersParentIsDestroyed()0%550100%
FailCorrectlyWhenGivenWrongURL()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTF/Tests/BlockedAndMasterPromisesShould.cs

#LineLine coverage
 1using DCL;
 2using DCL.Helpers;
 3using System.Collections;
 4using System.Text.RegularExpressions;
 5using UnityEngine;
 6using UnityEngine.Assertions;
 7using UnityEngine.TestTools;
 8
 9namespace AssetPromiseKeeper_GLTF_Tests
 10{
 11    public class BlockedAndMasterPromisesShould : IntegrationTestSuite_Legacy
 12    {
 13        [UnityTest]
 14        public IEnumerator SucceedWhenMastersParentIsDestroyed()
 15        {
 116            var keeper = new AssetPromiseKeeper_GLTF();
 17
 118            string url = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 119            GameObject parent = new GameObject("parent");
 20
 121            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 122            prom.settings.parent = parent.transform;
 23
 124            AssetPromise_GLTF prom2 = new AssetPromise_GLTF(scene.contentProvider, url);
 125            bool failEventCalled2 = false;
 126            prom2.OnFailEvent += (x) => { failEventCalled2 = true; };
 27
 128            AssetPromise_GLTF prom3 = new AssetPromise_GLTF(scene.contentProvider, url);
 129            bool failEventCalled3 = false;
 130            prom3.OnFailEvent += (x) => { failEventCalled3 = true; };
 31
 132            keeper.Keep(prom);
 133            keeper.Keep(prom2);
 134            keeper.Keep(prom3);
 35
 136            keeper.Forget(prom);
 37
 138            Assert.AreEqual(3, keeper.waitingPromisesCount);
 39
 140            Object.Destroy(parent);
 41
 142            yield return prom;
 143            yield return prom2;
 144            yield return prom3;
 45
 146            Assert.AreEqual(AssetPromiseState.FINISHED, prom.state);
 147            Assert.AreEqual(AssetPromiseState.FINISHED, prom2.state);
 148            Assert.AreEqual(AssetPromiseState.FINISHED, prom3.state);
 49
 150            Assert.IsFalse(failEventCalled2);
 151            Assert.IsFalse(failEventCalled3);
 52
 153            Assert.IsTrue(prom.asset != null);
 154            Assert.IsTrue(prom2.asset != null);
 155            Assert.IsTrue(prom3.asset != null);
 56
 157            Assert.IsTrue(keeper.library.Contains(prom.asset));
 158            Assert.AreEqual(1, keeper.library.masterAssets.Count);
 159        }
 60
 61        [UnityTest]
 62        public IEnumerator FailCorrectlyWhenGivenWrongURL()
 63        {
 164            var keeper = new AssetPromiseKeeper_GLTF();
 65
 66            //NOTE(Brian): Expect the 404 error
 167            LogAssert.Expect(LogType.Error, new Regex("^*.?404"));
 68
 169            string url = TestAssetsUtils.GetPath() + "/non_existing_url.glb";
 70
 171            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 172            Asset_GLTF asset = null;
 173            bool failEventCalled1 = false;
 174            prom.OnSuccessEvent += (x) => { asset = x; };
 375            prom.OnFailEvent += (x) => { failEventCalled1 = true; };
 76
 177            AssetPromise_GLTF prom2 = new AssetPromise_GLTF(scene.contentProvider, url);
 178            Asset_GLTF asset2 = null;
 179            bool failEventCalled2 = false;
 180            prom2.OnSuccessEvent += (x) => { asset2 = x; };
 381            prom2.OnFailEvent += (x) => { failEventCalled2 = true; };
 82
 183            AssetPromise_GLTF prom3 = new AssetPromise_GLTF(scene.contentProvider, url);
 184            Asset_GLTF asset3 = null;
 185            bool failEventCalled3 = false;
 186            prom3.OnSuccessEvent += (x) => { asset3 = x; };
 387            prom3.OnFailEvent += (x) => { failEventCalled3 = true; };
 88
 189            keeper.Keep(prom);
 190            keeper.Keep(prom2);
 191            keeper.Keep(prom3);
 92
 193            Assert.AreEqual(3, keeper.waitingPromisesCount);
 94
 195            yield return prom;
 196            yield return prom2;
 197            yield return prom3;
 98
 199            Assert.AreNotEqual(AssetPromiseState.FINISHED, prom.state);
 1100            Assert.AreNotEqual(AssetPromiseState.FINISHED, prom2.state);
 1101            Assert.AreNotEqual(AssetPromiseState.FINISHED, prom3.state);
 102
 1103            Assert.IsTrue(failEventCalled1);
 1104            Assert.IsTrue(failEventCalled2);
 1105            Assert.IsTrue(failEventCalled3);
 106
 1107            Assert.IsFalse(asset != null);
 1108            Assert.IsFalse(asset2 != null);
 1109            Assert.IsFalse(asset3 != null);
 110
 1111            Assert.IsFalse(keeper.library.Contains(asset));
 1112            Assert.AreNotEqual(1, keeper.library.masterAssets.Count);
 1113        }
 114    }
 115}