< Summary

Class:Azure.Messaging.ServiceBus.Management.SubscriptionProperties
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\SubscriptionProperties.cs
Covered lines:106
Uncovered lines:15
Coverable lines:121
Total lines:354
Line coverage:87.6% (106 of 121)
Covered branches:23
Total branches:54
Branch coverage:42.5% (23 of 54)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
.ctor(...)-100%100%
get_LockDuration()-100%100%
set_LockDuration(...)-100%100%
get_RequiresSession()-100%100%
get_DefaultMessageTimeToLive()-100%100%
set_DefaultMessageTimeToLive(...)-100%100%
get_AutoDeleteOnIdle()-100%100%
set_AutoDeleteOnIdle(...)-100%100%
get_DeadLetteringOnMessageExpiration()-100%100%
get_EnableDeadLetteringOnFilterEvaluationExceptions()-100%100%
get_TopicName()-100%100%
set_TopicName(...)-100%100%
get_SubscriptionName()-100%100%
set_SubscriptionName(...)-100%100%
get_MaxDeliveryCount()-100%100%
set_MaxDeliveryCount(...)-100%100%
get_Status()-100%100%
get_ForwardTo()-100%100%
set_ForwardTo(...)-87.5%75%
get_ForwardDeadLetteredMessagesTo()-100%100%
set_ForwardDeadLetteredMessagesTo(...)-87.5%75%
get_EnableBatchedOperations()-100%100%
get_UserMetadata()-100%100%
set_UserMetadata(...)-100%100%
get_UnknownProperties()-100%100%
get_Rule()-100%100%
GetHashCode()-0%0%
Equals(...)-0%100%
Equals(...)-94.12%50%
op_Equality(...)-0%0%
op_Inequality(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\SubscriptionProperties.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 Azure.Core;
 7
 8namespace Azure.Messaging.ServiceBus.Management
 9{
 10    /// <summary>
 11    /// Represents the static properties of the subscription.
 12    /// </summary>
 13    public class SubscriptionProperties : IEquatable<SubscriptionProperties>
 14    {
 15        private string _topicName, _subscriptionName;
 9616        private TimeSpan _lockDuration = TimeSpan.FromSeconds(60);
 9617        private TimeSpan _defaultMessageTimeToLive = TimeSpan.MaxValue;
 9618        private TimeSpan _autoDeleteOnIdle = TimeSpan.MaxValue;
 9619        private int _maxDeliveryCount = 10;
 20        private string _forwardTo = null;
 21        private string _forwardDeadLetteredMessagesTo = null;
 22        private string _userMetadata = null;
 23
 24        /// <summary>
 25        /// Initializes a new instance of SubscriptionDescription class with the specified name and topic name.
 26        /// </summary>
 27        /// <param name="topicName">Name of the topic relative to the namespace base address.</param>
 28        /// <param name="subscriptionName">Name of the subscription.</param>
 6829        public SubscriptionProperties(string topicName, string subscriptionName)
 30        {
 6831            TopicName = topicName;
 6832            SubscriptionName = subscriptionName;
 6833        }
 34
 2835        internal SubscriptionProperties(CreateSubscriptionOptions options)
 36        {
 2837            TopicName = options.TopicName;
 2838            SubscriptionName = options.SubscriptionName;
 2839            LockDuration = options.LockDuration;
 2840            RequiresSession = options.RequiresSession;
 2841            DefaultMessageTimeToLive = options.DefaultMessageTimeToLive;
 2842            AutoDeleteOnIdle = options.AutoDeleteOnIdle;
 2843            DeadLetteringOnMessageExpiration = options.DeadLetteringOnMessageExpiration;
 2844            EnableDeadLetteringOnFilterEvaluationExceptions = options.EnableDeadLetteringOnFilterEvaluationExceptions;
 2845            MaxDeliveryCount = options.MaxDeliveryCount;
 2846            EnableBatchedOperations = options.EnableBatchedOperations;
 2847            Status = options.Status;
 2848            ForwardTo = options.ForwardTo;
 2849            ForwardDeadLetteredMessagesTo = options.ForwardDeadLetteredMessagesTo;
 2850            if (options.UserMetadata != null)
 51            {
 452                UserMetadata = options.UserMetadata;
 53            }
 2854        }
 55
 56        /// <summary>
 57        /// Duration of a peek lock receive. i.e., the amount of time that the message is locked by a given receiver so 
 58        /// no other receiver receives the same message.
 59        /// </summary>
 60        /// <remarks>Max value is 5 minutes. Default value is 60 seconds.</remarks>
 61        public TimeSpan LockDuration
 62        {
 5263            get => _lockDuration;
 64            set
 65            {
 7266                Argument.AssertPositive(value, nameof(LockDuration));
 7267                _lockDuration = value;
 7268            }
 69        }
 70
 71        /// <summary>
 72        /// This indicates whether the subscription supports the concept of session. Sessionful-messages follow FIFO ord
 73        /// </summary>
 74        /// <remarks>
 75        /// If true, the receiver can only receive messages using <see cref="ServiceBusSessionProcessor"/>.
 76        /// Defaults to false.
 77        /// </remarks>
 12478        public bool RequiresSession { get; set; } = false;
 79
 80        /// <summary>
 81        /// The default time to live value for the messages. This is the duration after which the message expires, start
 82        /// the message is sent to Service Bus. </summary>
 83        /// <remarks>
 84        /// This is the default value used when <see cref="ServiceBusMessage.TimeToLive"/> is not set on a
 85        ///  message itself. Messages older than their TimeToLive value will expire and no longer be retained in the mes
 86        ///  Subscribers will be unable to receive expired messages.
 87        ///  Default value is <see cref="TimeSpan.MaxValue"/>.
 88        ///  </remarks>
 89        public TimeSpan DefaultMessageTimeToLive
 90        {
 6091            get => _defaultMessageTimeToLive;
 92            set
 93            {
 7694                Argument.AssertInRange(
 7695                    value,
 7696                    ManagementClientConstants.MinimumAllowedTimeToLive,
 7697                    ManagementClientConstants.MaximumAllowedTimeToLive,
 7698                    nameof(DefaultMessageTimeToLive));
 99
 76100                _defaultMessageTimeToLive = value;
 76101            }
 102        }
 103
 104        /// <summary>
 105        /// The <see cref="TimeSpan"/> idle interval after which the subscription is automatically deleted.
 106        /// </summary>
 107        /// <remarks>The minimum duration is 5 minutes. Default value is <see cref="TimeSpan.MaxValue"/>.</remarks>
 108        public TimeSpan AutoDeleteOnIdle
 109        {
 60110            get => _autoDeleteOnIdle;
 111            set
 112            {
 72113                Argument.AssertAtLeast(
 72114                    value,
 72115                    ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle,
 72116                    nameof(AutoDeleteOnIdle));
 117
 72118                _autoDeleteOnIdle = value;
 72119            }
 120        }
 121
 122        /// <summary>
 123        /// Indicates whether this subscription has dead letter support when a message expires.
 124        /// </summary>
 125        /// <remarks>If true, the expired messages are moved to dead-letter sub-queue. Default value is false.</remarks>
 124126        public bool DeadLetteringOnMessageExpiration { get; set; } = false;
 127
 128        /// <summary>
 129        /// indicates whether messages need to be forwarded to dead-letter sub queue when subscription rule evaluation f
 130        /// </summary>
 131        /// <remarks>Defaults to true.</remarks>
 220132        public bool EnableDeadLetteringOnFilterEvaluationExceptions { get; set; } = true;
 133
 134        /// <summary>
 135        /// Name of the topic under which subscription exists.
 136        /// </summary>
 137        /// <remarks>Value cannot be null or empty. Value cannot exceed 260 chars. Cannot start or end with a slash.
 138        /// Cannot have restricted characters: '@','?','#','*'</remarks>
 139        public string TopicName
 140        {
 88141            get => _topicName;
 142            set
 143            {
 96144                EntityNameFormatter.CheckValidTopicName(value, nameof(TopicName));
 96145                _topicName = value;
 96146            }
 147        }
 148
 149        /// <summary>
 150        /// Name of the subscription.
 151        /// </summary>
 152        /// <remarks>Value cannot be null or empty. Value cannot exceed 50 chars.
 153        /// Cannot have restricted characters: '@','?','#','*','/','\'</remarks>
 154        public string SubscriptionName
 155        {
 56156            get => _subscriptionName;
 157            set
 158            {
 96159                EntityNameFormatter.CheckValidSubscriptionName(value, nameof(SubscriptionName));
 96160                _subscriptionName = value;
 96161            }
 162        }
 163
 164        /// <summary>
 165        /// The maximum delivery count of a message before it is dead-lettered.
 166        /// </summary>
 167        /// <remarks>The delivery count is increased when a message is received in <see cref="ReceiveMode.PeekLock"/> mo
 168        /// and didn't complete the message before the message lock expired.
 169        /// Default value is 10. Minimum value is 1.</remarks>
 170        public int MaxDeliveryCount
 171        {
 52172            get => _maxDeliveryCount;
 173            set
 174            {
 76175                Argument.AssertAtLeast(
 76176                    value,
 76177                    ManagementClientConstants.MinAllowedMaxDeliveryCount,
 76178                    nameof(AutoDeleteOnIdle));
 179
 76180                _maxDeliveryCount = value;
 76181            }
 182        }
 183
 184        /// <summary>
 185        /// The current status of the subscription (Enabled / Disabled).
 186        /// </summary>
 187        /// <remarks>When an entity is disabled, that entity cannot send or receive messages.</remarks>
 220188        public EntityStatus Status { get; set; } = EntityStatus.Active;
 189
 190        /// <summary>
 191        /// The name of the recipient entity to which all the messages sent to the subscription are forwarded to.
 192        /// </summary>
 193        /// <remarks>If set, user cannot manually receive messages from this subscription. The destination entity
 194        /// must be an already existing entity.</remarks>
 195        public string ForwardTo
 196        {
 130197            get => _forwardTo;
 198            set
 199            {
 38200                if (string.IsNullOrWhiteSpace(value))
 201                {
 28202                    _forwardTo = value;
 28203                    return;
 204                }
 205
 10206                EntityNameFormatter.CheckValidQueueName(value, nameof(ForwardTo));
 6207                if (_topicName.Equals(value, StringComparison.CurrentCultureIgnoreCase))
 208                {
 0209                    throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself");
 210                }
 211
 6212                _forwardTo = value;
 6213            }
 214        }
 215
 216        /// <summary>
 217        /// The name of the recipient entity to which all the dead-lettered messages of this subscription are forwarded 
 218        /// </summary>
 219        /// <remarks>If set, user cannot manually receive dead-lettered messages from this subscription. The destination
 220        /// entity must already exist.</remarks>
 221        public string ForwardDeadLetteredMessagesTo
 222        {
 130223            get => _forwardDeadLetteredMessagesTo;
 224            set
 225            {
 38226                if (string.IsNullOrWhiteSpace(value))
 227                {
 28228                    _forwardDeadLetteredMessagesTo = value;
 28229                    return;
 230                }
 231
 10232                EntityNameFormatter.CheckValidQueueName(value, nameof(ForwardDeadLetteredMessagesTo));
 6233                if (_topicName.Equals(value, StringComparison.CurrentCultureIgnoreCase))
 234                {
 0235                    throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself");
 236                }
 237
 6238                _forwardDeadLetteredMessagesTo = value;
 6239            }
 240        }
 241
 242        /// <summary>
 243        /// Indicates whether server-side batched operations are enabled.
 244        /// </summary>
 245        /// <remarks>Defaults to true.</remarks>
 220246        public bool EnableBatchedOperations { get; set; } = true;
 247
 248        /// <summary>
 249        /// Custom metdata that user can associate with the description.
 250        /// </summary>
 251        /// <remarks>Cannot be null. Max length is 1024 chars.</remarks>
 252        public string UserMetadata
 253        {
 60254            get => _userMetadata;
 255            set
 256            {
 24257                Argument.AssertNotNull(value, nameof(UserMetadata));
 24258                Argument.AssertNotTooLong(
 24259                    value,
 24260                    ManagementClientConstants.MaxUserMetadataLength,
 24261                    nameof(UserMetadata));
 262
 24263                _userMetadata = value;
 24264            }
 265        }
 266
 267        /// <summary>
 268        /// List of properties that were retrieved using GetSubscription but are not understood by this version of clien
 269        /// The list will be sent back when an already retrieved SubscriptionDescription will be used in UpdateSubscript
 270        /// </summary>
 172271        internal List<object> UnknownProperties { get; set; }
 272
 92273        internal RuleProperties Rule { get; set; }
 274
 275        /// <summary>
 276        ///   Returns a hash code for this instance.
 277        /// </summary>
 278        public override int GetHashCode()
 279        {
 0280            int hash = 7;
 281            unchecked
 282            {
 0283                hash = (hash * 7) + TopicName?.GetHashCode() ?? 0;
 0284                hash = (hash * 7) + SubscriptionName?.GetHashCode() ?? 0;
 285            }
 286
 0287            return hash;
 288        }
 289
 290        /// <summary>Determines whether the specified object is equal to the current object.</summary>
 291        public override bool Equals(object obj)
 292        {
 0293            var other = obj as SubscriptionProperties;
 0294            return Equals(other);
 295        }
 296
 297        /// <summary>Determines whether the specified object is equal to the current object.</summary>
 298        public bool Equals(SubscriptionProperties other)
 299        {
 4300            if (other is SubscriptionProperties otherDescription
 4301                && SubscriptionName.Equals(otherDescription.SubscriptionName, StringComparison.OrdinalIgnoreCase)
 4302                && TopicName.Equals(otherDescription.TopicName, StringComparison.OrdinalIgnoreCase)
 4303                && AutoDeleteOnIdle.Equals(otherDescription.AutoDeleteOnIdle)
 4304                && DefaultMessageTimeToLive.Equals(otherDescription.DefaultMessageTimeToLive)
 4305                && EnableBatchedOperations == otherDescription.EnableBatchedOperations
 4306                && DeadLetteringOnMessageExpiration == otherDescription.DeadLetteringOnMessageExpiration
 4307                && EnableDeadLetteringOnFilterEvaluationExceptions == otherDescription.EnableDeadLetteringOnFilterEvalua
 4308                && string.Equals(ForwardDeadLetteredMessagesTo, otherDescription.ForwardDeadLetteredMessagesTo, StringCo
 4309                && string.Equals(ForwardTo, otherDescription.ForwardTo, StringComparison.OrdinalIgnoreCase)
 4310                && LockDuration.Equals(otherDescription.LockDuration)
 4311                && MaxDeliveryCount == otherDescription.MaxDeliveryCount
 4312                && RequiresSession.Equals(otherDescription.RequiresSession)
 4313                && Status.Equals(otherDescription.Status)
 4314                && string.Equals(_userMetadata, otherDescription._userMetadata, StringComparison.OrdinalIgnoreCase))
 315            {
 4316                return true;
 317            }
 318
 0319            return false;
 320        }
 321
 322        /// <summary>
 323        ///
 324        /// </summary>
 325        /// <param name="left"></param>
 326        /// <param name="right"></param>
 327        /// <returns></returns>
 328        public static bool operator ==(SubscriptionProperties left, SubscriptionProperties right)
 329        {
 0330            if (ReferenceEquals(left, right))
 331            {
 0332                return true;
 333            }
 334
 0335            if (left is null || right is null)
 336            {
 0337                return false;
 338            }
 339
 0340            return left.Equals(right);
 341        }
 342
 343        /// <summary>
 344        ///
 345        /// </summary>
 346        /// <param name="left"></param>
 347        /// <param name="right"></param>
 348        /// <returns></returns>
 349        public static bool operator !=(SubscriptionProperties left, SubscriptionProperties right)
 350        {
 0351            return !(left == right);
 352        }
 353    }
 354}