< Summary

Class:AssetPromiseKeeper_Mock_Tests.AnyAssetPromiseShould
Assembly:AssetPromiseKeeper_Basic_Tests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Common/Mock/Tests/AnyAssetPromiseShould.cs
Covered lines:67
Uncovered lines:4
Coverable lines:71
Total lines:135
Line coverage:94.3% (67 of 71)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CallSuccessCallbackOnlyWhenNeeded()0%330100%
CallFailedCallbackOnlyWhenNeeded()0%330100%
DontCallFailedCallbackAfterIsAlreadyUnloaded()0%220100%

File(s)

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

#LineLine coverage
 1using DCL;
 2using System.Collections;
 3using UnityEngine.Assertions;
 4using UnityEngine.TestTools;
 5
 6namespace AssetPromiseKeeper_Mock_Tests
 7{
 8    public class AnyAssetPromiseShould
 9    {
 10        [UnityTest]
 11        public IEnumerator CallSuccessCallbackOnlyWhenNeeded()
 12        {
 113            var library = new AssetLibrary_Mock();
 114            var keeper = new AssetPromiseKeeper_Mock(library);
 15
 116            AssetPromise_Mock prom = new AssetPromise_Mock();
 17
 118            bool successCalled = false;
 19
 120            prom.idGenerator = "1";
 21
 122            System.Action<Asset_Mock> testEvent = (x) =>
 23            {
 124                successCalled = true;
 125            };
 26
 127            prom.OnSuccessEvent += testEvent;
 28
 129            prom.SetLibrary_Test(library);
 130            prom.Load_Test();
 31
 132            yield return prom;
 33
 134            Assert.IsTrue(successCalled == true, "Success callback wasn't called!");
 35
 136            successCalled = false;
 137            prom.Load_Test();
 138            Assert.IsTrue(successCalled == false, "Success callback was called when it shouldn't and the event didn't cl
 39
 140            successCalled = false;
 141            prom.OnSuccessEvent += testEvent;
 142            prom.Load_Test();
 43
 144            Assert.IsTrue(successCalled == false, "Success callback was called when it shouldn't!");
 145        }
 46
 47        [UnityTest]
 48        public IEnumerator CallFailedCallbackOnlyWhenNeeded()
 49        {
 150            var library = new AssetLibrary_Mock();
 151            var keeper = new AssetPromiseKeeper_Mock(library);
 52
 153            AssetPromise_Mock prom = new AssetPromise_Mock();
 54
 155            bool failCalled = false;
 56
 157            System.Action<Asset_Mock> testEvent = (x) =>
 58            {
 059                failCalled = true;
 060            };
 61
 162            prom.idGenerator = "1";
 163            prom.OnFailEvent += testEvent;
 64
 165            prom.SetLibrary_Test(library);
 166            prom.Load_Test();
 67
 168            yield return prom;
 69
 170            Assert.IsTrue(prom.state == AssetPromiseState.FINISHED);
 71
 72            //NOTE(Brian): Test that nothing should happen if called multiple times
 173            prom.Unload_Test();
 74
 175            Assert.IsTrue(!failCalled, "Fail callback was called when it shouldn't!");
 176            Assert.IsTrue(prom.state == AssetPromiseState.IDLE_AND_EMPTY, "Status should be NOT_GIVEN");
 77
 178            failCalled = false;
 179            prom.OnFailEvent += testEvent;
 80
 181            prom.Unload_Test();
 182            Assert.IsTrue(!failCalled, "Fail callback was called when it shouldn't!");
 183            Assert.IsTrue(prom.state == AssetPromiseState.IDLE_AND_EMPTY, "Status should be NOT_GIVEN");
 84
 185            Assert.IsTrue(prom.GetAsset_Test() == null, "Asset should be null when promise is cancelled!");
 186        }
 87
 88        [UnityTest]
 89        public IEnumerator DontCallFailedCallbackAfterIsAlreadyUnloaded()
 90        {
 191            var library = new AssetLibrary_Mock();
 192            var keeper = new AssetPromiseKeeper_Mock(library);
 93
 194            AssetPromise_Mock prom = new AssetPromise_Mock();
 195            bool failCalled = false;
 96
 197            System.Action<Asset_Mock> testEvent = (x) =>
 98            {
 099                failCalled = true;
 0100            };
 101
 1102            prom.idGenerator = "1";
 1103            prom.OnFailEvent += testEvent;
 104
 1105            prom.SetLibrary_Test(library);
 1106            prom.Load_Test();
 107
 1108            Assert.IsTrue(prom.state == AssetPromiseState.LOADING);
 1109            Assert.IsTrue(prom.GetAsset_Test() != null, "Asset shouldn't be null when loading!");
 110
 111            //NOTE(Brian): Test that nothing should happen if called multiple times
 1112            prom.Unload_Test();
 113
 1114            Assert.IsTrue(!failCalled, "Fail callback was called when it shouldnt'!");
 115
 1116            failCalled = false;
 1117            prom.Unload_Test();
 1118            Assert.IsTrue(!failCalled, "Fail callback was called when it shouldn't and fail event didn't clear!");
 119
 1120            failCalled = false;
 1121            prom.OnFailEvent += testEvent;
 122
 1123            prom.Unload_Test();
 1124            Assert.IsTrue(!failCalled, "Fail callback was called twice when it shouldn't!");
 125
 126            //NOTE(Brian): Test that nothing should happen if called multiple times
 1127            prom.Unload_Test();
 1128            prom.Unload_Test();
 1129            prom.Unload_Test();
 130
 1131            Assert.IsTrue(prom.GetAsset_Test() == null, "Asset should be null when promise is cancelled!");
 1132            yield break;
 133        }
 134    }
 135}