public async Task DelayIntervalWaitsForDurationCorrectly() { // Arrange var schedule = Get.CustomBuilderFor.Schedule.WithInterval(TimeSpan.FromMilliseconds(500)); var sut = new Timer(); // Act var sw = Stopwatch.StartNew(); await sut.DelayInterval(schedule, CancellationToken.None); sw.Stop(); //Assert sw.Elapsed.Should().BeCloseTo(TimeSpan.FromMilliseconds(500), 100); }
public void DelayIntervalCancelsIfTriggered() { // Arrange var schedule = Get.CustomBuilderFor.Schedule.WithInterval(TimeSpan.FromMilliseconds(1000)); var sut = new Timer(); // Act var sw = Stopwatch.StartNew(); var cts = new CancellationTokenSource(150); Assert.CatchAsync(async() => await sut.DelayInterval(schedule, cts.Token)); sw.Stop(); //Assert sw.Elapsed.Should().BeCloseTo(TimeSpan.FromMilliseconds(150), 50); }