< Summary

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker
 6{
 7    using System;
 8    using System.Net.Http;
 9    using System.Threading;
 10    using System.Threading.Tasks;
 11    using Microsoft.Rest;
 12
 13    /// <summary>
 14    /// Allows authentication to the API using a basic apiKey mechanism
 15    /// </summary>
 16    public class EndpointKeyServiceClientCredentials : ServiceClientCredentials
 17    {
 18        private readonly string endpointKey;
 19
 20        /// <summary>
 21        /// Creates a new instance of the EndpointKeyServiceClientCredentials class
 22        /// </summary>
 23        /// <param name="endpointKey">The Endpoint key to authenticate and authorize as</param>
 224        public EndpointKeyServiceClientCredentials(string endpointKey)
 25        {
 226            this.endpointKey = endpointKey;
 227        }
 28
 29        /// <summary>
 30        /// Add the Basic Authentication Header to each outgoing request
 31        /// </summary>
 32        /// <param name="request">The outgoing request</param>
 33        /// <param name="cancellationToken">A token to cancel the operation</param>
 34        public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 35        {
 236            if (request == null)
 037                throw new ArgumentNullException("request");
 38
 239            request.Headers.Add("Authorization", $"EndpointKey {this.endpointKey}");
 40
 241            return Task.FromResult<object>(null);
 42        }
 43    }
 44}