< Summary

Class:DCL.WrappedTextureUtils
Assembly:WrappedTextureAsset
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Textures/WrappedTextureAsset/WrappedTextureAsset.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:58
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetHeader()0%42600%
Fetch()0%20400%
Fetch()0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Textures/WrappedTextureAsset/WrappedTextureAsset.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL.Helpers;
 4using UnityEngine.Networking;
 5
 6namespace DCL
 7{
 8    public static class WrappedTextureUtils
 9    {
 10        public static IEnumerator GetHeader(string url, string headerField, Action<string> OnSuccess, Action<string> OnF
 11        {
 012            using (var headReq = UnityWebRequest.Head(url))
 13            {
 014                yield return headReq.SendWebRequest();
 15
 016                if (headReq.WebRequestSucceded())
 17                {
 018                    OnSuccess?.Invoke(headReq.GetResponseHeader(headerField));
 019                }
 20                else
 21                {
 022                    OnFail?.Invoke(headReq.error);
 23                }
 024            }
 025        }
 26
 27        public static IEnumerator Fetch(string url, Action<IPromiseLike_TextureAsset> OnSuccess, Action OnFail = null)
 28        {
 029            string contentType = null;
 030            yield return GetHeader(url, "Content-Type", type => contentType = type, null);
 031            yield return Fetch(contentType, url, OnSuccess, OnFail);
 032        }
 33
 34        public static IEnumerator Fetch(string contentType, string url, Action<IPromiseLike_TextureAsset> OnSuccess, Act
 35        {
 036            if (contentType == "image/gif")
 37            {
 038                AssetPromise_Gif gifPromise = new AssetPromise_Gif(url);
 039                gifPromise.OnSuccessEvent += texture => { OnSuccess?.Invoke(new PromiseLike_Gif(gifPromise)); };
 040                gifPromise.OnFailEvent += (x) => OnFail?.Invoke();
 41
 042                AssetPromiseKeeper_Gif.i.Keep(gifPromise);
 43
 044                yield return gifPromise;
 045            }
 46            else
 47            {
 048                AssetPromise_Texture texturePromise = new AssetPromise_Texture(url, storeTexAsNonReadable: false);
 049                texturePromise.OnSuccessEvent += texture => { OnSuccess?.Invoke(new PromiseLike_Texture(texturePromise))
 050                texturePromise.OnFailEvent += (x) => OnFail?.Invoke();
 51
 052                AssetPromiseKeeper_Texture.i.Keep(texturePromise);
 53
 054                yield return texturePromise;
 55            }
 056        }
 57    }
 58}

Methods/Properties

GetHeader()
Fetch()
Fetch()