Example #1
0
        public void execute_pauses_if_context_is_paused()
        {
            var delayService   = new DelayServiceMock();
            var delayCallCount = 0;

            using (var context = new ExecutionContext())
            {
                delayService
                .When(x => x.Delay(It.IsAny <TimeSpan>()))
                .Do(() => context.IsPaused = delayCallCount++ == 2)
                .Return(Observable.Return(Unit.Default));

                var sut = new WaitActionBuilder()
                          .WithDelayService(delayService)
                          .WithDelay(TimeSpan.FromSeconds(50))
                          .Build();

                sut
                .Execute(context)
                .Subscribe();

                Assert.True(context.IsPaused);
                delayService
                .Verify(x => x.Delay(It.IsAny <TimeSpan>()))
                .WasCalledExactly(times: 3);
            }
        }
Example #2
0
        public void execute_skips_ahead_if_the_context_has_skip_ahead_even_if_the_context_is_paused(int delayInMs, int skipInMs)
        {
            var delayService = new DelayServiceMock();
            var totalDelay   = TimeSpan.Zero;

            delayService
            .When(x => x.Delay(It.IsAny <TimeSpan>()))
            .Do <TimeSpan>(t => totalDelay += t)
            .Return(Observable.Return(Unit.Default));

            var sut = new WaitActionBuilder()
                      .WithDelayService(delayService)
                      .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                      .Build();

            using (var context = new ExecutionContext(TimeSpan.FromMilliseconds(skipInMs))
            {
                IsPaused = true
            })
            {
                var progress = context
                               .WhenAnyValue(x => x.Progress)
                               .Skip(1)
                               .CreateCollection();

                sut.Execute(context).Subscribe();

                Assert.Equal(TimeSpan.FromMilliseconds(skipInMs), progress.First());
            }
        }
        public void execute_async_throws_if_context_is_null()
        {
            var sut = new WaitActionBuilder()
                      .Build();

            Assert.Throws <ArgumentNullException>(() => sut.ExecuteAsync(null));
        }
        public void execute_async_bails_out_if_context_is_cancelled()
        {
            var delayService   = new DelayServiceMock();
            var delayCallCount = 0;

            using (var context = new ExecutionContext())
            {
                delayService
                .When(x => x.DelayAsync(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()))
                .Do(
                    () =>
                {
                    if (delayCallCount++ == 2)
                    {
                        context.Cancel();
                    }
                })
                .Return(Observable.Return(Unit.Default));

                var sut = new WaitActionBuilder()
                          .WithDelayService(delayService)
                          .WithDelay(TimeSpan.FromSeconds(50))
                          .Build();

                sut.ExecuteAsync(context);
                Assert.True(context.IsCancelled);

                delayService
                .Verify(x => x.DelayAsync(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()))
                .WasCalledExactly(times: 3);
            }
        }
        public void execute_async_throws_if_context_is_null()
        {
            var sut = new WaitActionBuilder()
                .Build();

            Assert.Throws<ArgumentNullException>(() => sut.ExecuteAsync(null));
        }
Example #6
0
        public void duration_yields_the_duration_passed_into_ctor(int delayInMs)
        {
            var sut = new WaitActionBuilder()
                      .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                      .Build();

            Assert.Equal(TimeSpan.FromMilliseconds(delayInMs), sut.Duration);
        }
        public void duration_yields_the_duration_passed_into_ctor(int delayInMs)
        {
            var sut = new WaitActionBuilder()
                .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                .Build();

            Assert.Equal(TimeSpan.FromMilliseconds(delayInMs), sut.Duration);
        }
        public void execute_completes_even_if_there_is_no_delay()
        {
            var sut = new WaitActionBuilder()
                      .WithDelay(TimeSpan.Zero)
                      .Build();

            var executionContext = new ExecutionContext();
            var completed        = false;

            sut
            .Execute(executionContext)
            .Subscribe(_ => completed = true);

            Assert.True(completed);
        }
        public void execute_completes_even_if_there_is_no_delay()
        {
            var sut = new WaitActionBuilder()
                .WithDelay(TimeSpan.Zero)
                .Build();

            using (var executionContext = new ExecutionContext())
            {
                var completed = false;
                sut
                    .Execute(executionContext)
                    .Subscribe(_ => completed = true);

                Assert.True(completed);
            }
        }
