< Summary

Class:Azure.Messaging.ServiceBus.Management.CreateTopicOptions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\CreateTopicOptions.cs
Covered lines:76
Uncovered lines:11
Coverable lines:87
Total lines:256
Line coverage:87.3% (76 of 87)
Covered branches:21
Total branches:46
Branch coverage:45.6% (21 of 46)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
.ctor(...)-100%100%
get_DefaultMessageTimeToLive()-100%100%
set_DefaultMessageTimeToLive(...)-100%100%
get_AutoDeleteOnIdle()-100%100%
set_AutoDeleteOnIdle(...)-100%100%
get_MaxSizeInMegabytes()-100%100%
get_RequiresDuplicateDetection()-100%100%
get_DuplicateDetectionHistoryTimeWindow()-100%100%
set_DuplicateDetectionHistoryTimeWindow(...)-100%100%
get_Name()-100%100%
set_Name(...)-100%100%
get_AuthorizationRules()-100%100%
get_Status()-100%100%
get_EnablePartitioning()-100%100%
get_SupportOrdering()-0%100%
get_EnableBatchedOperations()-100%100%
get_UserMetadata()-100%100%
set_UserMetadata(...)-100%100%
GetHashCode()-0%0%
Equals(...)-0%100%
Equals(...)-93.75%52.78%
op_Equality(...)-0%0%
op_Inequality(...)-0%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure.Core;
 6
 7namespace Azure.Messaging.ServiceBus.Management
 8{
 9    /// <summary>
 10    /// Represents the options that can be specified for the creation of a topic.
 11    /// </summary>
 12    public class CreateTopicOptions : IEquatable<CreateTopicOptions>
 13    {
 4814        private TimeSpan _duplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1);
 15        private string _name;
 4816        private TimeSpan _defaultMessageTimeToLive = TimeSpan.MaxValue;
 4817        private TimeSpan _autoDeleteOnIdle = TimeSpan.MaxValue;
 18        private string _userMetadata = null;
 19
 20        /// <summary>
 21        /// Initializes a new instance of <see cref="CreateTopicOptions"/> with the specified relative name.
 22        /// </summary>
 23        /// <param name="name">Name of the topic relative to the namespace base address.</param>
 4024        public CreateTopicOptions(string name)
 25        {
 4026            Name = name;
 4027        }
 28
 29        /// <summary>
 30        /// Initializes a new instance of <see cref="CreateTopicOptions"/> based on the
 31        /// specified <see cref="TopicProperties"/> instance. This is useful for creating a new topic based
 32        /// on the properties of an existing topic.
 33        /// </summary>
 34        /// <param name="topic">Existing topic to create options from.</param>
 835        public CreateTopicOptions(TopicProperties topic)
 36        {
 837            Name = topic.Name;
 838            MaxSizeInMegabytes = topic.MaxSizeInMegabytes;
 839            RequiresDuplicateDetection = topic.RequiresDuplicateDetection;
 840            DefaultMessageTimeToLive = topic.DefaultMessageTimeToLive;
 841            AutoDeleteOnIdle = topic.AutoDeleteOnIdle;
 842            DuplicateDetectionHistoryTimeWindow = topic.DuplicateDetectionHistoryTimeWindow;
 843            EnableBatchedOperations = topic.EnableBatchedOperations;
 844            AuthorizationRules = topic.AuthorizationRules.Clone();
 845            Status = topic.Status;
 846            EnablePartitioning = topic.EnablePartitioning;
 847            if (topic.UserMetadata != null)
 48            {
 449                UserMetadata = topic.UserMetadata;
 50            }
 851        }
 52
 53        /// <summary>
 54        /// The default time to live value for the messages. This is the duration after which the message expires,
 55        /// starting from when the message is sent to Service Bus. </summary>
 56        /// <remarks>
 57        /// This is the default value used when <see cref="ServiceBusMessage.TimeToLive"/> is not set on a
 58        /// message itself. Messages older than their TimeToLive value will expire and no longer be retained
 59        /// in the message store.
 60        /// Subscribers will be unable to receive expired messages.
 61        /// Default value is <see cref="TimeSpan.MaxValue"/>.
 62        /// </remarks>
 63        public TimeSpan DefaultMessageTimeToLive
 64        {
 5665            get => _defaultMessageTimeToLive;
 66            set
 67            {
 1268                Argument.AssertInRange(
 1269                    value,
 1270                    ManagementClientConstants.MinimumAllowedTimeToLive,
 1271                    ManagementClientConstants.MaximumAllowedTimeToLive,
 1272                    nameof(DefaultMessageTimeToLive));
 73
 1274                _defaultMessageTimeToLive = value;
 1275            }
 76        }
 77
 78        /// <summary>
 79        /// The <see cref="TimeSpan"/> idle interval after which the topic is automatically deleted.
 80        /// </summary>
 81        /// <remarks>The minimum duration is 5 minutes. Default value is <see cref="TimeSpan.MaxValue"/>.</remarks>
 82        public TimeSpan AutoDeleteOnIdle
 83        {
 5684            get => _autoDeleteOnIdle;
 85            set
 86            {
 1287                Argument.AssertAtLeast(
 1288                    value,
 1289                    ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle,
 1290                    nameof(AutoDeleteOnIdle));
 91
 1292                _autoDeleteOnIdle = value;
 1293            }
 94        }
 95
 96        /// <summary>
 97        /// The maximum size of the topic in megabytes, which is the size of memory allocated for the topic.
 98        /// </summary>
 99        /// <remarks>Default value is 1024.</remarks>
 116100        public long MaxSizeInMegabytes { get; set; } = 1024;
 101
 102        /// <summary>
 103        /// This value indicates if the topic requires guard against duplicate messages. If true, duplicate messages hav
 104        /// <see cref="ServiceBusMessage.MessageId"/> and sent to topic within duration of <see cref="DuplicateDetection
 105        /// will be discarded.
 106        /// </summary>
 107        /// <remarks>Defaults to false.</remarks>
 76108        public bool RequiresDuplicateDetection { get; set; } = false;
 109
 110        /// <summary>
 111        /// The <see cref="TimeSpan"/> duration of duplicate detection history that is maintained by the service.
 112        /// </summary>
 113        /// <remarks>
 114        /// The default value is 1 minute. Max value is 7 days and minimum is 20 seconds.
 115        /// </remarks>
 116        public TimeSpan DuplicateDetectionHistoryTimeWindow
 117        {
 48118            get => _duplicateDetectionHistoryTimeWindow;
 119            set
 120            {
 12121                Argument.AssertInRange(
 12122                    value,
 12123                    ManagementClientConstants.MinimumDuplicateDetectionHistoryTimeWindow,
 12124                    ManagementClientConstants.MaximumDuplicateDetectionHistoryTimeWindow,
 12125                    nameof(DuplicateDetectionHistoryTimeWindow));
 126
 12127                _duplicateDetectionHistoryTimeWindow = value;
 12128            }
 129        }
 130
 131        /// <summary>
 132        /// Name of the topic relative to the namespace base address.
 133        /// </summary>
 134        /// <remarks>Max length is 260 chars. Cannot start or end with a slash.
 135        /// Cannot have restricted characters: '@','?','#','*'</remarks>
 136        public string Name
 137        {
 64138            get => _name;
 139            set
 140            {
 48141                EntityNameFormatter.CheckValidTopicName(value, nameof(Name));
 48142                _name = value;
 48143            }
 144        }
 145
 146        /// <summary>
 147        /// The <see cref="AuthorizationRules"/> on the topic to control user access at entity level.
 148        /// </summary>
 148149        public AuthorizationRules AuthorizationRules { get; internal set; } = new AuthorizationRules();
 150
 151        /// <summary>
 152        /// The current status of the topic (Enabled / Disabled).
 153        /// </summary>
 154        /// <remarks>When an entity is disabled, that entity cannot send or receive messages.</remarks>
 112155        public EntityStatus Status { get; set; } = EntityStatus.Active;
 156
 157        /// <summary>
 158        /// Indicates whether the topic is to be partitioned across multiple message brokers.
 159        /// </summary>
 160        /// <remarks>Defaults to false.</remarks>
 28161        public bool EnablePartitioning { get; set; } = false;
 162
 163        /// <summary>
 164        /// Defines whether ordering needs to be maintained. If true, messages sent to topic will be
 165        /// forwarded to the subscription in order.
 166        /// </summary>
 167        /// <remarks>Defaults to false.</remarks>
 0168        public bool SupportOrdering { get; set; } = false;
 169
 170        /// <summary>
 171        /// Indicates whether server-side batched operations are enabled.
 172        /// </summary>
 173        /// <remarks>Defaults to true.</remarks>
 156174        public bool EnableBatchedOperations { get; set; } = true;
 175
 176        /// <summary>
 177        /// Custom metdata that user can associate with the topic.
 178        /// </summary>
 179        /// <remarks>Cannot be null. Max length is 1024 chars.</remarks>
 180        public string UserMetadata
 181        {
 44182            get => _userMetadata;
 183            set
 184            {
 8185                Argument.AssertNotNull(value, nameof(UserMetadata));
 8186                Argument.AssertNotTooLong(
 8187                    value,
 8188                    ManagementClientConstants.MaxUserMetadataLength,
 8189                    nameof(UserMetadata));
 190
 8191                _userMetadata = value;
 8192            }
 193        }
 194
 195        /// <summary>
 196        ///   Returns a hash code for this instance.
 197        /// </summary>
 198        public override int GetHashCode()
 199        {
 0200            return Name?.GetHashCode() ?? base.GetHashCode();
 201        }
 202
 203        /// <summary>Determines whether the specified object is equal to the current object.</summary>
 204        public override bool Equals(object obj)
 205        {
 0206            var other = obj as TopicProperties;
 0207            return Equals(other);
 208        }
 209
 210        /// <summary>Determines whether the specified object is equal to the current object.</summary>
 211        public bool Equals(CreateTopicOptions other)
 212        {
 8213            if (other is CreateTopicOptions otherOptions
 8214                && Name.Equals(otherOptions.Name, StringComparison.OrdinalIgnoreCase)
 8215                && AutoDeleteOnIdle.Equals(otherOptions.AutoDeleteOnIdle)
 8216                && DefaultMessageTimeToLive.Equals(otherOptions.DefaultMessageTimeToLive)
 8217                && (!RequiresDuplicateDetection || DuplicateDetectionHistoryTimeWindow.Equals(otherOptions.DuplicateDete
 8218                && EnableBatchedOperations == otherOptions.EnableBatchedOperations
 8219                && EnablePartitioning == otherOptions.EnablePartitioning
 8220                && MaxSizeInMegabytes == otherOptions.MaxSizeInMegabytes
 8221                && RequiresDuplicateDetection.Equals(otherOptions.RequiresDuplicateDetection)
 8222                && Status.Equals(otherOptions.Status)
 8223                && string.Equals(_userMetadata, otherOptions._userMetadata, StringComparison.OrdinalIgnoreCase)
 8224                && (AuthorizationRules != null && otherOptions.AuthorizationRules != null
 8225                    || AuthorizationRules == null && otherOptions.AuthorizationRules == null)
 8226                && (AuthorizationRules == null || AuthorizationRules.Equals(otherOptions.AuthorizationRules)))
 227            {
 8228                return true;
 229            }
 230
 0231            return false;
 232        }
 233
 234        /// <summary></summary>
 235        public static bool operator ==(CreateTopicOptions left, CreateTopicOptions right)
 236        {
 0237            if (ReferenceEquals(left, right))
 238            {
 0239                return true;
 240            }
 241
 0242            if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
 243            {
 0244                return false;
 245            }
 246
 0247            return left.Equals(right);
 248        }
 249
 250        /// <summary></summary>
 251        public static bool operator !=(CreateTopicOptions left, CreateTopicOptions right)
 252        {
 0253            return !(left == right);
 254        }
 255    }
 256}