< Summary

Class:Microsoft.Azure.Search.Tests.Utilities.SearchTestUtilities
Assembly:Search.Management.Tests
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\tests\Utilities\SearchTestUtilities.cs
Covered lines:8
Uncovered lines:23
Coverable lines:31
Total lines:98
Line coverage:25.8% (8 of 31)
Covered branches:1
Total branches:12
Branch coverage:8.3% (1 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-0%100%
GenerateServiceName()-100%100%
GenerateName()-100%100%
WaitForIndexing()-100%100%
WaitForSynonymMapUpdate()-100%100%
WaitForServiceProvisioning()-0%100%
WaitForSearchServiceDns(...)-15.38%16.67%
CanResolve(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\tests\Utilities\SearchTestUtilities.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.Search.Tests.Utilities
 6{
 7    using System;
 8    using System.Linq;
 9    using System.Net.Http;
 10    using System.Threading;
 11    using Microsoft.Azure.Test.HttpRecorder;
 12    using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
 13
 14    public static class SearchTestUtilities
 15    {
 016        private static readonly HttpClient _httpClient = new HttpClient();
 17
 18        public static string GenerateServiceName()
 19        {
 60220            return TestUtilities.GenerateName(prefix: "azs-");
 21        }
 22
 23        public static string GenerateName()
 24        {
 199425            return TestUtilities.GenerateName();
 26        }
 27
 28        public static void WaitForIndexing()
 29        {
 41830            TestUtilities.Wait(TimeSpan.FromSeconds(2));
 41831        }
 32
 33        public static void WaitForSynonymMapUpdate()
 34        {
 435            TestUtilities.Wait(TimeSpan.FromSeconds(5));
 436        }
 37
 38        public static void WaitForServiceProvisioning()
 39        {
 040            TestUtilities.Wait(TimeSpan.FromSeconds(10));
 041        }
 42
 43        public static bool WaitForSearchServiceDns(string searchServiceName, TimeSpan maxDelay)
 44        {
 60245            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
 46            {
 47                // Nothing to wait for when we're running mocked.
 60248                return true;
 49            }
 50
 051            TestEnvironment testEnvironment = TestEnvironmentFactory.GetTestEnvironment();
 052            Uri baseUri = testEnvironment.GetBaseSearchUri(searchServiceName);
 53
 054            TimeSpan retryDelay = TimeSpan.FromSeconds(1);
 55
 056            long maxRetries = (long)(maxDelay.TotalSeconds / retryDelay.TotalSeconds);
 057            int retries = 0;
 58
 059            while (retries < maxRetries)
 60            {
 061                if (CanResolve(baseUri))
 62                {
 063                    return true;
 64                }
 65                else
 66                {
 067                    Thread.Sleep(retryDelay);
 068                    retries++;
 69                }
 70            }
 71
 072            return false;
 73        }
 74
 75        // Workaround since the Dns class is not available in PCLs.
 76        private static bool CanResolve(Uri url)
 77        {
 78            try
 79            {
 080                return _httpClient.GetAsync(url).Wait(TimeSpan.FromSeconds(5));
 81            }
 082            catch (AggregateException e)
 83            {
 084                HttpRequestException httpEx = e.InnerExceptions.FirstOrDefault() as HttpRequestException;
 085                if (httpEx != null)
 86                {
 087                    if (httpEx.InnerException != null &&
 088                        httpEx.InnerException.Message.Contains("could not be resolved"))
 89                    {
 090                        return false;
 91                    }
 92                }
 93
 094                throw;
 95            }
 096        }
 97    }
 98}