< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-0%100%
get_Instance()-0%100%
EnlistAsync()-0%0%
RemoveEnlistment(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Amqp\AmqpTransactionManager.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.Collections.Generic;
 8    using System.Threading.Tasks;
 9    using System.Transactions;
 10
 11    internal class AmqpTransactionManager
 12    {
 013        readonly object syncRoot = new object();
 014        readonly Dictionary<string, AmqpTransactionEnlistment> enlistmentMap = new Dictionary<string, AmqpTransactionEnl
 15
 016        public static AmqpTransactionManager Instance { get; } = new AmqpTransactionManager();
 17
 18        public async Task<ArraySegment<byte>> EnlistAsync(
 19            Transaction transaction,
 20            ServiceBusConnection serviceBusConnection)
 21        {
 022            if (transaction.IsolationLevel != IsolationLevel.Serializable)
 23            {
 024                throw new InvalidOperationException($"The only supported IsolationLevel is {nameof(IsolationLevel.Serial
 25            }
 26
 027            string transactionId = transaction.TransactionInformation.LocalIdentifier;
 28            AmqpTransactionEnlistment transactionEnlistment;
 29
 030            lock (this.syncRoot)
 31            {
 032                if (!this.enlistmentMap.TryGetValue(transactionId, out transactionEnlistment))
 33                {
 034                    transactionEnlistment = new AmqpTransactionEnlistment(transaction, this, serviceBusConnection);
 035                    this.enlistmentMap.Add(transactionId, transactionEnlistment);
 36
 037                    if (!transaction.EnlistPromotableSinglePhase(transactionEnlistment))
 38                    {
 039                        this.enlistmentMap.Remove(transactionId);
 040                        throw new InvalidOperationException("Local transactions are not supported with other resource ma
 41                    }
 42                }
 043            }
 44
 045            transactionEnlistment = await transactionEnlistment.GetOrCreateAsync(serviceBusConnection.OperationTimeout).
 046            return transactionEnlistment.AmqpTransactionId;
 047        }
 48
 49        public void RemoveEnlistment(string transactionId)
 50        {
 051            lock (this.syncRoot)
 52            {
 053                this.enlistmentMap.Remove(transactionId);
 054            }
 055        }
 56    }
 57}