< Summary

Class:Microsoft.Azure.Batch.Protocol.BatchTokenProvider
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Protocol\BatchTokenProvider.cs
Covered lines:7
Uncovered lines:0
Coverable lines:7
Total lines:35
Line coverage:100% (7 of 7)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_TokenProvider()-100%100%
.ctor(...)-100%100%
GetAuthenticationHeaderAsync()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Protocol\BatchTokenProvider.cs

#LineLine coverage
 1//
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for license information.
 4
 5namespace Microsoft.Azure.Batch.Protocol
 6{
 7    using System;
 8    using System.Net.Http;
 9    using System.Net.Http.Headers;
 10    using System.Threading;
 11    using System.Threading.Tasks;
 12    using Rest;
 13
 14    public class BatchTokenProvider : ITokenProvider
 15    {
 16        private const string BearerAuthenticationScheme = "Bearer";
 17
 318        private Func<Task<string>> TokenProvider { get; }
 19
 20        /// <summary>
 21        /// Initializes a new instance of the <see cref="BatchTokenProvider"/> class.
 22        /// </summary>
 23        /// <param name="tokenProvider">A token provider function which retrieves an AAD token.</param>
 224        public BatchTokenProvider(Func<Task<string>> tokenProvider)
 25        {
 226            this.TokenProvider = tokenProvider;
 227        }
 28
 29        public async Task<AuthenticationHeaderValue> GetAuthenticationHeaderAsync(CancellationToken cancellationToken)
 30        {
 331            string token = await this.TokenProvider().ConfigureAwait(false);
 332            return new AuthenticationHeaderValue(BearerAuthenticationScheme, token);
 333        }
 34    }
 35}