< Summary

Class:BatchTestCommon.TestCommon
Assembly:Microsoft.Azure.Batch.Common
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\tests\TestCommon\TestCommon.cs
Covered lines:0
Uncovered lines:31
Coverable lines:31
Total lines:124
Line coverage:0% (0 of 31)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-0%100%
ParseHeaderEnvironmentVariable(...)-0%0%
GetEnvironmentVariableOrThrow(...)-0%0%
GetEnvironmentVariableOrDefault(...)-0%0%
.cctor()-0%100%
get_Configuration()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\tests\TestCommon\TestCommon.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 license information.
 3
 4namespace BatchTestCommon
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Linq;
 9
 10    public static class TestCommon
 11    {
 12        public class TestConfiguration
 13        {
 14            public const string BatchSubscriptionEnivronmentSettingName = "MABOM_BatchAccountSubscriptionId";
 15
 16            public const string BatchManagementUrlEnvironmentSettingName = "MABOM_BatchManagementEndpoint";
 17
 18            public const string BatchAccountKeyEnvironmentSettingName = "MABOM_BatchAccountKey";
 19
 20            public const string BatchAccountNameEnvironmentSettingName = "MABOM_BatchAccountName";
 21
 22            public const string BatchAccountUrlEnvironmentSettingName = "MABOM_BatchAccountEndpoint";
 23
 24            public const string StorageAccountKeyEnvironmentSettingName = "MABOM_StorageKey";
 25
 26            public const string StorageAccountNameEnvironmentSettingName = "MABOM_StorageAccount";
 27
 28            public const string StorageAccountBlobEndpointEnvironmentSettingName = "MABOM_BlobEndpoint";
 29
 30            public const string BatchAccountResourceGroupEnvironmentSettingName = "MABOM_BatchAccountResourceGroupName";
 31
 32            public const string StorageAccountResourceGroupEnvironmentSettingName = "MABOM_StorageAccountResourceGroupNa
 33
 34            // Required only for Microsoft pre-production test environments
 35
 36            // The client Id from the Azure Active Directory, this is used for connecting to the management api.
 37            public const string AzureAuthenticationClientIdEnvironmentSettingName = "MABOM_AzureAuthenticationClientId";
 38
 39            // The client key from the Azure Active Directory app.
 40            public const string AzureAuthenticationClientSecretEnvironmentSettingName = "MABOM_AzureAuthenticationClient
 41
 42            public const string BatchAuthorityUrlEnvironmentSettingName = "MABOM_BatchAuthorityUrl";
 43
 44            public const string BatchTRPCertificateThumbprintEnvironmentSettingName = "MABOM_BatchTRPCertificateThumbpri
 45
 46            //Should be a string like so: header1=value1;header2=value2;...
 47            // Required only for Microsoft pre-production test environments
 48            public const string BatchTRPExtraHeadersEnvironmentSettingName = "MABOM_BatchTRPExtraHeaders";
 49
 050            public readonly string BatchSubscription = GetEnvironmentVariableOrThrow(BatchSubscriptionEnivronmentSetting
 51
 052            public readonly string BatchManagementUrl = GetEnvironmentVariableOrThrow(BatchManagementUrlEnvironmentSetti
 53
 054            public readonly string BatchAccountKey = GetEnvironmentVariableOrThrow(BatchAccountKeyEnvironmentSettingName
 55
 056            public readonly string BatchAccountName = GetEnvironmentVariableOrThrow(BatchAccountNameEnvironmentSettingNa
 57
 058            public readonly string BatchAccountUrl = GetEnvironmentVariableOrThrow(BatchAccountUrlEnvironmentSettingName
 59
 060            public readonly string StorageAccountKey = GetEnvironmentVariableOrThrow(StorageAccountKeyEnvironmentSetting
 61
 062            public readonly string StorageAccountName = GetEnvironmentVariableOrThrow(StorageAccountNameEnvironmentSetti
 63
 064            public readonly string StorageAccountBlobEndpoint = GetEnvironmentVariableOrThrow(StorageAccountBlobEndpoint
 65
 066            public readonly string BatchAccountResourceGroup = GetEnvironmentVariableOrThrow(BatchAccountResourceGroupEn
 67
 068            public readonly string StorageAccountResourceGroup = GetEnvironmentVariableOrThrow(StorageAccountResourceGro
 69
 070            public readonly Func<string> BatchTRPCertificateThumbprint = () => GetEnvironmentVariableOrThrow(BatchTRPCer
 71
 072            public readonly string AzureAuthenticationClientId = GetEnvironmentVariableOrThrow(AzureAuthenticationClient
 73
 074            public readonly string AzureAuthenticationClientSecret = GetEnvironmentVariableOrThrow(AzureAuthenticationCl
 75
 076            public readonly IReadOnlyDictionary<string, string> BatchTRPExtraHeaders = ParseHeaderEnvironmentVariable(Ba
 77
 078            public readonly string BatchAuthorityUrl = GetEnvironmentVariableOrDefault(BatchAuthorityUrlEnvironmentSetti
 79
 80            private static IReadOnlyDictionary<string, string> ParseHeaderEnvironmentVariable(string environmentSettingN
 81            {
 082                string settingString = Environment.GetEnvironmentVariable(environmentSettingName);
 083                IReadOnlyDictionary<string, string> result = new Dictionary<string, string>();
 84
 085                if (!string.IsNullOrEmpty(settingString))
 86                {
 087                    IEnumerable<string> pairs = settingString.Split(';');
 088                    result = pairs.ToDictionary(pair => pair.Split('=')[0], pair => pair.Split('=')[1]);
 89                }
 90
 091                return result;
 92            }
 93
 94            private static string GetEnvironmentVariableOrThrow(string environmentSettingName)
 95            {
 096                string result = Environment.GetEnvironmentVariable(environmentSettingName);
 097                if (string.IsNullOrEmpty(result))
 98                {
 099                    throw new ArgumentException(string.Format("Missing required environment variable {0}", environmentSe
 100                }
 101
 0102                return result;
 103            }
 104
 105            private static string GetEnvironmentVariableOrDefault(string environmentSettingName, string defaultValue)
 106            {
 0107                string result = Environment.GetEnvironmentVariable(environmentSettingName);
 0108                if (string.IsNullOrEmpty(result))
 109                {
 0110                    return defaultValue;
 111                }
 112
 0113                return result;
 114            }
 115        }
 116
 0117        private static readonly Lazy<TestConfiguration> configurationInstance = new Lazy<TestConfiguration>(() => new Te
 118
 119        public static TestConfiguration Configuration
 120        {
 0121            get { return configurationInstance.Value; }
 122        }
 123    }
 124}