< Summary

Class:Azure.Core.Pipeline.HttpPipelineBuilder
Assembly:Azure.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Pipeline\HttpPipelineBuilder.cs
Covered lines:37
Uncovered lines:3
Coverable lines:40
Total lines:121
Line coverage:92.5% (37 of 40)
Covered branches:11
Total branches:14
Branch coverage:78.5% (11 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Build(...)-100%100%
Build(...)-92.59%75%
CreateTelemetryPolicy(...)-91.67%83.33%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Pipeline\HttpPipelineBuilder.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using System.Reflection;
 8
 9namespace Azure.Core.Pipeline
 10{
 11    /// <summary>
 12    /// Factory for creating instances of <see cref="HttpPipeline"/> populated with default policies.
 13    /// </summary>
 14    public static class HttpPipelineBuilder
 15    {
 16        /// <summary>
 17        /// Creates an instance of <see cref="HttpPipeline"/> populated with default policies, customer provided policie
 18        /// </summary>
 19        /// <param name="options">The customer provided client options object.</param>
 20        /// <param name="perRetryPolicies">Client provided per-retry policies.</param>
 21        /// <returns>A new instance of <see cref="HttpPipeline"/></returns>
 22        public static HttpPipeline Build(ClientOptions options, params HttpPipelinePolicy[] perRetryPolicies)
 23        {
 5424            return Build(options, Array.Empty<HttpPipelinePolicy>(), perRetryPolicies, new ResponseClassifier());
 25        }
 26
 27        /// <summary>
 28        /// Creates an instance of <see cref="HttpPipeline"/> populated with default policies, customer provided policie
 29        /// </summary>
 30        /// <param name="options">The customer provided client options object.</param>
 31        /// <param name="perCallPolicies">Client provided per-call policies.</param>
 32        /// <param name="perRetryPolicies">Client provided per-retry policies.</param>
 33        /// <param name="responseClassifier">The client provided response classifier.</param>
 34        /// <returns>A new instance of <see cref="HttpPipeline"/></returns>
 35        public static HttpPipeline Build(ClientOptions options, HttpPipelinePolicy[] perCallPolicies, HttpPipelinePolicy
 36        {
 5637            if (perCallPolicies == null)
 38            {
 039                throw new ArgumentNullException(nameof(perCallPolicies));
 40            }
 41
 5642            if (perRetryPolicies == null)
 43            {
 044                throw new ArgumentNullException(nameof(perRetryPolicies));
 45            }
 46
 5647            var policies = new List<HttpPipelinePolicy>();
 48
 5649            bool isDistributedTracingEnabled = options.Diagnostics.IsDistributedTracingEnabled;
 50
 5651            policies.Add(ReadClientRequestIdPolicy.Shared);
 52
 5653            policies.AddRange(perCallPolicies);
 54
 5655            policies.AddRange(options.PerCallPolicies);
 56
 5657            policies.Add(ClientRequestIdPolicy.Shared);
 58
 5659            DiagnosticsOptions diagnostics = options.Diagnostics;
 5660            if (diagnostics.IsTelemetryEnabled)
 61            {
 5662                policies.Add(CreateTelemetryPolicy(options));
 63            }
 64
 5665            RetryOptions retryOptions = options.Retry;
 5666            policies.Add(new RetryPolicy(retryOptions.Mode, retryOptions.Delay, retryOptions.MaxDelay, retryOptions.MaxR
 67
 5668            policies.AddRange(perRetryPolicies);
 69
 5670            policies.AddRange(options.PerRetryPolicies);
 71
 5672            if (diagnostics.IsLoggingEnabled)
 73            {
 5674                string assemblyName = options.GetType().Assembly.GetName().Name;
 75
 5676                policies.Add(new LoggingPolicy(diagnostics.IsLoggingContentEnabled, diagnostics.LoggedContentSizeLimit,
 5677                    diagnostics.LoggedHeaderNames.ToArray(), diagnostics.LoggedQueryParameters.ToArray(), assemblyName))
 78            }
 79
 5680            policies.Add(new ResponseBodyPolicy(options.Retry.NetworkTimeout));
 81
 5682            policies.Add(new RequestActivityPolicy(isDistributedTracingEnabled, ClientDiagnostics.GetResourceProviderNam
 83
 45884            policies.RemoveAll(policy => policy == null);
 85
 5686            return new HttpPipeline(options.Transport,
 5687                policies.ToArray(),
 5688                responseClassifier);
 89        }
 90
 91        // internal for testing
 92        internal static TelemetryPolicy CreateTelemetryPolicy(ClientOptions options)
 93        {
 94            const string PackagePrefix = "Azure.";
 95
 5896            Assembly clientAssembly = options.GetType().Assembly;
 97
 5898            AssemblyInformationalVersionAttribute versionAttribute = clientAssembly.GetCustomAttribute<AssemblyInformati
 5899            if (versionAttribute == null)
 100            {
 0101                throw new InvalidOperationException($"{nameof(AssemblyInformationalVersionAttribute)} is required on cli
 102            }
 103
 58104            string version = versionAttribute.InformationalVersion;
 105
 58106            string assemblyName = clientAssembly.GetName().Name;
 58107            if (assemblyName.StartsWith(PackagePrefix, StringComparison.Ordinal))
 108            {
 58109                assemblyName = assemblyName.Substring(PackagePrefix.Length);
 110            }
 111
 58112            int hashSeparator = version.IndexOf('+');
 58113            if (hashSeparator != -1)
 114            {
 58115                version = version.Substring(0, hashSeparator);
 116            }
 117
 58118            return new TelemetryPolicy(assemblyName, version, options.Diagnostics.ApplicationId);
 119        }
 120    }
 121}