< Summary

Class:Microsoft.Azure.ServiceBus.SqlRuleAction
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Filters\SqlRuleAction.cs
Covered lines:0
Uncovered lines:38
Coverable lines:38
Total lines:128
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\SqlRuleAction.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 set of actions written in SQL language-based syntax that is performed against a <see cref="Message" /
 13    /// </summary>
 14    public sealed class SqlRuleAction : RuleAction
 15    {
 16        internal PropertyDictionary parameters;
 17
 18        /// <summary>
 19        /// Initializes a new instance of the <see cref="SqlRuleAction" /> class with the specified SQL expression.
 20        /// </summary>
 21        /// <param name="sqlExpression">The SQL expression.</param>
 22        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 023        public SqlRuleAction(string sqlExpression)
 24        {
 025            if (string.IsNullOrEmpty(sqlExpression))
 26            {
 027                throw Fx.Exception.ArgumentNullOrWhiteSpace(nameof(sqlExpression));
 28            }
 29
 030            if (sqlExpression.Length > Constants.MaximumSqlRuleActionStatementLength)
 31            {
 032                throw Fx.Exception.Argument(
 033                    nameof(sqlExpression),
 034                    Resources.SqlFilterActionStatmentTooLong.FormatForUser(
 035                        sqlExpression.Length,
 036                        Constants.MaximumSqlRuleActionStatementLength));
 37            }
 38
 039            this.SqlExpression = sqlExpression;
 040        }
 41
 42        /// <summary>
 43        /// Gets the SQL expression.
 44        /// </summary>
 45        /// <value>The SQL expression.</value>
 46        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 047        public string SqlExpression { get; }
 48
 49        /// <summary>
 50        /// Sets the value of a rule action.
 51        /// </summary>
 52        /// <value>The value of a rule action.</value>
 053        public IDictionary<string, object> Parameters => this.parameters ?? (this.parameters = new PropertyDictionary())
 54
 55        /// <summary>
 56        /// Returns a string representation of <see cref="SqlRuleAction" />.
 57        /// </summary>
 58        /// <returns>The string representation of <see cref="SqlRuleAction" />.</returns>
 59        public override string ToString()
 60        {
 061            return string.Format(CultureInfo.InvariantCulture, "SqlRuleAction: {0}", this.SqlExpression);
 62        }
 63
 64        public override int GetHashCode()
 65        {
 066            return this.SqlExpression?.GetHashCode() ?? base.GetHashCode();
 67        }
 68
 69        public override bool Equals(object obj)
 70        {
 071            var other = obj as RuleAction;
 072            return this.Equals(other);
 73        }
 74
 75        public override bool Equals(RuleAction other)
 76        {
 077            if (other is SqlRuleAction sqlAction)
 78            {
 079                if (string.Equals(this.SqlExpression, sqlAction.SqlExpression, StringComparison.OrdinalIgnoreCase)
 080                    && (this.parameters != null && sqlAction.parameters != null
 081                        || this.parameters == null && sqlAction.parameters == null))
 82                {
 083                    if (this.parameters != null)
 84                    {
 085                        if (this.parameters.Count != sqlAction.parameters.Count)
 86                        {
 087                            return false;
 88                        }
 89
 090                        foreach (var param in this.parameters)
 91                        {
 092                            if (!sqlAction.parameters.TryGetValue(param.Key, out var otherParamValue) ||
 093                                (param.Value == null ^ otherParamValue == null) ||
 094                                (param.Value != null && !param.Value.Equals(otherParamValue)))
 95                            {
 096                                return false;
 97                            }
 98                        }
 99                    }
 100
 0101                    return true;
 102                }
 103            }
 104
 0105            return false;
 0106        }
 107
 108        public static bool operator ==(SqlRuleAction o1, SqlRuleAction o2)
 109        {
 0110            if (ReferenceEquals(o1, o2))
 111            {
 0112                return true;
 113            }
 114
 0115            if (ReferenceEquals(o1, null) || ReferenceEquals(o2, null))
 116            {
 0117                return false;
 118            }
 119
 0120            return o1.Equals(o2);
 121        }
 122
 123        public static bool operator !=(SqlRuleAction o1, SqlRuleAction o2)
 124        {
 0125            return !(o1 == o2);
 126        }
 127    }
 128}