< Summary

Class:Azure.Messaging.ServiceBus.Core.ServiceBusRetryOptionsExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Core\ServiceBusRetryOptionsExtensions.cs
Covered lines:10
Uncovered lines:13
Coverable lines:23
Total lines:88
Line coverage:43.4% (10 of 23)
Covered branches:2
Total branches:18
Branch coverage:11.1% (2 of 18)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Clone(...)-100%100%
ToRetryPolicy(...)-100%100%
IsEquivalentTo(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Core\ServiceBusRetryOptionsExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5
 6namespace Azure.Messaging.ServiceBus.Core
 7{
 8    /// <summary>
 9    ///   The set of extension methods for the <see cref="ServiceBusRetryOptions" />
 10    ///   class.
 11    /// </summary>
 12    ///
 13    internal static class ServiceBusRetryOptionsExtensions
 14    {
 15        /// <summary>
 16        ///   Creates a new copy of the current <see cref="ServiceBusRetryOptions" />, cloning its attributes into a new
 17        /// </summary>
 18        ///
 19        /// <param name="instance">The instance that this method was invoked on.</param>
 20        ///
 21        /// <returns>A new copy of <see cref="ServiceBusRetryOptions" />.</returns>
 22        ///
 23        public static ServiceBusRetryOptions Clone(this ServiceBusRetryOptions instance) =>
 6024            new ServiceBusRetryOptions
 6025            {
 6026                Mode = instance.Mode,
 6027                CustomRetryPolicy = instance.CustomRetryPolicy,
 6028                MaxRetries = instance.MaxRetries,
 6029                Delay = instance.Delay,
 6030                MaxDelay = instance.MaxDelay,
 6031                TryTimeout = instance.TryTimeout
 6032            };
 33
 34        /// <summary>
 35        ///   Converts the options into a retry policy for use.
 36        /// </summary>
 37        ///
 38        /// <param name="instance">The instance that this method was invoked on.</param>
 39        ///
 40        /// <returns>The <see cref="ServiceBusRetryPolicy" /> represented by the options.</returns>
 41        public static ServiceBusRetryPolicy ToRetryPolicy(this ServiceBusRetryOptions instance) =>
 8842            instance.CustomRetryPolicy ?? new BasicRetryPolicy(instance);
 43
 44        /// <summary>
 45        ///   Compares retry options between two instances to determine if the
 46        ///   instances represent the same set of options.
 47        /// </summary>
 48        ///
 49        /// <param name="instance">The instance that this method was invoked on.</param>
 50        /// <param name="other">The other set of retry options to consider.</param>
 51        ///
 52        /// <returns><c>true</c>, if the two sets of options are structurally equivalent; otherwise, <c>false</c>.</retu
 53        ///
 54        public static bool IsEquivalentTo(
 55            this ServiceBusRetryOptions instance,
 56            ServiceBusRetryOptions other)
 57        {
 58            // If the events are the same instance, they're equal.  This should only happen
 59            // if both are null or they are the exact same instance.
 60
 061            if (Object.ReferenceEquals(instance, other))
 62            {
 063                return true;
 64            }
 65
 66            // If one or the other is null, then they cannot be equal, since we know that
 67            // they are not both null.
 68
 069            if ((instance == null) || (other == null))
 70            {
 071                return false;
 72            }
 73
 74            // If the contents of each attribute are equal, the instance are
 75            // equal.
 76
 077            return
 078            (
 079                instance.Mode == other.Mode
 080                && instance.MaxRetries == other.MaxRetries
 081                && instance.Delay == other.Delay
 082                && instance.MaxDelay == other.MaxDelay
 083                && instance.TryTimeout == other.TryTimeout
 084                && instance.CustomRetryPolicy == other.CustomRetryPolicy
 085            );
 86        }
 87    }
 88}