< Summary

Class:Microsoft.Azure.ServiceBus.Amqp.AmqpLinkCreator
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Amqp\AmqpLinkCreator.cs
Covered lines:0
Uncovered lines:45
Coverable lines:45
Total lines:95
Line coverage:0% (0 of 45)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%100%
get_ClientId()-0%100%
CreateAndOpenAmqpLinkAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Amqp\AmqpLinkCreator.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus.Amqp
 5{
 6    using System;
 7    using System.Threading.Tasks;
 8    using Microsoft.Azure.Amqp;
 9    using Microsoft.Azure.Amqp.Framing;
 10    using Microsoft.Azure.ServiceBus.Primitives;
 11
 12    internal abstract class AmqpLinkCreator
 13    {
 14        readonly string entityPath;
 15        readonly ServiceBusConnection serviceBusConnection;
 16        readonly Uri endpointAddress;
 17        readonly string[] audience;
 18        readonly string[] requiredClaims;
 19        readonly ICbsTokenProvider cbsTokenProvider;
 20        readonly AmqpLinkSettings amqpLinkSettings;
 21
 022        protected AmqpLinkCreator(string entityPath, ServiceBusConnection serviceBusConnection, Uri endpointAddress, str
 23        {
 024            this.entityPath = entityPath;
 025            this.serviceBusConnection = serviceBusConnection;
 026            this.endpointAddress = endpointAddress;
 027            this.audience = audience;
 028            this.requiredClaims = requiredClaims;
 029            this.cbsTokenProvider = cbsTokenProvider;
 030            this.amqpLinkSettings = amqpLinkSettings;
 031            this.ClientId = clientId;
 032        }
 33
 034        protected string ClientId { get; }
 35
 36        public async Task<Tuple<AmqpObject, DateTime>> CreateAndOpenAmqpLinkAsync()
 37        {
 038            var timeoutHelper = new TimeoutHelper(this.serviceBusConnection.OperationTimeout, true);
 39
 040            MessagingEventSource.Log.AmqpGetOrCreateConnectionStart();
 041            var amqpConnection = await this.serviceBusConnection.ConnectionManager.GetOrCreateAsync(timeoutHelper.Remain
 042            MessagingEventSource.Log.AmqpGetOrCreateConnectionStop(this.entityPath, amqpConnection.ToString(), amqpConne
 43
 44            // Authenticate over CBS
 045            var cbsLink = amqpConnection.Extensions.Find<AmqpCbsLink>();
 046            DateTime cbsTokenExpiresAtUtc = DateTime.MaxValue;
 47
 048            foreach (var resource in this.audience)
 49            {
 050                MessagingEventSource.Log.AmqpSendAuthenticationTokenStart(this.endpointAddress, resource, resource, this
 051                cbsTokenExpiresAtUtc = TimeoutHelper.Min(
 052                    cbsTokenExpiresAtUtc,
 053                    await cbsLink.SendTokenAsync(this.cbsTokenProvider, this.endpointAddress, resource, resource, this.r
 054                MessagingEventSource.Log.AmqpSendAuthenticationTokenStop();
 55            }
 56
 057            AmqpSession session = null;
 58            try
 59            {
 60                // Create Session
 061                var amqpSessionSettings = new AmqpSessionSettings { Properties = new Fields() };
 062                session = amqpConnection.CreateSession(amqpSessionSettings);
 063                await session.OpenAsync(timeoutHelper.RemainingTime()).ConfigureAwait(false);
 064            }
 065            catch (Exception exception)
 66            {
 067                MessagingEventSource.Log.AmqpSessionCreationException(this.entityPath, amqpConnection, exception);
 068                session?.Abort();
 069                throw AmqpExceptionHelper.GetClientException(exception, null, session.GetInnerException(), amqpConnectio
 70            }
 71
 072            AmqpObject link = null;
 73            try
 74            {
 75                // Create Link
 076                link = this.OnCreateAmqpLink(amqpConnection, this.amqpLinkSettings, session);
 077                await link.OpenAsync(timeoutHelper.RemainingTime()).ConfigureAwait(false);
 078                return new Tuple<AmqpObject, DateTime>(link, cbsTokenExpiresAtUtc);
 79            }
 080            catch (Exception exception)
 81            {
 082                MessagingEventSource.Log.AmqpLinkCreationException(
 083                    this.entityPath,
 084                    session,
 085                    amqpConnection,
 086                    exception);
 87
 088                session.SafeClose(exception);
 089                throw AmqpExceptionHelper.GetClientException(exception, null, link?.GetInnerException(), amqpConnection.
 90            }
 091        }
 92
 93        protected abstract AmqpObject OnCreateAmqpLink(AmqpConnection connection, AmqpLinkSettings linkSettings, AmqpSes
 94    }
 95}