< 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:18
Uncovered lines:7
Coverable lines:25
Total lines:65
Line coverage:72% (18 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetHeader()0%6.076087.5%
Fetch()0%440100%
Fetch()0%7.465053.85%

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 interface IWrappedTextureHelper
 9    {
 10        IEnumerator GetHeader(string url, string headerField, Action<string> OnSuccess, Action<string> OnFail);
 11        IEnumerator Fetch(string url, Action<IPromiseLike_TextureAsset> OnSuccess, Action OnFail = null);
 12        IEnumerator Fetch(string contentType, string url, Action<IPromiseLike_TextureAsset> OnSuccess, Action OnFail = n
 13    }
 14
 15    public class WrappedTextureUtils : IWrappedTextureHelper
 16    {
 17        public IEnumerator GetHeader(string url, string headerField, Action<string> OnSuccess, Action<string> OnFail)
 18        {
 719            using (var headReq = UnityWebRequest.Head(url))
 20            {
 721                yield return headReq.SendWebRequest();
 22
 723                if (headReq.WebRequestSucceded())
 24                {
 725                    OnSuccess?.Invoke(headReq.GetResponseHeader(headerField));
 726                }
 27                else
 28                {
 029                    OnFail?.Invoke(headReq.error);
 30                }
 731            }
 732        }
 33
 34        public IEnumerator Fetch(string url, Action<IPromiseLike_TextureAsset> OnSuccess, Action OnFail = null)
 35        {
 736            string contentType = null;
 1437            yield return GetHeader(url, "Content-Type", type => contentType = type, null);
 738            yield return Fetch(contentType, url, OnSuccess, OnFail);
 739        }
 40
 41        public IEnumerator Fetch(string contentType, string url, Action<IPromiseLike_TextureAsset> OnSuccess, Action OnF
 42        {
 743            if (contentType == "image/gif")
 44            {
 045                AssetPromise_Gif gifPromise = new AssetPromise_Gif(url);
 046                gifPromise.OnSuccessEvent += texture => { OnSuccess?.Invoke(new PromiseLike_Gif(gifPromise)); };
 047                gifPromise.OnFailEvent += (x) => OnFail?.Invoke();
 48
 049                AssetPromiseKeeper_Gif.i.Keep(gifPromise);
 50
 051                yield return gifPromise;
 052            }
 53            else
 54            {
 755                AssetPromise_Texture texturePromise = new AssetPromise_Texture(url);
 2156                texturePromise.OnSuccessEvent += texture => { OnSuccess?.Invoke(new PromiseLike_Texture(texturePromise))
 757                texturePromise.OnFailEvent += (x) => OnFail?.Invoke();
 58
 759                AssetPromiseKeeper_Texture.i.Keep(texturePromise);
 60
 761                yield return texturePromise;
 62            }
 763        }
 64    }
 65}

Methods/Properties

GetHeader()
Fetch()
Fetch()