< Summary

Class:Microsoft.Azure.Attestation.AttestationCredentials
Assembly:Microsoft.Azure.Attestation
File(s):C:\Git\azure-sdk-for-net\sdk\attestation\Microsoft.Azure.Attestation\src\Customized\AttestationCredentials.cs
Covered lines:8
Uncovered lines:2
Coverable lines:10
Total lines:52
Line coverage:80% (8 of 10)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\attestation\Microsoft.Azure.Attestation\src\Customized\AttestationCredentials.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 license information.
 3
 4using Microsoft.Rest;
 5using System;
 6using System.Net.Http;
 7using System.Threading;
 8using System.Threading.Tasks;
 9
 10namespace Microsoft.Azure.Attestation
 11{
 12    /// <summary>
 13    /// The Attestation credential class that implements <see cref="ServiceClientCredentials"/>
 14    /// </summary>
 15    public class AttestationCredentials : ServiceClientCredentials
 16    {
 17        /// <summary>
 18        /// Bearer token
 19        /// </summary>
 2820        public string Token { get; set; }
 21
 22        /// <summary>
 23        /// Constructor.
 24        /// </summary>
 25        /// <param name="token"> token. </param>
 826        public AttestationCredentials(string token)
 27        {
 828            if (string.IsNullOrEmpty(token))
 29            {
 030                throw new ArgumentException($"{nameof(token)} must not be null or empty");
 31            }
 32
 833            this.Token = token;
 834        }
 35
 36        /// <summary>
 37        /// ProcessHttpRequestAsync.
 38        /// </summary>
 39        /// <param name="request"> request. </param>
 40        /// <param name="cancellationToken"> cancellationToken. </param>
 41        public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 42        {
 2043            if (request == null)
 44            {
 045                throw new ArgumentNullException(nameof(request));
 46            }
 47
 2048            request.Headers.Add("Authorization", $"Bearer {Token}");
 2049            return Task.FromResult(true);
 50        }
 51    }
 52}