< Summary

Class:Azure.Messaging.ServiceBus.Management.CreateSubscriptionOptions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\CreateSubscriptionOptions.cs
Covered lines:97
Uncovered lines:23
Coverable lines:120
Total lines:353
Line coverage:80.8% (97 of 120)
Covered branches:19
Total branches:54
Branch coverage:35.1% (19 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(...)-37.5%25%
get_ForwardDeadLetteredMessagesTo()-100%100%
set_ForwardDeadLetteredMessagesTo(...)-37.5%25%
get_EnableBatchedOperations()-100%100%
get_UserMetadata()-100%100%
set_UserMetadata(...)-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\CreateSubscriptionOptions.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 metadata description of the subscription.
 12    /// </summary>
 13    public class CreateSubscriptionOptions : IEquatable<CreateSubscriptionOptions>
 14    {
 15        private string _topicName, _subscriptionName;
 3616        private TimeSpan _lockDuration = TimeSpan.FromSeconds(60);
 3617        private TimeSpan _defaultMessageTimeToLive = TimeSpan.MaxValue;
 3618        private TimeSpan _autoDeleteOnIdle = TimeSpan.MaxValue;
 3619        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>
 2829        public CreateSubscriptionOptions(string topicName, string subscriptionName)
 30        {
 2831            TopicName = topicName;
 2832            SubscriptionName = subscriptionName;
 2833        }
 34
 35        /// <summary>
 36        /// Initializes a new instance of <see cref="CreateSubscriptionOptions"/> based on the
 37        /// specified <see cref="SubscriptionProperties"/> instance. This is useful for creating a new subscription base
 38        /// on the properties of an existing subscription.
 39        /// </summary>
 40        /// <param name="subscription">Existing subscription to create options from.</param>
 841        public CreateSubscriptionOptions(SubscriptionProperties subscription)
 42        {
 843            Argument.AssertNotNull(subscription, nameof(subscription));
 844            TopicName = subscription.TopicName;
 845            SubscriptionName = subscription.SubscriptionName;
 846            LockDuration = subscription.LockDuration;
 847            RequiresSession = subscription.RequiresSession;
 848            DefaultMessageTimeToLive = subscription.DefaultMessageTimeToLive;
 849            AutoDeleteOnIdle = subscription.AutoDeleteOnIdle;
 850            DeadLetteringOnMessageExpiration = subscription.DeadLetteringOnMessageExpiration;
 851            EnableDeadLetteringOnFilterEvaluationExceptions = subscription.EnableDeadLetteringOnFilterEvaluationExceptio
 852            MaxDeliveryCount = subscription.MaxDeliveryCount;
 853            EnableBatchedOperations = subscription.EnableBatchedOperations;
 854            Status = subscription.Status;
 855            ForwardTo = subscription.ForwardTo;
 856            ForwardDeadLetteredMessagesTo = subscription.ForwardDeadLetteredMessagesTo;
 857            if (subscription.UserMetadata != null)
 58            {
 859                UserMetadata = subscription.UserMetadata;
 60            }
 861        }
 62
 63        /// <summary>
 64        /// Duration of a peek lock receive. i.e., the amount of time that the message is locked by a given receiver so 
 65        /// no other receiver receives the same message.
 66        /// </summary>
 67        /// <remarks>Max value is 5 minutes. Default value is 60 seconds.</remarks>
 68        public TimeSpan LockDuration
 69        {
 4470            get => _lockDuration;
 71            set
 72            {
 1273                Argument.AssertPositive(value, nameof(LockDuration));
 1274                _lockDuration = value;
 1275            }
 76        }
 77
 78        /// <summary>
 79        /// This indicates whether the subscription supports the concept of session. Sessionful-messages follow FIFO ord
 80        /// </summary>
 81        /// <remarks>
 82        /// If true, the receiver can only receive messages using <see cref="ServiceBusSessionProcessor"/>.
 83        /// Defaults to false.
 84        /// </remarks>
 5685        public bool RequiresSession { get; set; } = false;
 86
 87        /// <summary>
 88        /// The default time to live value for the messages. This is the duration after which the message expires, start
 89        /// the message is sent to Service Bus. </summary>
 90        /// <remarks>
 91        /// This is the default value used when <see cref="ServiceBusMessage.TimeToLive"/> is not set on a
 92        ///  message itself. Messages older than their TimeToLive value will expire and no longer be retained in the mes
 93        ///  Subscribers will be unable to receive expired messages.
 94        ///  Default value is <see cref="TimeSpan.MaxValue"/>.
 95        ///  </remarks>
 96        public TimeSpan DefaultMessageTimeToLive
 97        {
 4498            get => _defaultMessageTimeToLive;
 99            set
 100            {
 12101                Argument.AssertInRange(
 12102                    value,
 12103                    ManagementClientConstants.MinimumAllowedTimeToLive,
 12104                    ManagementClientConstants.MaximumAllowedTimeToLive,
 12105                    nameof(DefaultMessageTimeToLive));
 106
 12107                _defaultMessageTimeToLive = value;
 12108            }
 109        }
 110
 111        /// <summary>
 112        /// The <see cref="TimeSpan"/> idle interval after which the subscription is automatically deleted.
 113        /// </summary>
 114        /// <remarks>The minimum duration is 5 minutes. Default value is <see cref="TimeSpan.MaxValue"/>.</remarks>
 115        public TimeSpan AutoDeleteOnIdle
 116        {
 44117            get => _autoDeleteOnIdle;
 118            set
 119            {
 12120                Argument.AssertAtLeast(
 12121                    value,
 12122                    ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle,
 12123                    nameof(AutoDeleteOnIdle));
 124
 12125                _autoDeleteOnIdle = value;
 12126            }
 127        }
 128
 129        /// <summary>
 130        /// Indicates whether this subscription has dead letter support when a message expires.
 131        /// </summary>
 132        /// <remarks>If true, the expired messages are moved to dead-letter sub-queue. Default value is false.</remarks>
 56133        public bool DeadLetteringOnMessageExpiration { get; set; } = false;
 134
 135        /// <summary>
 136        /// indicates whether messages need to be forwarded to dead-letter sub queue when subscription rule evaluation f
 137        /// </summary>
 138        /// <remarks>Defaults to true.</remarks>
 88139        public bool EnableDeadLetteringOnFilterEvaluationExceptions { get; set; } = true;
 140
 141        /// <summary>
 142        /// Name of the topic under which subscription exists.
 143        /// </summary>
 144        /// <remarks>Value cannot be null or empty. Value cannot exceed 260 chars. Cannot start or end with a slash.
 145        /// Cannot have restricted characters: '@','?','#','*'</remarks>
 146        public string TopicName
 147        {
 60148            get => _topicName;
 149            set
 150            {
 36151                EntityNameFormatter.CheckValidTopicName(value, nameof(TopicName));
 36152                _topicName = value;
 36153            }
 154        }
 155
 156        /// <summary>
 157        /// Name of the subscription.
 158        /// </summary>
 159        /// <remarks>Value cannot be null or empty. Value cannot exceed 50 chars.
 160        /// Cannot have restricted characters: '@','?','#','*','/','\'</remarks>
 161        public string SubscriptionName
 162        {
 56163            get => _subscriptionName;
 164            set
 165            {
 36166                EntityNameFormatter.CheckValidSubscriptionName(value, nameof(SubscriptionName));
 36167                _subscriptionName = value;
 36168            }
 169        }
 170
 171        /// <summary>
 172        /// The maximum delivery count of a message before it is dead-lettered.
 173        /// </summary>
 174        /// <remarks>The delivery count is increased when a message is received in <see cref="ReceiveMode.PeekLock"/> mo
 175        /// and didn't complete the message before the message lock expired.
 176        /// Default value is 10. Minimum value is 1.</remarks>
 177        public int MaxDeliveryCount
 178        {
 44179            get => _maxDeliveryCount;
 180            set
 181            {
 12182                Argument.AssertAtLeast(
 12183                    value,
 12184                    ManagementClientConstants.MinAllowedMaxDeliveryCount,
 12185                    nameof(AutoDeleteOnIdle));
 186
 12187                _maxDeliveryCount = value;
 12188            }
 189        }
 190
 191        /// <summary>
 192        /// The current status of the subscription (Enabled / Disabled).
 193        /// </summary>
 194        /// <remarks>When an entity is disabled, that entity cannot send or receive messages.</remarks>
 88195        public EntityStatus Status { get; set; } = EntityStatus.Active;
 196
 197        /// <summary>
 198        /// The name of the recipient entity to which all the messages sent to the subscription are forwarded to.
 199        /// </summary>
 200        /// <remarks>If set, user cannot manually receive messages from this subscription. The destination entity
 201        /// must be an already existing entity.</remarks>
 202        public string ForwardTo
 203        {
 44204            get => _forwardTo;
 205            set
 206            {
 12207                if (string.IsNullOrWhiteSpace(value))
 208                {
 12209                    _forwardTo = value;
 12210                    return;
 211                }
 212
 0213                EntityNameFormatter.CheckValidQueueName(value, nameof(ForwardTo));
 0214                if (_topicName.Equals(value, StringComparison.CurrentCultureIgnoreCase))
 215                {
 0216                    throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself");
 217                }
 218
 0219                _forwardTo = value;
 0220            }
 221        }
 222
 223        /// <summary>
 224        /// The name of the recipient entity to which all the dead-lettered messages of this subscription are forwarded 
 225        /// </summary>
 226        /// <remarks>If set, user cannot manually receive dead-lettered messages from this subscription. The destination
 227        /// entity must already exist.</remarks>
 228        public string ForwardDeadLetteredMessagesTo
 229        {
 44230            get => _forwardDeadLetteredMessagesTo;
 231            set
 232            {
 12233                if (string.IsNullOrWhiteSpace(value))
 234                {
 12235                    _forwardDeadLetteredMessagesTo = value;
 12236                    return;
 237                }
 238
 0239                EntityNameFormatter.CheckValidQueueName(value, nameof(ForwardDeadLetteredMessagesTo));
 0240                if (_topicName.Equals(value, StringComparison.CurrentCultureIgnoreCase))
 241                {
 0242                    throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself");
 243                }
 244
 0245                _forwardDeadLetteredMessagesTo = value;
 0246            }
 247        }
 248
 249        /// <summary>
 250        /// Indicates whether server-side batched operations are enabled.
 251        /// </summary>
 252        /// <remarks>Defaults to true.</remarks>
 92253        public bool EnableBatchedOperations { get; set; } = true;
 254
 255        /// <summary>
 256        /// Custom metadata that user can associate with the subscription.
 257        /// </summary>
 258        /// <remarks>Cannot be null. Max length is 1024 chars.</remarks>
 259        public string UserMetadata
 260        {
 32261            get => _userMetadata;
 262            set
 263            {
 12264                Argument.AssertNotNull(value, nameof(UserMetadata));
 12265                Argument.AssertNotTooLong(
 12266                    value,
 12267                    ManagementClientConstants.MaxUserMetadataLength,
 12268                    nameof(UserMetadata));
 269
 12270                _userMetadata = value;
 12271            }
 272        }
 273
 274        /// <summary>
 275        ///   Returns a hash code for this instance.
 276        /// </summary>
 277        public override int GetHashCode()
 278        {
 0279            int hash = 7;
 280            unchecked
 281            {
 0282                hash = (hash * 7) + TopicName?.GetHashCode() ?? 0;
 0283                hash = (hash * 7) + SubscriptionName?.GetHashCode() ?? 0;
 284            }
 285
 0286            return hash;
 287        }
 288
 289        /// <summary>Determines whether the specified object is equal to the current object.</summary>
 290        public override bool Equals(object obj)
 291        {
 0292            var other = obj as CreateSubscriptionOptions;
 0293            return Equals(other);
 294        }
 295
 296        /// <summary>Determines whether the specified object is equal to the current object.</summary>
 297        public bool Equals(CreateSubscriptionOptions other)
 298        {
 8299            if (other is CreateSubscriptionOptions otherOptions
 8300                && SubscriptionName.Equals(otherOptions.SubscriptionName, StringComparison.OrdinalIgnoreCase)
 8301                && TopicName.Equals(otherOptions.TopicName, StringComparison.OrdinalIgnoreCase)
 8302                && AutoDeleteOnIdle.Equals(otherOptions.AutoDeleteOnIdle)
 8303                && DefaultMessageTimeToLive.Equals(otherOptions.DefaultMessageTimeToLive)
 8304                && EnableBatchedOperations == otherOptions.EnableBatchedOperations
 8305                && DeadLetteringOnMessageExpiration == otherOptions.DeadLetteringOnMessageExpiration
 8306                && EnableDeadLetteringOnFilterEvaluationExceptions == otherOptions.EnableDeadLetteringOnFilterEvaluation
 8307                && string.Equals(ForwardDeadLetteredMessagesTo, otherOptions.ForwardDeadLetteredMessagesTo, StringCompar
 8308                && string.Equals(ForwardTo, otherOptions.ForwardTo, StringComparison.OrdinalIgnoreCase)
 8309                && LockDuration.Equals(otherOptions.LockDuration)
 8310                && MaxDeliveryCount == otherOptions.MaxDeliveryCount
 8311                && RequiresSession.Equals(otherOptions.RequiresSession)
 8312                && Status.Equals(otherOptions.Status)
 8313                && string.Equals(_userMetadata, otherOptions._userMetadata, StringComparison.OrdinalIgnoreCase))
 314            {
 8315                return true;
 316            }
 317
 0318            return false;
 319        }
 320
 321        /// <summary>
 322        ///
 323        /// </summary>
 324        /// <param name="left"></param>
 325        /// <param name="right"></param>
 326        /// <returns></returns>
 327        public static bool operator ==(CreateSubscriptionOptions left, CreateSubscriptionOptions right)
 328        {
 0329            if (ReferenceEquals(left, right))
 330            {
 0331                return true;
 332            }
 333
 0334            if (left is null || right is null)
 335            {
 0336                return false;
 337            }
 338
 0339            return left.Equals(right);
 340        }
 341
 342        /// <summary>
 343        ///
 344        /// </summary>
 345        /// <param name="left"></param>
 346        /// <param name="right"></param>
 347        /// <returns></returns>
 348        public static bool operator !=(CreateSubscriptionOptions left, CreateSubscriptionOptions right)
 349        {
 0350            return !(left == right);
 351        }
 352    }
 353}