< Summary

Class:DCL.AssetPromise_Mock
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Common/Mock/AssetPromise_Mock.cs
Covered lines:18
Uncovered lines:2
Coverable lines:20
Total lines:63
Line coverage:90% (18 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetId()0%220100%
OnLoad(...)0%110100%
OnCancelLoading()0%110100%
MockLoadingCoroutine()0%660100%
Load_Test()0%110100%
GetAsset_Test()0%2100%
Unload_Test()0%110100%
SetLibrary_Test(...)0%2100%
OnBeforeLoadOrReuse()0%110100%
OnAfterLoadOrReuse()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Common/Mock/AssetPromise_Mock.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using UnityEngine;
 4using UnityEngine.Assertions;
 5
 6namespace DCL
 7{
 8    public class AssetPromise_Mock : AssetPromise<Asset_Mock>
 9    {
 10        public bool forceFail = false;
 11        public float loadTime;
 12        public object idGenerator;
 13        private object id;
 14        Coroutine assetMockCoroutine;
 15
 16        public override object GetId()
 17        {
 23018            Assert.IsTrue(idGenerator != null, "idGenerator should not be null");
 19
 23020            if (id == null)
 6721                id = idGenerator.GetHashCode();
 22
 23023            return id;
 24        }
 25
 26        protected override void OnLoad(Action OnSuccess, Action OnFail)
 27        {
 1328            loadTime = 1;
 1329            assetMockCoroutine = CoroutineStarter.Start(MockLoadingCoroutine(OnSuccess, OnFail));
 1330        }
 31
 1232        protected override void OnCancelLoading() { CoroutineStarter.Stop(assetMockCoroutine); }
 33
 34        IEnumerator MockLoadingCoroutine(Action OnSuccess, Action OnFail)
 35        {
 1336            yield return WaitForSecondsCache.Get(loadTime);
 37
 838            if (forceFail)
 39            {
 140                OnFail?.Invoke();
 141            }
 42            else
 43            {
 744                OnSuccess?.Invoke();
 45            }
 846        }
 47
 48        //NOTE(Brian): Used for testing
 1049        public void Load_Test() { Load(); }
 50
 051        public Asset_Mock GetAsset_Test() { return asset; }
 52
 1653        public void Unload_Test() { Unload(); }
 54
 055        public void SetLibrary_Test(AssetLibrary<Asset_Mock> library) { this.library = library; }
 56
 6757        protected override void OnBeforeLoadOrReuse() { }
 58
 6159        protected override void OnAfterLoadOrReuse() { }
 60    }
 61
 62    public class AssetPromise_Mock_Alt_Loading_Approach : AssetPromise_Mock { }
 63}