Example #10
0
        public void execute_reports_progress_correctly_even_if_the_skip_ahead_exceeds_the_wait_duration()
        {
            var delayService = new DelayServiceMock(MockBehavior.Loose);
            var sut          = new WaitActionBuilder()
                               .WithDelayService(delayService)
                               .WithDelay(TimeSpan.FromMilliseconds(50))
                               .Build();

            using (var context = new ExecutionContext(TimeSpan.FromMilliseconds(100)))
            {
                Assert.Equal(TimeSpan.Zero, context.Progress);

                sut.Execute(context).Subscribe();

                Assert.Equal(TimeSpan.FromMilliseconds(50), context.Progress);
            }
        }
Example #11
0
        public void execute_reports_progress()
        {
            var delayService = new DelayServiceMock(MockBehavior.Loose);
            var sut          = new WaitActionBuilder()
                               .WithDelayService(delayService)
                               .WithDelay(TimeSpan.FromMilliseconds(50))
                               .Build();

            using (var context = new ExecutionContext())
            {
                Assert.Equal(TimeSpan.Zero, context.Progress);

                sut.Execute(context).Subscribe();

                Assert.Equal(TimeSpan.FromMilliseconds(50), context.Progress);
            }
        }
        public void execute_async_skips_ahead_if_the_context_has_skip_ahead(int delayInMs, int skipInMs, int expectedDelayInMs)
        {
            var delayService = new DelayServiceMock();
            var totalDelay   = TimeSpan.Zero;

            delayService
            .When(x => x.DelayAsync(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()))
            .Do <TimeSpan, CancellationToken>((t, ct) => totalDelay += t)
            .Return(Observable.Return(Unit.Default));

            var sut = new WaitActionBuilder()
                      .WithDelayService(delayService)
                      .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                      .Build();

            sut.ExecuteAsync(new ExecutionContext(TimeSpan.FromMilliseconds(skipInMs)));

            Assert.Equal(TimeSpan.FromMilliseconds(expectedDelayInMs), totalDelay);
        }
        public void execute_async_breaks_for_the_specified_delay(int delayInMs)
        {
            var delayService = new DelayServiceMock();
            var totalDelay = TimeSpan.Zero;

            delayService
                .When(x => x.DelayAsync(It.IsAny<TimeSpan>(), It.IsAny<CancellationToken>()))
                .Do<TimeSpan, CancellationToken>((t, ct) => totalDelay += t)
                .Return(Observable.Return(Unit.Default));

            var sut = new WaitActionBuilder()
                .WithDelayService(delayService)
                .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                .Build();

            sut.ExecuteAsync(new ExecutionContext());

            Assert.Equal(TimeSpan.FromMilliseconds(delayInMs), totalDelay);
        }
