< Summary

Class:Azure.Core.ClientOptions
Assembly:Azure.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\ClientOptions.cs
Covered lines:16
Uncovered lines:4
Coverable lines:20
Total lines:113
Line coverage:80% (16 of 20)
Covered branches:4
Total branches:6
Branch coverage:66.6% (4 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
get_Transport()-100%100%
set_Transport(...)-100%50%
get_Diagnostics()-100%100%
get_Retry()-100%100%
AddPolicy(...)-80%75%
get_PerCallPolicies()-100%100%
get_PerRetryPolicies()-100%100%
Equals(...)-0%100%
GetHashCode()-0%100%
ToString()-0%100%
GetDefaultTransport()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\ClientOptions.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.ComponentModel;
 7using Azure.Core.Pipeline;
 8
 9namespace Azure.Core
 10{
 11    /// <summary>
 12    /// Base type for all client option types, exposes various common client options like <see cref="Diagnostics"/>, <se
 13    /// </summary>
 14    public abstract class ClientOptions
 15    {
 9416        private HttpPipelineTransport _transport = GetDefaultTransport();
 17
 18        /// <summary>
 19        /// Creates a new instance of <see cref="ClientOptions"/>.
 20        /// </summary>
 9421        protected ClientOptions()
 22        {
 9423            Retry = new RetryOptions();
 9424            Diagnostics = new DiagnosticsOptions();
 9425        }
 26
 27        /// <summary>
 28        /// The <see cref="HttpPipelineTransport"/> to be used for this client. Defaults to an instance of <see cref="Ht
 29        /// </summary>
 30        public HttpPipelineTransport Transport
 31        {
 5832            get => _transport;
 4033            set => _transport = value ?? throw new ArgumentNullException(nameof(value));
 34        }
 35
 36        /// <summary>
 37        /// Gets the client diagnostic options.
 38        /// </summary>
 26039        public DiagnosticsOptions Diagnostics { get; }
 40
 41        /// <summary>
 42        /// Gets the client retry options.
 43        /// </summary>
 15644        public RetryOptions Retry { get; }
 45
 46        /// <summary>
 47        /// Adds an <see cref="HttpPipeline"/> policy into the client pipeline. The position of policy in the pipeline i
 48        /// If you want the policy to execute once per client request use <see cref="HttpPipelinePosition.PerCall"/> oth
 49        /// to run the policy for every retry. Note that the same instance of <paramref name="policy"/> would be added t
 50        /// </summary>
 51        /// <param name="policy">The <see cref="HttpPipelinePolicy"/> instance to be added to the pipeline.</param>
 52        /// <param name="position">The position of policy in the pipeline.</param>
 53        public void AddPolicy(HttpPipelinePolicy policy, HttpPipelinePosition position)
 54        {
 55            switch (position)
 56            {
 57                case HttpPipelinePosition.PerCall:
 858                    PerCallPolicies.Add(policy);
 859                    break;
 60                case HttpPipelinePosition.PerRetry:
 461                    PerRetryPolicies.Add(policy);
 462                    break;
 63                default:
 064                    throw new ArgumentOutOfRangeException(nameof(position), position, null);
 65            }
 66        }
 67
 15868        internal IList<HttpPipelinePolicy> PerCallPolicies { get; } = new List<HttpPipelinePolicy>();
 69
 15470        internal IList<HttpPipelinePolicy> PerRetryPolicies { get; } = new List<HttpPipelinePolicy>();
 71
 72        /// <inheritdoc />
 73        [EditorBrowsable(EditorBrowsableState.Never)]
 074        public override bool Equals(object? obj) => base.Equals(obj);
 75
 76        /// <inheritdoc />
 77        [EditorBrowsable(EditorBrowsableState.Never)]
 078        public override int GetHashCode() => base.GetHashCode();
 79
 80        /// <inheritdoc />
 81        [EditorBrowsable(EditorBrowsableState.Never)]
 082        public override string ToString() => base.ToString();
 83
 84
 85        private static HttpPipelineTransport GetDefaultTransport()
 86        {
 87// TODO: Uncomment after release
 88#if false && NETFRAMEWORK
 89            bool GetSwitchValue(string switchName, string envVariable)
 90            {
 91                if (!AppContext.TryGetSwitch(switchName, out bool ret))
 92                {
 93                    string? switchValue = Environment.GetEnvironmentVariable(envVariable);
 94                    if (switchValue != null)
 95                    {
 96                        ret = string.Equals("true", switchValue, StringComparison.InvariantCultureIgnoreCase) ||
 97                              switchValue.Equals("1", StringComparison.InvariantCultureIgnoreCase);
 98                    }
 99                }
 100
 101                return ret;
 102            }
 103
 104            if (!GetSwitchValue("Azure.Core.Pipeline.DisableHttpWebRequestTransport", "AZURE_CORE_DISABLE_HTTPWEBREQUEST
 105            {
 106                return HttpWebRequestTransport.Shared;
 107            }
 108#endif
 94109            return HttpClientTransport.Shared;
 110        }
 111
 112    }
 113}