< Summary

Class:Microsoft.Azure.ServiceBus.SqlFilter
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Filters\SqlFilter.cs
Covered lines:0
Uncovered lines:38
Coverable lines:38
Total lines:135
Line coverage:0% (0 of 38)
Covered branches:0
Total branches:40
Branch coverage:0% (0 of 40)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Filters\SqlFilter.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Globalization;
 9    using Primitives;
 10
 11    /// <summary>
 12    /// Represents a filter which is a composition of an expression and an action that is executed in the pub/sub pipeli
 13    /// </summary>
 14    /// <remarks>
 15    /// A <see cref="SqlFilter"/> holds a SQL-like condition expression that is evaluated in the broker against the arri
 16    /// user-defined properties and system properties. All system properties (which are all properties explicitly listed
 17    /// on the <see cref="Message"/> class) must be prefixed with <code>sys.</code> in the condition expression. The SQL
 18    /// testing for existence of properties (EXISTS), testing for null-values (IS NULL), logical NOT/AND/OR, relational 
 19    /// numeric arithmetic, and simple text pattern matching with LIKE.
 20    /// </remarks>
 21    public class SqlFilter : Filter
 22    {
 23        internal PropertyDictionary parameters;
 24
 25        /// <summary>
 26        /// Initializes a new instance of the <see cref="SqlFilter" /> class using the specified SQL expression.
 27        /// </summary>
 28        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 029        public SqlFilter(string sqlExpression)
 30        {
 031            if (string.IsNullOrEmpty(sqlExpression))
 32            {
 033                throw Fx.Exception.ArgumentNull(nameof(sqlExpression));
 34            }
 35
 036            if (sqlExpression.Length > Constants.MaximumSqlFilterStatementLength)
 37            {
 038                throw Fx.Exception.Argument(
 039                    nameof(sqlExpression),
 040                    Resources.SqlFilterStatmentTooLong.FormatForUser(
 041                        sqlExpression.Length,
 042                        Constants.MaximumSqlFilterStatementLength));
 43            }
 44
 045            this.SqlExpression = sqlExpression;
 046        }
 47
 48        /// <summary>
 49        /// Gets the SQL expression.
 50        /// </summary>
 51        /// <value>The SQL expression.</value>
 52        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 053        public string SqlExpression { get; }
 54
 55        /// <summary>
 56        /// Sets the value of a filter expression.
 57        /// Allowed types: string, int, long, bool, double
 58        /// </summary>
 59        /// <value>The value of a filter expression.</value>
 060        public IDictionary<string, object> Parameters => this.parameters ?? (this.parameters = new PropertyDictionary())
 61
 62        /// <summary>
 63        /// Returns a string representation of <see cref="SqlFilter" />.
 64        /// </summary>
 65        /// <returns>The string representation of <see cref="SqlFilter" />.</returns>
 66        public override string ToString()
 67        {
 068            return string.Format(CultureInfo.InvariantCulture, "SqlFilter: {0}", this.SqlExpression);
 69        }
 70
 71        public override int GetHashCode()
 72        {
 073            return this.SqlExpression?.GetHashCode() ?? base.GetHashCode();
 74        }
 75
 76        public override bool Equals(object obj)
 77        {
 078            var other = obj as Filter;
 079            return this.Equals(other);
 80        }
 81
 82        public override bool Equals(Filter other)
 83        {
 084            if (other is SqlFilter sqlFilter)
 85            {
 086                if (string.Equals(this.SqlExpression, sqlFilter.SqlExpression, StringComparison.OrdinalIgnoreCase)
 087                    && (this.parameters != null && sqlFilter.parameters != null
 088                        || this.parameters == null && sqlFilter.parameters == null))
 89                {
 090                    if (this.parameters != null)
 91                    {
 092                        if (this.parameters.Count != sqlFilter.parameters.Count)
 93                        {
 094                            return false;
 95                        }
 96
 097                        foreach (var param in this.parameters)
 98                        {
 099                            if (!sqlFilter.parameters.TryGetValue(param.Key, out var otherParamValue) ||
 0100                                (param.Value == null ^ otherParamValue == null) ||
 0101                                (param.Value != null && !param.Value.Equals(otherParamValue)))
 102                            {
 0103                                return false;
 104                            }
 105                        }
 106                    }
 107
 0108                    return true;
 109                }
 110            }
 111
 0112            return false;
 0113        }
 114
 115        public static bool operator ==(SqlFilter o1, SqlFilter o2)
 116        {
 0117            if (ReferenceEquals(o1, o2))
 118            {
 0119                return true;
 120            }
 121
 0122            if (ReferenceEquals(o1, null) || ReferenceEquals(o2, null))
 123            {
 0124                return false;
 125            }
 126
 0127            return o1.Equals(o2);
 128        }
 129
 130        public static bool operator !=(SqlFilter o1, SqlFilter o2)
 131        {
 0132            return !(o1 == o2);
 133        }
 134    }
 135}