< Summary

Class:KeyVault.TestFramework.TestConfigurationManager
Assembly:Microsoft.Azure.KeyVault.TestFramework
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault\tests\TestFramework\TestConfigurationManager.cs
Covered lines:7
Uncovered lines:12
Coverable lines:19
Total lines:58
Line coverage:36.8% (7 of 19)
Covered branches:4
Total branches:10
Branch coverage:40% (4 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
GetEnvironmentOrAppSetting(...)-0%0%
TryGetEnvironmentOrAppSetting(...)-100%100%
GetEnvironmentSetting(...)-0%0%
TryGetEnvironmentSetting(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault\tests\TestFramework\TestConfigurationManager.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
 4using System;
 5using Microsoft.Extensions.Configuration;
 6using System.IO;
 7
 8namespace KeyVault.TestFramework
 9{
 10    public class TestConfigurationManager
 11    {
 12        public static string GetEnvironmentOrAppSetting(string settingName)
 13        {
 014            var value = TryGetEnvironmentOrAppSetting(settingName, null);
 15
 016            if (value == null)
 017                throw new Exception(string.Format("Missing configuration setting for {0}", settingName));
 18
 019            return value;
 20        }
 21
 22        public static string TryGetEnvironmentOrAppSetting(string settingName, string defaultValue = null)
 23        {
 3224            var value = Environment.GetEnvironmentVariable(settingName);
 25
 26            // We don't use IsNullOrEmpty because an empty setting overrides what's on AppSettings.
 3227            if (value == null)
 28            {
 3229                var config = new ConfigurationBuilder()
 3230                                    .SetBasePath(Directory.GetCurrentDirectory())
 3231                                    .AddJsonFile("appsettings.json").Build();
 3232                value = config.GetSection("AppSettings:" + settingName).Value;
 33            }
 34
 3235            return value ?? defaultValue;
 36        }
 37
 38        public static string GetEnvironmentSetting(string settingName)
 39        {
 040            var result = TryGetEnvironmentSetting(settingName, null);
 41
 042            if (string.IsNullOrEmpty(result))
 043                throw new Exception(string.Format("Missing environment variable for {0}", settingName));
 44
 045            return result;
 46        }
 47
 48        public static string TryGetEnvironmentSetting(string settingName, string defaultValue = null)
 49        {
 050            var result = Environment.GetEnvironmentVariable(settingName);
 51
 052            if (string.IsNullOrWhiteSpace(result))
 053                result = defaultValue;
 54
 055            return result;
 56        }
 57    }
 58}