< Summary

Class:AssetPromiseKeeper_AssetBundle_Tests.BlockedAndMasterPromisesShould
Assembly:AssetPromiseKeeper_AssetBundleTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/AB/Tests/BlockedAndMasterPromisesShould.cs
Covered lines:39
Uncovered lines:0
Coverable lines:39
Total lines:70
Line coverage:100% (39 of 39)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CreatePromise(...)0%220100%
FailCorrectlyWhenGivenWrongURL()0%550100%

File(s)

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

#LineLine coverage
 1using AssetPromiseKeeper_Tests;
 2using DCL;
 3using DCL.Helpers;
 4using System.Collections;
 5using UnityEngine.Assertions;
 6using UnityEngine.TestTools;
 7
 8namespace AssetPromiseKeeper_AssetBundle_Tests
 9{
 10    public class BlockedAndMasterPromisesShould :
 11        TestsBase_APK<AssetPromiseKeeper_AB, AssetPromise_AB, Asset_AB, AssetLibrary_AB>
 12    {
 13        protected AssetPromise_AB CreatePromise(string hash = null)
 14        {
 315            string contentUrl = TestAssetsUtils.GetPath() + "/AssetBundles/";
 316            hash = hash ?? "QmYACL8SnbXEonXQeRHdWYbfm8vxvaFAWnsLHUaDG4ABp5";
 317            var prom = new AssetPromise_AB(contentUrl, hash);
 318            return prom;
 19        }
 20
 21        [UnityTest]
 22        public IEnumerator FailCorrectlyWhenGivenWrongURL()
 23        {
 124            string url = "non_existing_url.glb";
 25
 126            AssetPromise_AB prom = CreatePromise(url);
 127            Asset_AB asset = null;
 128            bool failEventCalled1 = false;
 129            prom.OnSuccessEvent += (x) => { asset = x; };
 330            prom.OnFailEvent += (x) => { failEventCalled1 = true; };
 31
 132            AssetPromise_AB prom2 = CreatePromise(url);
 133            Asset_AB asset2 = null;
 134            bool failEventCalled2 = false;
 135            prom2.OnSuccessEvent += (x) => { asset2 = x; };
 336            prom2.OnFailEvent += (x) => { failEventCalled2 = true; };
 37
 138            AssetPromise_AB prom3 = CreatePromise(url);
 139            Asset_AB asset3 = null;
 140            bool failEventCalled3 = false;
 141            prom3.OnSuccessEvent += (x) => { asset3 = x; };
 342            prom3.OnFailEvent += (x) => { failEventCalled3 = true; };
 43
 144            keeper.Keep(prom);
 145            keeper.Keep(prom2);
 146            keeper.Keep(prom3);
 47
 148            Assert.AreEqual(3, keeper.waitingPromisesCount);
 49
 150            yield return prom;
 151            yield return prom2;
 152            yield return prom3;
 53
 154            Assert.AreNotEqual(AssetPromiseState.FINISHED, prom.state);
 155            Assert.AreNotEqual(AssetPromiseState.FINISHED, prom2.state);
 156            Assert.AreNotEqual(AssetPromiseState.FINISHED, prom3.state);
 57
 158            Assert.IsTrue(failEventCalled1);
 159            Assert.IsTrue(failEventCalled2);
 160            Assert.IsTrue(failEventCalled3);
 61
 162            Assert.IsFalse(asset != null);
 163            Assert.IsFalse(asset2 != null);
 164            Assert.IsFalse(asset3 != null);
 65
 166            Assert.IsFalse(keeper.library.Contains(asset));
 167            Assert.AreNotEqual(1, keeper.library.masterAssets.Count);
 168        }
 69    }
 70}