< Summary

Class:Azure.Messaging.ServiceBus.Amqp.AmqpResponseMessage
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Amqp\AmqpResponseMessage.cs
Covered lines:0
Uncovered lines:28
Coverable lines:28
Total lines:88
Line coverage:0% (0 of 28)
Covered branches:0
Total branches:14
Branch coverage:0% (0 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
get_AmqpMessage()-0%100%
get_StatusCode()-0%100%
get_TrackingId()-0%100%
get_Map()-0%100%
CreateResponse(...)-0%100%
GetValue(...)-0%0%
GetListValue(...)-0%0%
GetResponseErrorCondition()-0%0%
ToMessagingContractException()-0%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using Microsoft.Azure.Amqp;
 8using Microsoft.Azure.Amqp.Encoding;
 9using Microsoft.Azure.Amqp.Framing;
 10
 11namespace Azure.Messaging.ServiceBus.Amqp
 12{
 13    internal sealed class AmqpResponseMessage
 14    {
 015        private AmqpResponseMessage(AmqpMessage responseMessage)
 16        {
 017            AmqpMessage = responseMessage;
 018            StatusCode = AmqpMessage.GetResponseStatusCode();
 019            if (AmqpMessage.ApplicationProperties.Map.TryGetValue<string>(ManagementConstants.Properties.TrackingId, out
 20            {
 021                TrackingId = trackingId;
 22            }
 23
 024            if (responseMessage.ValueBody != null)
 25            {
 026                Map = responseMessage.ValueBody.Value as AmqpMap;
 27            }
 028        }
 29
 030        public AmqpMessage AmqpMessage { get; }
 31
 032        public AmqpResponseStatusCode StatusCode { get; }
 33
 034        public string TrackingId { get; }
 35
 036        public AmqpMap Map { get; }
 37
 38        public static AmqpResponseMessage CreateResponse(AmqpMessage response)
 39        {
 040            return new AmqpResponseMessage(response);
 41        }
 42
 43        public TValue GetValue<TValue>(MapKey key)
 44        {
 045            if (Map == null)
 46            {
 047                throw new ArgumentException(AmqpValue.Name);
 48            }
 49
 050            var valueObject = Map[key];
 051            if (valueObject == null)
 52            {
 053                throw new ArgumentException(key.ToString());
 54            }
 55
 056            if (!(valueObject is TValue))
 57            {
 058                throw new ArgumentException(key.ToString());
 59            }
 60
 061            return (TValue)Map[key];
 62        }
 63
 64        public IEnumerable<TValue> GetListValue<TValue>(MapKey key)
 65        {
 066            if (Map == null)
 67            {
 068                throw new ArgumentException(AmqpValue.Name);
 69            }
 70
 071            var list = (List<object>)Map[key];
 72
 073            return list.Cast<TValue>();
 74        }
 75
 76        public AmqpSymbol GetResponseErrorCondition()
 77        {
 078            var condition = AmqpMessage.ApplicationProperties.Map[ManagementConstants.Response.ErrorCondition];
 79
 080            return condition is AmqpSymbol amqpSymbol ? amqpSymbol : null;
 81        }
 82
 83        public Exception ToMessagingContractException()
 84        {
 085            return AmqpMessage.ToMessagingContractException(StatusCode);
 86        }
 87    }
 88}