Пример #1
0
        public void It_sleeps_for_the_expected_time(int expectedDurationMilliseconds)
        {
            var waiter = new ThreadSleepWaiter();
            var start = DateTime.UtcNow;

            var expectedDuration = TimeSpan.FromMilliseconds(expectedDurationMilliseconds);
            waiter.Wait(expectedDuration);

            var actualWait = DateTime.UtcNow - start;

            const int tolleranceMilliseconds = 10;
            Assert.That(actualWait, Is.InRange(expectedDuration, expectedDuration + TimeSpan.FromMilliseconds(tolleranceMilliseconds)));
        }
Пример #2
0
        public void It_sleeps_for_the_expected_time(int expectedDurationMilliseconds)
        {
            var waiter = new ThreadSleepWaiter();
            var stopWatch = Stopwatch.StartNew();
            var expectedDuration = TimeSpan.FromMilliseconds(expectedDurationMilliseconds);

            waiter.Wait(expectedDuration);

            var actualWait = stopWatch.ElapsedMilliseconds;

            const int toleranceMilliseconds = ThreadSleepAccuracyMilliseconds;

            Assert.That(actualWait, Is.InRange(expectedDurationMilliseconds - toleranceMilliseconds,
                                               expectedDurationMilliseconds + toleranceMilliseconds));
        }