Example #14
0
        public void execute_breaks_for_the_specified_delay(int delayInMs)
        {
            var delayService = new DelayServiceMock();
            var totalDelay   = TimeSpan.Zero;

            delayService
            .When(x => x.Delay(It.IsAny <TimeSpan>()))
            .Do <TimeSpan>(t => totalDelay += t)
            .Return(Observable.Return(Unit.Default));

            var sut = new WaitActionBuilder()
                      .WithDelayService(delayService)
                      .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                      .Build();

            sut
            .Execute(new ExecutionContext())
            .Subscribe();

            Assert.Equal(TimeSpan.FromMilliseconds(delayInMs), totalDelay);
        }
        public void execute_skips_ahead_if_the_context_has_skip_ahead(int delayInMs, int skipInMs, int expectedDelayInMs)
        {
            var delayService = new DelayServiceMock();
            var totalDelay   = TimeSpan.Zero;

            delayService
            .When(x => x.Delay(It.IsAny <TimeSpan>()))
            .Do <TimeSpan>(t => totalDelay += t)
            .Return(Observables.Unit);

            var sut = new WaitActionBuilder()
                      .WithDelayService(delayService)
                      .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                      .Build();

            sut
            .Execute(new ExecutionContext(TimeSpan.FromMilliseconds(skipInMs)))
            .Subscribe();

            Assert.Equal(TimeSpan.FromMilliseconds(expectedDelayInMs), totalDelay);
        }
        public void execute_async_skips_ahead_if_the_context_has_skip_ahead_even_if_the_context_is_paused(int delayInMs, int skipInMs)
        {
            var delayService = new DelayServiceMock();
            var totalDelay = TimeSpan.Zero;

            delayService
                .When(x => x.DelayAsync(It.IsAny<TimeSpan>(), It.IsAny<CancellationToken>()))
                .Do<TimeSpan, CancellationToken>((t, ct) => totalDelay += t)
                .Return(Observable.Return(Unit.Default));

            var sut = new WaitActionBuilder()
                .WithDelayService(delayService)
                .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                .Build();

            using (var context = new ExecutionContext(TimeSpan.FromMilliseconds(skipInMs)) { IsPaused = true })
            {
                var progress = context
                    .WhenAnyValue(x => x.Progress)
                    .Skip(1)
                    .CreateCollection();

                sut.ExecuteAsync(context);

                Assert.Equal(TimeSpan.FromMilliseconds(skipInMs), progress.First());
            }
        }
        public void execute_async_reports_progress()
        {
            var delayService = new DelayServiceMock(MockBehavior.Loose);
            var sut = new WaitActionBuilder()
                .WithDelayService(delayService)
                .WithDelay(TimeSpan.FromMilliseconds(50))
                .Build();

            using (var context = new ExecutionContext())
            {
                Assert.Equal(TimeSpan.Zero, context.Progress);

                sut.ExecuteAsync(context);

                Assert.Equal(TimeSpan.FromMilliseconds(50), context.Progress);
            }
        }
        public void execute_async_reports_progress_correctly_even_if_the_skip_ahead_exceeds_the_wait_duration()
        {
            var delayService = new DelayServiceMock(MockBehavior.Loose);
            var sut = new WaitActionBuilder()
                .WithDelayService(delayService)
                .WithDelay(TimeSpan.FromMilliseconds(50))
                .Build();

            using (var context = new ExecutionContext(TimeSpan.FromMilliseconds(100)))
            {
                Assert.Equal(TimeSpan.Zero, context.Progress);

                sut.ExecuteAsync(context);

                Assert.Equal(TimeSpan.FromMilliseconds(50), context.Progress);
            }
        }
        public void execute_skips_ahead_if_the_context_has_skip_ahead(int delayInMs, int skipInMs, int expectedDelayInMs)
        {
            var delayService = new DelayServiceMock();
            var totalDelay = TimeSpan.Zero;

            delayService
                .When(x => x.Delay(It.IsAny<TimeSpan>()))
                .Do<TimeSpan>(t => totalDelay += t)
                .Return(Observable.Return(Unit.Default));

            var sut = new WaitActionBuilder()
                .WithDelayService(delayService)
                .WithDelay(TimeSpan.FromMilliseconds(delayInMs))
                .Build();

            sut
                .Execute(new ExecutionContext(TimeSpan.FromMilliseconds(skipInMs)))
                .Subscribe();

            Assert.Equal(TimeSpan.FromMilliseconds(expectedDelayInMs), totalDelay);
        }
        public void execute_async_pauses_if_context_is_paused()
        {
            var delayService = new DelayServiceMock();
            var delayCallCount = 0;

            using (var context = new ExecutionContext())
            {
                delayService
                    .When(x => x.DelayAsync(It.IsAny<TimeSpan>(), It.IsAny<CancellationToken>()))
                    .Do(() => context.IsPaused = delayCallCount++ == 2)
                    .Return(Observable.Return(Unit.Default));

                var sut = new WaitActionBuilder()
                    .WithDelayService(delayService)
                    .WithDelay(TimeSpan.FromSeconds(50))
                    .Build();

                sut.ExecuteAsync(context);

                Assert.True(context.IsPaused);
                delayService
                    .Verify(x => x.DelayAsync(It.IsAny<TimeSpan>(), It.IsAny<CancellationToken>()))
                    .WasCalledExactly(times: 3);
            }
        }