< Summary

Class:Microsoft.Azure.HDInsight.Job.Models.ModelHelper
Assembly:Microsoft.Azure.HDInsight.Job
File(s):C:\Git\azure-sdk-for-net\sdk\hdinsight\Microsoft.Azure.HDInsight.Job\src\Customizations\Helpers\ModelHelper.cs
Covered lines:28
Uncovered lines:2
Coverable lines:30
Total lines:92
Line coverage:93.3% (28 of 30)
Covered branches:9
Total branches:10
Branch coverage:90% (9 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
GetStatusDirectory(...)-100%100%
ConvertItemsToString(...)-100%100%
EscapeDataString(...)-88.89%75%
BuildNameValueList(...)-100%100%
BuildList(...)-100%100%
BuildListToCommaSeparatedString(...)-0%100%
Delay(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\hdinsight\Microsoft.Azure.HDInsight.Job\src\Customizations\Helpers\ModelHelper.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.HDInsight.Job.Models
 6{
 7    using System;
 8    using System.Collections.Generic;
 9    using System.Linq;
 10    using System.Threading.Tasks;
 11
 12    internal static class ModelHelper
 13    {
 214        internal static int MaxStringSizeForUrlEscapeData = 32766;
 15
 16        internal static string GetStatusDirectory(string status)
 17        {
 3818            var statusDir = status;
 3819            if (string.IsNullOrWhiteSpace(statusDir))
 20            {
 21                // Format of status directory: 2009-06-15T13-45-30-<guid>
 3222                statusDir = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
 23
 24                // Can't create a directory with char ":" in azure storage
 3225                statusDir = statusDir.Replace(':', '-');
 3226                statusDir = string.Format("{0}-{1}", statusDir, Guid.NewGuid().ToString());
 27            }
 28
 3829            return statusDir;
 30        }
 31
 32        internal static string ConvertItemsToString(IEnumerable<KeyValuePair<string, string>> args)
 33        {
 3834            var strings = (from kvp in args
 17035                           select kvp.Key.EscapeDataString() + "=" + kvp.Value.EscapeDataString()).ToList();
 3836            return string.Join("&", strings);
 37        }
 38
 39        internal static string EscapeDataString(this string inputValue)
 40        {
 26441            if (string.IsNullOrEmpty(inputValue))
 42            {
 043                return string.Empty;
 44            }
 45
 26446            var escapeString = string.Empty;
 26447            int i = 0;
 48
 26849            while (i < inputValue.Length / MaxStringSizeForUrlEscapeData)
 50            {
 451                escapeString += Uri.EscapeDataString(inputValue.Substring(MaxStringSizeForUrlEscapeData * i, MaxStringSi
 452                i++;
 53            }
 54
 26455            escapeString += Uri.EscapeDataString(inputValue.Substring(MaxStringSizeForUrlEscapeData * i));
 56
 26457            return escapeString;
 58        }
 59
 60        internal static IEnumerable<KeyValuePair<string, string>> BuildNameValueList(string paramName, IEnumerable<KeyVa
 61        {
 862            List<KeyValuePair<string, string>> retval = new List<KeyValuePair<string, string>>();
 63
 6864            foreach (var kvp in nameValuePairs)
 65            {
 2666                retval.Add(new KeyValuePair<string, string>(paramName, kvp.Key + "=" + kvp.Value));
 67            }
 868            return retval;
 69        }
 70
 71        internal static IEnumerable<KeyValuePair<string, string>> BuildList(string type, IEnumerable<string> args)
 72        {
 673            List<KeyValuePair<string, string>> retval = new List<KeyValuePair<string, string>>();
 74
 3675            foreach (var arg in args)
 76            {
 1277                retval.Add(new KeyValuePair<string, string>(type, arg));
 78            }
 679            return retval;
 80        }
 81
 82        internal static string BuildListToCommaSeparatedString(IEnumerable<string> input)
 83        {
 084            return string.Join(",", input.ToArray());
 85        }
 86
 87        internal static void Delay(TimeSpan duration)
 88        {
 38089            Task.Delay(duration).Wait();
 38090        }
 91    }
 92}