< Summary

Class:DCL.WebRequestAsyncOperation
Assembly:WebRequestControllerInterfaces
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/WebRequest/Interfaces/WebRequestAsyncOperation.cs
Covered lines:23
Uncovered lines:6
Coverable lines:29
Total lines:93
Line coverage:79.3% (23 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WebRequestAsyncOperation(...)0%110100%
SetAsCompleted(...)0%330100%
Abort()0%330100%
Dispose()0%220100%
SetNewWebRequest(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/WebRequest/Interfaces/WebRequestAsyncOperation.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.Networking;
 4
 5namespace DCL
 6{
 7    /// <summary>
 8    /// Our custom request async operation to be used with the WebRequestController.
 9    /// </summary>
 10    public class WebRequestAsyncOperation : CustomYieldInstruction
 11    {
 12        /// <summary>
 13        /// Event that will be invoked when the request has been completed.
 14        /// </summary>
 15        public event Action<WebRequestAsyncOperation> completed;
 16
 17        /// <summary>
 18        /// WebRequest that is being managed.
 19        /// </summary>
 020        public UnityWebRequest webRequest { get; private set; }
 21
 22        /// <summary>
 23        /// Returns true after the request has finished communicating with the remote server.
 24        /// </summary>
 025        public bool isDone { get; private set; }
 26
 27        /// <summary>
 28        /// Returns true if the request was successfully finished.
 29        /// </summary>
 030        public bool isSucceded { get; private set; }
 31
 32        /// <summary>
 33        /// Returns true if webRequest has been disposed (webRequest = null).
 34        /// </summary>
 035        public bool isDisposed { get { return webRequest == null; } }
 36
 37        /// <summary>
 38        /// Set to true for disposing the request just after it has been completed.
 39        /// </summary>
 040        public bool disposeOnCompleted { get; set; }
 41
 75942        public override bool keepWaiting { get { return !isDone; } }
 43
 37844        public WebRequestAsyncOperation(UnityWebRequest webRequest)
 45        {
 37846            this.webRequest = webRequest;
 37847            isDone = false;
 37848            isSucceded = false;
 37849            disposeOnCompleted = true;
 37850        }
 51
 52        /// <summary>
 53        /// Mark the request as completed and throw the corresponding event.
 54        /// </summary>
 55        /// <param name="success">True if the request was successfully ended.</param>
 56        internal void SetAsCompleted(bool success)
 57        {
 29758            completed?.Invoke(this);
 29759            isDone = true;
 29760            isSucceded = success;
 61
 29762            if (disposeOnCompleted)
 10163                Dispose();
 29764        }
 65
 66        /// <summary>
 67        /// If in progress, halts the request as soon as possible.
 68        /// </summary>
 69        public void Abort()
 70        {
 47771            if (webRequest == null || isDone)
 37272                return;
 73
 10574            webRequest.Abort();
 10575        }
 76
 77        /// <summary>
 78        /// Signals that this request is no longer being used, and should clean up any resources it is using (it aborts 
 79        /// </summary>
 80        public void Dispose()
 81        {
 47782            Abort();
 83
 47784            if (webRequest == null)
 10385                return;
 86
 37487            webRequest.Dispose();
 37488            webRequest = null;
 37489        }
 90
 091        internal void SetNewWebRequest(UnityWebRequest newRequest) { webRequest = newRequest; }
 92    }
 93}