Example #1
0
        public async Task DelayInitialWaitsForDurationCorrectly()
        {
            // Arrange
            var schedule = Get.CustomBuilderFor.Schedule.ToStartWithDelay(TimeSpan.FromMilliseconds(400));
            var sut      = new Timer();

            // Act
            var sw = Stopwatch.StartNew();
            await sut.DelayInitial(schedule, CancellationToken.None);

            sw.Stop();

            //Assert
            sw.Elapsed.Should().BeCloseTo(TimeSpan.FromMilliseconds(400), 50);
        }
Example #2
0
        public void DelayInitialCancelsIfTriggered()
        {
            // Arrange
            var schedule = Get.CustomBuilderFor.Schedule.ToStartWithDelay(TimeSpan.FromMilliseconds(1000));
            var sut      = new Timer();

            // Act
            var sw  = Stopwatch.StartNew();
            var cts = new CancellationTokenSource(150);

            Assert.CatchAsync(async() => await sut.DelayInitial(schedule, cts.Token));
            sw.Stop();

            //Assert
            sw.Elapsed.Should().BeCloseTo(TimeSpan.FromMilliseconds(150), 50);
        }