< 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:21
Uncovered lines:2
Coverable lines:23
Total lines:71
Line coverage:91.3% (21 of 23)
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%
Unload()0%220100%
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 event Action OnUnloaded;
 17
 18        public override object GetId()
 19        {
 26620            Assert.IsTrue(idGenerator != null, "idGenerator should not be null");
 21
 26622            if (id == null)
 7623                id = idGenerator.GetHashCode();
 24
 26625            return id;
 26        }
 27
 28        protected override void OnLoad(Action OnSuccess, Action<Exception> OnFail)
 29        {
 1630            loadTime = 1;
 1631            assetMockCoroutine = CoroutineStarter.Start(MockLoadingCoroutine(OnSuccess, OnFail));
 1632        }
 33
 1234        protected override void OnCancelLoading() { CoroutineStarter.Stop(assetMockCoroutine); }
 35
 36        IEnumerator MockLoadingCoroutine(Action OnSuccess, Action<Exception> OnFail)
 37        {
 1638            yield return WaitForSecondsCache.Get(loadTime);
 39
 1140            if (forceFail)
 41            {
 142                OnFail?.Invoke(new Exception("Promise was forced to fail"));
 143            }
 44            else
 45            {
 1046                OnSuccess?.Invoke();
 47            }
 1148        }
 49
 50        //NOTE(Brian): Used for testing
 1051        public void Load_Test() { Load(); }
 52
 053        public Asset_Mock GetAsset_Test() { return asset; }
 54
 1655        public void Unload_Test() { Unload(); }
 56
 57        internal override void Unload()
 58        {
 1659            base.Unload();
 1660            OnUnloaded?.Invoke();
 161        }
 62
 063        public void SetLibrary_Test(AssetLibrary<Asset_Mock> library) { this.library = library; }
 64
 7665        protected override void OnBeforeLoadOrReuse() { }
 66
 7067        protected override void OnAfterLoadOrReuse() { }
 68    }
 69
 70    public class AssetPromise_Mock_Alt_Loading_Approach : AssetPromise_Mock { }
 71}