Esempio n. 1
0
        public void TimeSyncIsSupportedByDefault()
        {
            // given
            var provider = new DefaultTimingProvider();

            // then
            Assert.That(provider.IsTimeSyncSupported, Is.True);
        }
Esempio n. 2
0
        public void ProvideTimeStampInMillisecondsReturnsCurrentTime()
        {
            // given
            var target = new DefaultTimingProvider();

            // when
            var timeBefore = (long)TimeSpan.FromTicks(
                (target.ReferenceTimestampTicks + (long)((Stopwatch.GetTimestamp() / (double)Stopwatch.Frequency) * TimeSpan.TicksPerSecond))
                ).TotalMilliseconds;
            var obtained  = target.ProvideTimestampInMilliseconds();
            var timeAfter = (long)TimeSpan.FromTicks(
                (target.ReferenceTimestampTicks + (long)((Stopwatch.GetTimestamp() / (double)Stopwatch.Frequency) * TimeSpan.TicksPerSecond))
                ).TotalMilliseconds;

            // then
            Assert.That(obtained, Is.GreaterThanOrEqualTo(timeBefore));
            Assert.That(obtained, Is.LessThanOrEqualTo(timeAfter));
        }