< Summary

Class:Azure.Identity.HttpExtensions
Assembly:Azure.Identity
File(s):C:\Git\azure-sdk-for-net\sdk\identity\Azure.Identity\src\HttpExtensions.cs
Covered lines:23
Uncovered lines:6
Coverable lines:29
Total lines:85
Line coverage:79.3% (23 of 29)
Covered branches:11
Total branches:16
Branch coverage:68.7% (11 of 16)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ToPipelineRequestAsync()-100%100%
AddHeader(...)-0%0%
ToHttpResponseMessage(...)-90.91%83.33%
ToPipelineRequestContentAsync()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\identity\Azure.Identity\src\HttpExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using Azure.Core.Pipeline;
 5using Azure;
 6using System;
 7using System.Net.Http;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using System.Net;
 11using Azure.Core;
 12
 13namespace Azure.Identity
 14{
 15    internal static class HttpExtensions
 16    {
 17        public static async Task<Request> ToPipelineRequestAsync(this HttpRequestMessage request, HttpPipeline pipeline)
 18        {
 21619            Request pipelineRequest = pipeline.CreateRequest();
 20
 21621            pipelineRequest.Method = RequestMethod.Parse(request.Method.Method);
 22
 21623            pipelineRequest.Uri.Reset(request.RequestUri);
 24
 21625            pipelineRequest.Content = await request.Content.ToPipelineRequestContentAsync().ConfigureAwait(false);
 26
 448027            foreach (System.Collections.Generic.KeyValuePair<string, System.Collections.Generic.IEnumerable<string>> hea
 28            {
 809629                foreach (var value in header.Value)
 30                {
 202431                    pipelineRequest.Headers.Add(header.Key, value);
 32                }
 33            }
 34
 21635            return pipelineRequest;
 21636        }
 37
 38        private static void AddHeader(HttpResponseMessage request, HttpHeader header)
 39        {
 040            if (request.Headers.TryAddWithoutValidation(header.Name, header.Value))
 41            {
 042                return;
 43            }
 44
 045            if (!request.Content.Headers.TryAddWithoutValidation(header.Name, header.Value))
 46            {
 047                throw new InvalidOperationException("Unable to add header to request or content");
 48            }
 049        }
 50
 51        public static HttpResponseMessage ToHttpResponseMessage(this Response response)
 52        {
 20853            HttpResponseMessage responseMessage = new HttpResponseMessage
 20854            {
 20855                StatusCode = (HttpStatusCode)response.Status,
 20856
 20857                Content = new StreamContent(response.ContentStream)
 20858            };
 59
 474860            foreach (HttpHeader header in response.Headers)
 61            {
 216662                if (!responseMessage.Headers.TryAddWithoutValidation(header.Name, header.Value))
 63                {
 45264                    if (!responseMessage.Content.Headers.TryAddWithoutValidation(header.Name, header.Value))
 65                    {
 066                        throw new InvalidOperationException("Unable to add header to request or content");
 67                    }
 68                }
 69            }
 70
 20871            return responseMessage;
 72        }
 73
 74        public static async Task<RequestContent> ToPipelineRequestContentAsync(this HttpContent content)
 75        {
 21676            if (content != null)
 77            {
 16078                return RequestContent.Create(await content.ReadAsStreamAsync().ConfigureAwait(false));
 79            }
 80
 5681            return null;
 21682        }
 83
 84    }
 85}