< Summary

Class:Microsoft.Azure.CognitiveServices.Language.SpellCheck.ApiKeyServiceClientCredentials
Assembly:Microsoft.Azure.CognitiveServices.Language.SpellCheck
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.SpellCheck\src\Customizations\ApiKeyServiceClientCredentials.cs
Covered lines:7
Uncovered lines:2
Coverable lines:9
Total lines:43
Line coverage:77.7% (7 of 9)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.SpellCheck\src\Customizations\ApiKeyServiceClientCredentials.cs

#LineLine coverage
 1namespace Microsoft.Azure.CognitiveServices.Language.SpellCheck
 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>
 120        public ApiKeyServiceClientCredentials(string subscriptionKey)
 21        {
 122            if (string.IsNullOrWhiteSpace(subscriptionKey))
 023                throw new ArgumentNullException("subscriptionKey");
 24
 125            this.subscriptionKey = subscriptionKey;
 126        }
 27
 28        /// <summary>
 29        /// Add the Basic Authentication Header to each outgoing request
 30        /// </summary>
 31        /// <param name="request">The outgoing request</param>
 32        /// <param name="cancellationToken">A token to cancel the operation</param>
 33        public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 34        {
 135            if (request == null)
 036                throw new ArgumentNullException("request");
 37
 138            request.Headers.Add("Ocp-Apim-Subscription-Key", this.subscriptionKey);
 39
 140            return Task.FromResult<object>(null);
 41        }
 42    }
 43}