public void delay_cancels_the_delay_if_subscription_is_disposed()
        {
            var scheduler = new TestScheduler();
            var sut = new DelayServiceBuilder()
                .WithScheduler(scheduler)
                .Build();
            var executed = false;
            var delayResult = sut
                .Delay(TimeSpan.FromSeconds(5))
                .Subscribe(_ => executed = true);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1));
            Assert.False(executed);

            delayResult.Dispose();
            scheduler.AdvanceBy(TimeSpan.FromSeconds(5));
            Assert.False(executed);
        }
        public void delay_async_cancels_the_delay_if_cancellation_token_is_cancelled()
        {
            var scheduler = new TestSchedulerService();
            var sut = new DelayServiceBuilder()
                .WithSchedulerService(scheduler)
                .Build();
            var cts = new CancellationTokenSource();
            Exception exception = null;
            var delayResult = sut
                .DelayAsync(TimeSpan.FromSeconds(5), cts.Token)
                .Subscribe(
                    _ => { },
                    ex => exception = ex);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1));
            Assert.Null(exception);

            cts.Cancel();
            scheduler.AdvanceBy(TimeSpan.FromSeconds(5));
            Assert.IsType<OperationCanceledException>(exception);
        }
        public void delay_async_returns_observable_that_ticks_after_specified_delay()
        {
            var scheduler = new TestSchedulerService();
            var sut = new DelayServiceBuilder()
                .WithSchedulerService(scheduler)
                .Build();

            var completed = false;
            sut
                .DelayAsync(TimeSpan.FromSeconds(5))
                .Subscribe(_ => completed = true);
            Assert.False(completed);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1));
            Assert.False(completed);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(2));
            Assert.False(completed);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(3));
            Assert.True(completed);
        }