< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.ComputerVision.ApiKeyServiceClientCredentials
Assembly:Microsoft.Azure.CognitiveServices.Vision.ComputerVision
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.ComputerVision\src\Customizations\ApiKeyServiceClientCredentials.cs
Covered lines:6
Uncovered lines:1
Coverable lines:7
Total lines:40
Line coverage:85.7% (6 of 7)
Covered branches:1
Total branches:2
Branch coverage:50% (1 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
ProcessHttpRequestAsync(...)-75%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.ComputerVision\src\Customizations\ApiKeyServiceClientCredentials.cs

#LineLine coverage
 1namespace Microsoft.Azure.CognitiveServices.Vision.ComputerVision
 2{
 3    using System;
 4    using System.Net.Http;
 5    using System.Threading;
 6    using System.Threading.Tasks;
 7    using Microsoft.Rest;
 8
 9    /// <summary>
 10    /// Allows authentication to the API using a basic apiKey mechanism
 11    /// </summary>
 12    public class ApiKeyServiceClientCredentials : ServiceClientCredentials
 13    {
 14        private readonly string subscriptionKey;
 15
 16        /// <summary>
 17        /// Creates a new instance of the ApiKeyServiceClientCredentails class
 18        /// </summary>
 19        /// <param name="subscriptionKey">The subscription key to authenticate and authorize as</param>
 4220        public ApiKeyServiceClientCredentials(string subscriptionKey)
 21        {
 4222            this.subscriptionKey = subscriptionKey;
 4223        }
 24
 25        /// <summary>
 26        /// Add the Basic Authentication Header to each outgoing request
 27        /// </summary>
 28        /// <param name="request">The outgoing request</param>
 29        /// <param name="cancellationToken">A token to cancel the operation</param>
 30        public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 31        {
 3832            if (request == null)
 033                throw new ArgumentNullException("request");
 34
 3835            request.Headers.Add("Ocp-Apim-Subscription-Key", this.subscriptionKey);
 36
 3837            return Task.FromResult<object>(null);
 38        }
 39    }
 40}