< Summary

Class:Azure.Core.Pipeline.ReadClientRequestIdPolicy
Assembly:Azure.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Pipeline\Internal\ReadClientRequestIdPolicy.cs
Covered lines:18
Uncovered lines:0
Coverable lines:18
Total lines:56
Line coverage:100% (18 of 18)
Covered branches:6
Total branches:6
Branch coverage:100% (6 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor()-100%100%
get_Shared()-100%100%
OnSendingRequest(...)-100%100%
StartScope(...)-100%100%
.ctor(...)-100%100%
get_ClientRequestId()-100%100%
Dispose()-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Threading;
 6
 7namespace Azure.Core.Pipeline
 8{
 9    internal class ReadClientRequestIdPolicy : HttpPipelineSynchronousPolicy
 10    {
 211        private static readonly AsyncLocal<ClientRequestIdScope?> CurrentRequestIdScope = new AsyncLocal<ClientRequestId
 12
 213        protected ReadClientRequestIdPolicy()
 14        {
 215        }
 16
 6617        public static ReadClientRequestIdPolicy Shared { get; } = new ReadClientRequestIdPolicy();
 18
 19        public override void OnSendingRequest(HttpMessage message)
 20        {
 164421            if (message.Request.Headers.TryGetValue(ClientRequestIdPolicy.ClientRequestIdHeader, out string? value))
 22            {
 623                message.Request.ClientRequestId = value;
 24            }
 163825            else if (CurrentRequestIdScope.Value?.ClientRequestId != null)
 26            {
 427                message.Request.ClientRequestId = CurrentRequestIdScope.Value.ClientRequestId;
 28            }
 163829        }
 30
 31        internal static IDisposable StartScope(string? clientRequestId)
 32        {
 1033            CurrentRequestIdScope.Value = new ClientRequestIdScope(clientRequestId, CurrentRequestIdScope.Value);
 34
 1035            return CurrentRequestIdScope.Value;
 36        }
 37
 38        private class ClientRequestIdScope: IDisposable
 39        {
 40            private readonly ClientRequestIdScope? _parent;
 41
 1042            internal ClientRequestIdScope(string? clientRequestId, ClientRequestIdScope? parent)
 43            {
 1044                ClientRequestId = clientRequestId;
 1045                _parent = parent;
 1046            }
 47
 1048            public string? ClientRequestId { get; }
 49
 50            public void Dispose()
 51            {
 1052                CurrentRequestIdScope.Value = _parent;
 1053            }
 54        }
 55    }
 56}