< Summary

Class:Azure.Messaging.EventHubs.Core.TimeSpanExtensions
Assembly:Azure.Messaging.EventHubs
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Core\TimeSpanExtensions.cs
Covered lines:3
Uncovered lines:2
Coverable lines:5
Total lines:41
Line coverage:60% (3 of 5)
Covered branches:3
Total branches:6
Branch coverage:50% (3 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
CalculateRemaining(...)-60%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Core\TimeSpanExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5
 6namespace Azure.Messaging.EventHubs.Core
 7{
 8    /// <summary>
 9    ///   The set of extensions for the <see cref="TimeSpan" />
 10    ///   class.
 11    /// </summary>
 12    ///
 13    internal static class TimeSpanExtensions
 14    {
 15        /// <summary>
 16        ///   Calculates the duration remaining in a given period, with consideration to
 17        ///   the amount of time that has already elapsed.
 18        /// </summary>
 19        ///
 20        /// <param name="instance">The instance that this method was invoked on.</param>
 21        /// <param name="elapsed">The amount of time that has already elapsed.</param>
 22        ///
 23        /// <returns>The amount of time remaining in the time period.</returns>
 24        ///
 25        public static TimeSpan CalculateRemaining(this TimeSpan instance,
 26                                                  TimeSpan elapsed)
 27        {
 30828            if ((instance == TimeSpan.Zero) || (elapsed >= instance))
 29            {
 030                return TimeSpan.Zero;
 31            }
 32
 30833            if (elapsed == TimeSpan.Zero)
 34            {
 035                return instance;
 36            }
 37
 30838            return TimeSpan.FromMilliseconds(Math.Max(instance.TotalMilliseconds - elapsed.TotalMilliseconds, 0));
 39        }
 40    }
 41}

Methods/Properties

CalculateRemaining(...)