< Summary

Class:Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentExtensions
Assembly:Search.Management.Tests
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\tests\Utilities\TestEnvironmentExtensions.cs
Covered lines:23
Uncovered lines:7
Coverable lines:30
Total lines:100
Line coverage:76.6% (23 of 30)
Covered branches:6
Total branches:11
Branch coverage:54.5% (6 of 11)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
GetSearchDnsSuffix(...)-40%40%
GetBaseSearchUri(...)-0%100%
LookupEnvironmentFromBaseUri(...)-94.44%75%
MatchEnvironmentBaseUri(...)-100%100%
EnsureTrailingSlash(...)-66.67%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\tests\Utilities\TestEnvironmentExtensions.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.Rest.ClientRuntime.Azure.TestFramework
 6{
 7    using System;
 8    using System.Collections.Generic;
 9
 10    /// <summary>
 11    /// Extensions to the TestEnvironment class.
 12    /// </summary>
 13    public static class TestEnvironmentExtensions
 14    {
 15        /// <summary>
 16        /// Gets the fully-qualified domain name suffix of an Azure Search service for the given test environment and se
 17        /// </summary>
 18        /// <param name="environment">The test environment.</param>
 19        /// <param name="searchServiceName">The name of the search service.</param>
 20        /// <returns>The fully-qualified domain name of the search service in the given environment.</returns>
 21        public static string GetSearchDnsSuffix(this TestEnvironment environment, string searchServiceName)
 22        {
 139423            EnvironmentNames envName = LookupEnvironmentFromBaseUri(environment.BaseUri.AbsoluteUri);
 24
 25            switch (envName)
 26            {
 27                case EnvironmentNames.Dogfood:
 028                    return "search-dogfood.windows-int.net";
 29
 30                case EnvironmentNames.Next:
 031                    return "search-next.windows-int.net";
 32
 33                case EnvironmentNames.Current:
 034                    return "search-current.windows-int.net";
 35
 36                case EnvironmentNames.Prod:
 37                default:
 38                    // Assume PROD if all else fails.
 139439                    return "search.windows.net";
 40            }
 41        }
 42
 43        /// <summary>
 44        /// Gets the base URI of an Azure Search service for the given test environment and service name.
 45        /// </summary>
 46        /// <param name="environment">The test environment.</param>
 47        /// <param name="searchServiceName">The name of the search service.</param>
 48        /// <returns>The correct base URI of the search service in the given environment.</returns>
 49        public static Uri GetBaseSearchUri(this TestEnvironment environment, string searchServiceName)
 50        {
 51            const string UriFormat = "https://{0}.{1}/";
 052            string dnsSuffix = environment.GetSearchDnsSuffix(searchServiceName);
 053            return new Uri(String.Format(UriFormat, searchServiceName, dnsSuffix));
 54        }
 55
 56        private static EnvironmentNames LookupEnvironmentFromBaseUri(string resourceManagementUri)
 57        {
 139458            Dictionary<Uri, EnvironmentNames> envEndpoints = new Dictionary<Uri, EnvironmentNames>();
 59
 139460            envEndpoints.Add(
 139461                new Uri("https://management.azure.com/"),
 139462                EnvironmentNames.Prod);
 139463            envEndpoints.Add(
 139464                new Uri("https://api-dogfood.resources.windows-int.net/"),
 139465                EnvironmentNames.Dogfood);
 139466            envEndpoints.Add(
 139467                new Uri("https://api-next.resources.windows-int.net/"),
 139468                EnvironmentNames.Next);
 139469            envEndpoints.Add(
 139470                new Uri("https://api-current.resources.windows-int.net/"),
 139471                EnvironmentNames.Current);
 72
 418273            foreach (Uri testUri in envEndpoints.Keys)
 74            {
 139475                if (MatchEnvironmentBaseUri(testUri, resourceManagementUri))
 76                {
 139477                    return envEndpoints[testUri];
 78                }
 79            }
 80
 081            return EnvironmentNames.Prod;
 139482        }
 83
 84        private static bool MatchEnvironmentBaseUri(Uri testUri, string endpointValue)
 85        {
 139486            endpointValue = EnsureTrailingSlash(endpointValue);
 139487            return string.Equals(testUri.ToString(), endpointValue, StringComparison.OrdinalIgnoreCase);
 88        }
 89
 90        private static string EnsureTrailingSlash(string uri)
 91        {
 139492            if (uri.EndsWith("/"))
 93            {
 139494                return uri;
 95            }
 96
 097            return string.Format("{0}/", uri);
 98        }
 99    }
 100}