Exemple #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);
            }
        }
Exemple #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_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);
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
0
        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);
        }
Exemple #8
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_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(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_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);
            }
        }
        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);
            }
        }
        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_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());
            }
        }