< Summary

Class:Azure.Messaging.ServiceBus.Management.SqlRuleAction
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\SqlRuleAction.cs
Covered lines:15
Uncovered lines:18
Coverable lines:33
Total lines:132
Line coverage:45.4% (15 of 33)
Covered branches:6
Total branches:24
Branch coverage:25% (6 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(...)-33.33%37.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\SqlRuleAction.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 set of actions written in SQL language-based syntax that is performed against a <see cref="ServiceBus
 14    /// </summary>
 15    public sealed class SqlRuleAction : RuleAction
 16    {
 17        /// <summary>
 18        /// Initializes a new instance of the <see cref="SqlRuleAction" /> class with the specified SQL expression.
 19        /// </summary>
 20        /// <param name="sqlExpression">The SQL expression.</param>
 21        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 3022        public SqlRuleAction(string sqlExpression)
 23        {
 3024            Argument.AssertNotNullOrWhiteSpace(sqlExpression, nameof(sqlExpression));
 2625            Argument.AssertNotTooLong(sqlExpression, Constants.MaximumSqlRuleActionStatementLength, nameof(sqlExpression
 26
 2427            SqlExpression = sqlExpression;
 2428        }
 29
 30        internal override RuleAction Clone() =>
 831            new SqlRuleAction(SqlExpression)
 832            {
 833                Parameters = (Parameters as PropertyDictionary).Clone()
 834            };
 35
 36        /// <summary>
 37        /// Gets the SQL expression.
 38        /// </summary>
 39        /// <value>The SQL expression.</value>
 40        /// <remarks>Max allowed length of sql expression is 1024 chars.</remarks>
 2841        public string SqlExpression { get; }
 42
 43        /// <summary>
 44        /// Sets the value of a rule action.
 45        /// </summary>
 46        /// <value>The value of a rule action.</value>
 7447        public IDictionary<string, object> Parameters { get; set; } = new PropertyDictionary();
 48
 49        /// <summary>
 50        /// Returns a string representation of <see cref="SqlRuleAction" />.
 51        /// </summary>
 52        /// <returns>The string representation of <see cref="SqlRuleAction" />.</returns>
 53        public override string ToString()
 54        {
 055            return string.Format(CultureInfo.InvariantCulture, "SqlRuleAction: {0}", SqlExpression);
 56        }
 57
 58        /// <inheritdoc/>
 59        public override int GetHashCode()
 60        {
 061            return SqlExpression?.GetHashCode() ?? base.GetHashCode();
 62        }
 63
 64        /// <inheritdoc/>
 65        public override bool Equals(object obj)
 66        {
 067            var other = obj as RuleAction;
 068            return Equals(other);
 69        }
 70
 71        /// <inheritdoc/>
 72        public override bool Equals(RuleAction other)
 73        {
 874            if (other is SqlRuleAction sqlRuleAction)
 75            {
 876                if (string.Equals(SqlExpression, sqlRuleAction.SqlExpression, StringComparison.OrdinalIgnoreCase))
 77                {
 878                    if (Parameters.Count != sqlRuleAction.Parameters.Count)
 79                    {
 080                        return false;
 81                    }
 82
 083                    foreach (var param in Parameters)
 84                    {
 085                        if (!sqlRuleAction.Parameters.TryGetValue(param.Key, out var otherParamValue) ||
 086                            (param.Value == null ^ otherParamValue == null) ||
 087                            (param.Value != null && !param.Value.Equals(otherParamValue)))
 88                        {
 089                            return false;
 90                        }
 91                    }
 92
 893                    return true;
 94                }
 95            }
 96
 097            return false;
 098        }
 99
 100        /// <summary>
 101        ///
 102        /// </summary>
 103        /// <param name="left"></param>
 104        /// <param name="right"></param>
 105        /// <returns></returns>
 106        public static bool operator ==(SqlRuleAction left, SqlRuleAction right)
 107        {
 0108            if (ReferenceEquals(left, right))
 109            {
 0110                return true;
 111            }
 112
 0113            if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
 114            {
 0115                return false;
 116            }
 117
 0118            return left.Equals(right);
 119        }
 120
 121        /// <summary>
 122        ///
 123        /// </summary>
 124        /// <param name="left"></param>
 125        /// <param name="right"></param>
 126        /// <returns></returns>
 127        public static bool operator !=(SqlRuleAction left, SqlRuleAction right)
 128        {
 0129            return !(left == right);
 130        }
 131    }
 132}