< Summary

Class:Microsoft.Azure.CognitiveServices.Personalizer.ApiKeyServiceClientCredentials
Assembly:Microsoft.Azure.CognitiveServices.Personalizer
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Personalizer\src\Customizations\ApiKeyServiceClientCredentials.cs
Covered lines:6
Uncovered lines:1
Coverable lines:7
Total lines:42
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\Personalizer\src\Customizations\ApiKeyServiceClientCredentials.cs

#LineLine coverage
 1using System;
 2using System.Net.Http;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using Microsoft.Rest;
 6
 7namespace Microsoft.Azure.CognitiveServices.Personalizer
 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 ApiKeyServiceClientCredentials class
 18        /// </summary>
 19        /// <param name="subscriptionKey">The subscription key to authenticate and authorize as</param>
 3420        public ApiKeyServiceClientCredentials(string subscriptionKey)
 21        {
 3422            this.subscriptionKey = subscriptionKey;
 3423        }
 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        {
 3432            if (request == null)
 33            {
 034                throw new ArgumentNullException("request");
 35            }
 36
 3437            request.Headers.Add("Ocp-Apim-Subscription-Key", this.subscriptionKey);
 3438            return Task.FromResult<object>(null);
 39        }
 40    }
 41}
 42