< Summary

Class:Microsoft.Azure.ServiceBus.Primitives.Ticks
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Primitives\Ticks.cs
Covered lines:0
Uncovered lines:14
Coverable lines:14
Total lines:57
Line coverage:0% (0 of 14)
Covered branches:0
Total branches:16
Branch coverage:0% (0 of 16)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Now()-0%100%
FromMilliseconds(...)-0%100%
ToMilliseconds(...)-0%100%
FromTimeSpan(...)-0%100%
ToTimeSpan(...)-0%100%
Add(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Primitives\Ticks.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.Primitives
 5{
 6    using System;
 7
 8    static class Ticks
 9    {
 010        public static long Now => DateTime.UtcNow.ToFileTimeUtc();
 11
 12        public static long FromMilliseconds(int milliseconds)
 13        {
 014            return checked(milliseconds * TimeSpan.TicksPerMillisecond);
 15        }
 16
 17        public static int ToMilliseconds(long ticks)
 18        {
 019            return checked((int)(ticks / TimeSpan.TicksPerMillisecond));
 20        }
 21
 22        public static long FromTimeSpan(TimeSpan duration)
 23        {
 024            return duration.Ticks;
 25        }
 26
 27        public static TimeSpan ToTimeSpan(long ticks)
 28        {
 029            return new TimeSpan(ticks);
 30        }
 31
 32        public static long Add(long firstTicks, long secondTicks)
 33        {
 034            if (firstTicks == long.MaxValue || firstTicks == long.MinValue)
 35            {
 036                return firstTicks;
 37            }
 38
 039            if (secondTicks == long.MaxValue || secondTicks == long.MinValue)
 40            {
 041                return secondTicks;
 42            }
 43
 044            if (firstTicks >= 0 && long.MaxValue - firstTicks <= secondTicks)
 45            {
 046                return long.MaxValue - 1;
 47            }
 48
 049            if (firstTicks <= 0 && long.MinValue - firstTicks >= secondTicks)
 50            {
 051                return long.MinValue + 1;
 52            }
 53
 054            return checked(firstTicks + secondTicks);
 55        }
 56    }
 57}