< Summary

Class:Azure.Messaging.ServiceBus.Management.CorrelationRuleFilter
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\CorrelationRuleFilter.cs
Covered lines:49
Uncovered lines:39
Coverable lines:88
Total lines:300
Line coverage:55.6% (49 of 88)
Covered branches:17
Total branches:54
Branch coverage:31.4% (17 of 54)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
.ctor(...)-100%100%
Clone()-100%100%
get_CorrelationId()-100%100%
set_CorrelationId(...)-100%100%
get_MessageId()-100%100%
set_MessageId(...)-100%100%
get_To()-100%100%
set_To(...)-100%100%
get_ReplyTo()-100%100%
set_ReplyTo(...)-100%100%
get_Label()-100%100%
set_Label(...)-100%100%
get_SessionId()-100%100%
set_SessionId(...)-100%100%
get_ReplyToSessionId()-100%100%
set_ReplyToSessionId(...)-100%100%
get_ContentType()-100%100%
set_ContentType(...)-100%100%
get_Properties()-100%100%
ToString()-0%0%
AppendPropertyExpression(...)-0%0%
GetHashCode()-0%0%
Equals(...)-0%100%
Equals(...)-78.95%56.67%
op_Equality(...)-0%0%
op_Inequality(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\CorrelationRuleFilter.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.Globalization;
 7using System.Text;
 8using Azure.Core;
 9using Azure.Messaging.ServiceBus.Primitives;
 10
 11namespace Azure.Messaging.ServiceBus.Management
 12{
 13    /// <summary>
 14    /// Represents the correlation rule filter expression.
 15    /// </summary>
 16    /// <remarks>
 17    /// <para>
 18    /// A CorrelationRuleFilter holds a set of conditions that are matched against one of more of an arriving message's 
 19    /// A common use is a match against the <see cref="ServiceBusMessage.CorrelationId"/> property, but the application 
 20    /// <see cref="ServiceBusMessage.ContentType"/>, <see cref="ServiceBusMessage.Label"/>, <see cref="ServiceBusMessage
 21    /// <see cref="ServiceBusMessage.ReplyToSessionId"/>, <see cref="ServiceBusMessage.SessionId"/>, <see cref="ServiceB
 22    /// A match exists when an arriving message's value for a property is equal to the value specified in the correlatio
 23    /// the comparison is case-sensitive. When specifying multiple match properties, the filter combines them as a logic
 24    /// meaning all conditions must match for the filter to match.
 25    /// </para>
 26    /// <para>
 27    /// The CorrelationRuleFilter provides an efficient shortcut for declarations of filters that deal only with correla
 28    /// In this case the cost of the lexigraphical analysis of the expression can be avoided.
 29    /// Not only will correlation filters be optimized at declaration time, but they will also be optimized at runtime.
 30    /// Correlation filter matching can be reduced to a hashtable lookup, which aggregates the complexity of the set of 
 31    /// </para>
 32    /// </remarks>
 33    public sealed class CorrelationRuleFilter : RuleFilter
 34    {
 35        /// <summary>
 36        /// Initializes a new instance of the <see cref="CorrelationRuleFilter" /> class with default values.
 37        /// </summary>
 3638        public CorrelationRuleFilter()
 39        {
 3640        }
 41
 42        /// <summary>
 43        /// Initializes a new instance of the <see cref="CorrelationRuleFilter" /> class with the specified correlation 
 44        /// </summary>
 45        /// <param name="correlationId">The identifier for the correlation.</param>
 46        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="correlationId" /> is null or empt
 47        public CorrelationRuleFilter(string correlationId)
 848            : this()
 49        {
 850            Argument.AssertNotNullOrWhiteSpace(correlationId, nameof(correlationId));
 851            CorrelationId = correlationId;
 852        }
 53
 54        internal override RuleFilter Clone() =>
 855            new CorrelationRuleFilter(CorrelationId)
 856            {
 857                MessageId = MessageId,
 858                To = To,
 859                ReplyTo = ReplyTo,
 860                Label = Label,
 861                SessionId = SessionId,
 862                ReplyToSessionId = ReplyToSessionId,
 863                ContentType = ContentType,
 864                Properties = (Properties as PropertyDictionary).Clone()
 865            };
 66
 67        /// <summary>
 68        /// Identifier of the correlation.
 69        /// </summary>
 70        /// <value>The identifier of the correlation.</value>
 71        public string CorrelationId
 72        {
 6073            get;
 3274            set;
 75        }
 76
 77        /// <summary>
 78        /// Identifier of the message.
 79        /// </summary>
 80        /// <value>The identifier of the message.</value>
 81        /// <remarks>Max MessageId size is 128 chars.</remarks>
 82        public string MessageId
 83        {
 6084            get;
 2885            set;
 86        }
 87
 88        /// <summary>
 89        /// Address to send to.
 90        /// </summary>
 91        /// <value>The address to send to.</value>
 92        public string To
 93        {
 6094            get;
 2895            set;
 96        }
 97
 98        /// <summary>
 99        /// Address of the queue to reply to.
 100        /// </summary>
 101        /// <value>The address of the queue to reply to.</value>
 102        public string ReplyTo
 103        {
 60104            get;
 28105            set;
 106        }
 107
 108        /// <summary>
 109        /// Application specific label.
 110        /// </summary>
 111        /// <value>The application specific label.</value>
 112        public string Label
 113        {
 60114            get;
 28115            set;
 116        }
 117
 118        /// <summary>
 119        /// Session identifier.
 120        /// </summary>
 121        /// <value>The session identifier.</value>
 122        /// <remarks>Max size of sessionId is 128 chars.</remarks>
 123        public string SessionId
 124        {
 60125            get;
 28126            set;
 127        }
 128
 129        /// <summary>
 130        /// Session identifier to reply to.
 131        /// </summary>
 132        /// <value>The session identifier to reply to.</value>
 133        /// <remarks>Max size of ReplyToSessionId is 128.</remarks>
 134        public string ReplyToSessionId
 135        {
 60136            get;
 28137            set;
 138        }
 139
 140        /// <summary>
 141        /// Content type of the message.
 142        /// </summary>
 143        /// <value>The content type of the message.</value>
 144        public string ContentType
 145        {
 60146            get;
 28147            set;
 148        }
 149
 150        /// <summary>
 151        /// Application specific properties of the message.
 152        /// </summary>
 153        /// <value>The application specific properties of the message.</value>
 154        /// <remarks>
 155        /// Only following value types are supported:
 156        /// byte, sbyte, char, short, ushort, int, uint, long, ulong, float, double, decimal,
 157        /// bool, Guid, string, Uri, DateTime, DateTimeOffset, TimeSpan, Stream, byte[],
 158        /// and IList / IDictionary of supported types
 159        /// </remarks>
 184160        public IDictionary<string, object> Properties { get; internal set; } = new PropertyDictionary();
 161
 162        /// <summary>
 163        /// Converts the value of the current instance to its equivalent string representation.
 164        /// </summary>
 165        /// <returns>A string representation of the current instance.</returns>
 166        public override string ToString()
 167        {
 0168            var stringBuilder = new StringBuilder();
 169
 0170            stringBuilder.Append("CorrelationRuleFilter: ");
 171
 0172            var isFirstExpression = true;
 173
 0174            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.CorrelationId", CorrelationId);
 0175            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.MessageId", MessageId);
 0176            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.To", To);
 0177            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.ReplyTo", ReplyTo);
 0178            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.Label", Label);
 0179            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.SessionId", SessionId);
 0180            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.ReplyToSessionId", ReplyToSessionId);
 0181            AppendPropertyExpression(ref isFirstExpression, stringBuilder, "sys.ContentType", ContentType);
 182
 0183            foreach (var pair in Properties)
 184            {
 0185                string propertyName = pair.Key;
 0186                object propertyValue = pair.Value;
 187
 0188                AppendPropertyExpression(ref isFirstExpression, stringBuilder, propertyName, propertyValue);
 189            }
 190
 0191            return stringBuilder.ToString();
 192        }
 193
 194        private static void AppendPropertyExpression(ref bool firstExpression, StringBuilder builder, string propertyNam
 195        {
 0196            if (value != null)
 197            {
 0198                if (firstExpression)
 199                {
 0200                    firstExpression = false;
 201                }
 202                else
 203                {
 0204                    builder.Append(" AND ");
 205                }
 206
 0207                builder.AppendFormat(CultureInfo.InvariantCulture, "{0} = '{1}'", propertyName, value);
 208            }
 0209        }
 210
 211        /// <inheritdoc/>
 212        public override int GetHashCode()
 213        {
 0214            int hash = 13;
 215            unchecked
 216            {
 0217                hash = (hash * 7) + CorrelationId?.GetHashCode() ?? 0;
 0218                hash = (hash * 7) + MessageId?.GetHashCode() ?? 0;
 0219                hash = (hash * 7) + SessionId?.GetHashCode() ?? 0;
 220            }
 221
 0222            return hash;
 223        }
 224
 225        /// <inheritdoc/>
 226        public override bool Equals(object obj)
 227        {
 0228            var other = obj as CorrelationRuleFilter;
 0229            return Equals(other);
 230        }
 231
 232        /// <inheritdoc/>
 233        public override bool Equals(RuleFilter other)
 234        {
 16235            if (other is CorrelationRuleFilter correlationRuleFilter)
 236            {
 16237                if (string.Equals(CorrelationId, correlationRuleFilter.CorrelationId, StringComparison.OrdinalIgnoreCase
 16238                    && string.Equals(MessageId, correlationRuleFilter.MessageId, StringComparison.OrdinalIgnoreCase)
 16239                    && string.Equals(To, correlationRuleFilter.To, StringComparison.OrdinalIgnoreCase)
 16240                    && string.Equals(ReplyTo, correlationRuleFilter.ReplyTo, StringComparison.OrdinalIgnoreCase)
 16241                    && string.Equals(Label, correlationRuleFilter.Label, StringComparison.OrdinalIgnoreCase)
 16242                    && string.Equals(SessionId, correlationRuleFilter.SessionId, StringComparison.OrdinalIgnoreCase)
 16243                    && string.Equals(ReplyToSessionId, correlationRuleFilter.ReplyToSessionId, StringComparison.OrdinalI
 16244                    && string.Equals(ContentType, correlationRuleFilter.ContentType, StringComparison.OrdinalIgnoreCase)
 245                {
 16246                    if (Properties.Count != correlationRuleFilter.Properties.Count)
 247                    {
 0248                        return false;
 249                    }
 250
 80251                    foreach (var param in Properties)
 252                    {
 24253                        if (!correlationRuleFilter.Properties.TryGetValue(param.Key, out var otherParamValue) ||
 24254                            (param.Value == null ^ otherParamValue == null) ||
 24255                            (param.Value != null && !param.Value.Equals(otherParamValue)))
 256                        {
 0257                            return false;
 258                        }
 259                    }
 260
 16261                    return true;
 262                }
 263            }
 264
 0265            return false;
 0266        }
 267
 268        /// <summary>
 269        ///
 270        /// </summary>
 271        /// <param name="left"></param>
 272        /// <param name="right"></param>
 273        /// <returns></returns>
 274        public static bool operator ==(CorrelationRuleFilter left, CorrelationRuleFilter right)
 275        {
 0276            if (ReferenceEquals(left, right))
 277            {
 0278                return true;
 279            }
 280
 0281            if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
 282            {
 0283                return false;
 284            }
 285
 0286            return left.Equals(right);
 287        }
 288
 289        /// <summary>
 290        ///
 291        /// </summary>
 292        /// <param name="left"></param>
 293        /// <param name="right"></param>
 294        /// <returns></returns>
 295        public static bool operator !=(CorrelationRuleFilter left, CorrelationRuleFilter right)
 296        {
 0297            return !(left == right);
 298        }
 299    }
 300}