< Summary

Class:Azure.Messaging.ServiceBus.Management.SqlRuleFilter
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\SqlRuleFilter.cs
Covered lines:19
Uncovered lines:14
Coverable lines:33
Total lines:140
Line coverage:57.5% (19 of 33)
Covered branches:10
Total branches:24
Branch coverage:41.6% (10 of 24)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
Clone()-100%100%
get_SqlExpression()-100%100%
get_Parameters()-100%100%
ToString()-0%100%
GetHashCode()-0%0%
Equals(...)-0%100%
Equals(...)-66.67%62.5%
op_Equality(...)-0%0%
op_Inequality(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\SqlRuleFilter.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 Azure.Core;
 8using Azure.Messaging.ServiceBus.Primitives;
 9
 10namespace Azure.Messaging.ServiceBus.Management
 11{
 12    /// <summary>
 13    /// Represents a filter which is a composition of an expression and an action that is executed in the pub/sub pipeli
 14    /// </summary>
 15    /// <remarks>
 16    /// A <see cref="SqlRuleFilter"/> holds a SQL-like condition expression that is evaluated in the broker against the 
 17    /// user-defined properties and system properties. All system properties (which are all properties explicitly listed
 18    /// on the <see cref="ServiceBusMessage"/> class) must be prefixed with <code>sys.</code> in the condition expressio
 19    /// testing for existence of properties (EXISTS), testing for null-values (IS NULL), logical NOT/AND/OR, relational 
 20    /// numeric arithmetic, and simple text pattern matching with LIKE.
 21    /// </remarks>
 22    public class SqlRuleFilter : RuleFilter
 23    {
 24
 25        /// <summary>
 26        /// Initializes a new instance of the <see cref="SqlRuleFilter" /> class using the specified SQL expression.
 27        /// </summary>
 28        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 6429        public SqlRuleFilter(string sqlExpression)
 30        {
 6431            Argument.AssertNotNullOrEmpty(sqlExpression, nameof(sqlExpression));
 6032            Argument.AssertNotTooLong(sqlExpression, Constants.MaximumSqlRuleFilterStatementLength, nameof(sqlExpression
 33
 5834            SqlExpression = sqlExpression;
 5835        }
 36
 37        internal override RuleFilter Clone() =>
 838            new SqlRuleFilter(SqlExpression)
 839            {
 840                Parameters = (Parameters as PropertyDictionary).Clone()
 841            };
 42
 43        /// <summary>
 44        /// Gets the SQL expression.
 45        /// </summary>
 46        /// <value>The SQL expression.</value>
 47        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 6848        public string SqlExpression { get; }
 49
 50        /// <summary>
 51        /// Sets the value of a filter expression.
 52        /// Allowed types: string, int, long, bool, double
 53        /// </summary>
 54        /// <value>The value of a filter expression.</value>
 38055        public IDictionary<string, object> Parameters { get; internal set; } = new PropertyDictionary();
 56
 57        /// <summary>
 58        /// Returns a string representation of <see cref="SqlRuleFilter" />.
 59        /// </summary>
 60        /// <returns>The string representation of <see cref="SqlRuleFilter" />.</returns>
 61        public override string ToString()
 62        {
 063            return string.Format(CultureInfo.InvariantCulture, "SqlRuleFilter: {0}", SqlExpression);
 64        }
 65
 66        /// <inheritdoc/>
 67        public override int GetHashCode()
 68        {
 069            return SqlExpression?.GetHashCode() ?? base.GetHashCode();
 70        }
 71
 72        /// <inheritdoc/>
 73        public override bool Equals(object obj)
 74        {
 075            var other = obj as RuleFilter;
 076            return Equals(other);
 77        }
 78
 79        /// <inheritdoc/>
 80        public override bool Equals(RuleFilter other)
 81        {
 1282            if (other is SqlRuleFilter sqlRuleFilter)
 83            {
 1284                if (string.Equals(SqlExpression, sqlRuleFilter.SqlExpression, StringComparison.OrdinalIgnoreCase))
 85                {
 1286                    if (Parameters.Count != sqlRuleFilter.Parameters.Count)
 87                    {
 088                        return false;
 89                    }
 90
 15291                    foreach (var param in Parameters)
 92                    {
 6493                        if (!sqlRuleFilter.Parameters.TryGetValue(param.Key, out var otherParamValue) ||
 6494                            (param.Value == null ^ otherParamValue == null) ||
 6495                            (param.Value != null && !param.Value.Equals(otherParamValue)))
 96                        {
 097                            return false;
 98                        }
 99                    }
 100
 12101                    return true;
 102                }
 103            }
 104
 0105            return false;
 0106        }
 107
 108        /// <summary>
 109        ///
 110        /// </summary>
 111        /// <param name="left"></param>
 112        /// <param name="right"></param>
 113        /// <returns></returns>
 114        public static bool operator ==(SqlRuleFilter left, SqlRuleFilter right)
 115        {
 0116            if (ReferenceEquals(left, right))
 117            {
 0118                return true;
 119            }
 120
 0121            if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
 122            {
 0123                return false;
 124            }
 125
 0126            return left.Equals(right);
 127        }
 128
 129        /// <summary>
 130        ///
 131        /// </summary>
 132        /// <param name="left"></param>
 133        /// <param name="right"></param>
 134        /// <returns></returns>
 135        public static bool operator !=(SqlRuleFilter left, SqlRuleFilter right)
 136        {
 0137            return !(left == right);
 138        }
 139    }
 140}