public void add_progress_adds_to_the_progress()
        {
            var sut = new ExecutionContext();
            Assert.Equal(TimeSpan.Zero, sut.Progress);

            sut.AddProgress(TimeSpan.FromMilliseconds(100));
            Assert.Equal(TimeSpan.FromMilliseconds(100), sut.Progress);

            sut.AddProgress(TimeSpan.FromMilliseconds(150));
            Assert.Equal(TimeSpan.FromMilliseconds(250), sut.Progress);

            sut.AddProgress(TimeSpan.FromMilliseconds(13));
            Assert.Equal(TimeSpan.FromMilliseconds(263), sut.Progress);
        }
Exemplo n.º 2
0
        public IObservable <Unit> Execute(ExecutionContext context)
        {
            Ensure.ArgumentNotNull(context, nameof(context));

            return(Observable
                   .Concat(
                       this
                       .GetEventsWithActions(context)
                       .SelectMany(eventWithActions => eventWithActions.Actions.Select(action => new { Action = action, Event = eventWithActions.Event }))
                       .Select(
                           actionAndEvent =>
            {
                var action = actionAndEvent.Action;
                var @event = actionAndEvent.Event;

                if (context.SkipAhead > TimeSpan.Zero && context.SkipAhead >= action.Duration)
                {
                    this.logger.Debug("Skipping action {0} for event {1} because its duration ({2}) is less than the remaining skip ahead ({3}).", action, @event, action.Duration, context.SkipAhead);
                    context.AddProgress(action.Duration);
                    return Observable.Return(Unit.Default);
                }

                this.logger.Debug("Executing action {0} for event {1}.", action, @event);
                return action.Execute(context);
            })));
        }
Exemplo n.º 3
0
        public IObservable<Unit> Execute(ExecutionContext context)
        {
            Ensure.ArgumentNotNull(context, nameof(context));

            return Observable
                .Concat(
                    this
                        .GetEventsWithActions(context)
                        .SelectMany(eventWithActions => eventWithActions.Actions.Select(action => new { Action = action, Event = eventWithActions.Event }))
                        .Select(
                            actionAndEvent =>
                            {
                                var action = actionAndEvent.Action;
                                var @event = actionAndEvent.Event;

                                if (context.SkipAhead > TimeSpan.Zero && context.SkipAhead >= action.Duration)
                                {
                                    this.logger.Debug("Skipping action {0} for event {1} because its duration ({2}) is less than the remaining skip ahead ({3}).", action, @event, action.Duration, context.SkipAhead);
                                    context.AddProgress(action.Duration);
                                    return Observable.Return(Unit.Default);
                                }

                                this.logger.Debug("Executing action {0} for event {1}.", action, @event);
                                return action.Execute(context);
                            }));
        }
        public void progress_time_span_is_zero_if_no_progress_has_been_made_through_this_exercise()
        {
            var model1 = new ExerciseBuilder()
                .Build();
            var model2 = new ExerciseBuilder()
                .Build();
            var executionContext = new ExecutionContext();
            var sut = new ExerciseViewModelBuilder()
                .WithModel(model2)
                .WithExecutionContext(executionContext)
                .Build();

            executionContext.SetCurrentExercise(model1);
            executionContext.AddProgress(TimeSpan.FromSeconds(3));

            Assert.Equal(TimeSpan.Zero, sut.ProgressTimeSpan);
        }
Exemplo n.º 5
0
        public IObservable <Unit> Execute(ExecutionContext context)
        {
            Ensure.ArgumentNotNull(context, nameof(context));

            return(Observable
                   .Concat(
                       this
                       .exercises
                       .Select(
                           exercise =>
            {
                if (context.SkipAhead > TimeSpan.Zero && context.SkipAhead >= exercise.Duration)
                {
                    this.logger.Debug("Skipping exercise '{0}' because its duration ({1}) is less than the remaining skip ahead ({2}).", exercise.Name, exercise.Duration, context.SkipAhead);
                    context.AddProgress(exercise.Duration);
                    return Observables.Unit;
                }

                this.logger.Debug("Executing exercise '{0}'.", exercise.Name);
                return exercise.Execute(context);
            }))
                   .DefaultIfEmpty());
        }
Exemplo n.º 6
0
        public IObservable<Unit> Execute(ExecutionContext context)
        {
            Ensure.ArgumentNotNull(context, nameof(context));

            return Observable
                .Concat(
                    this
                        .exercises
                        .Select(
                            exercise =>
                            {
                                if (context.SkipAhead > TimeSpan.Zero && context.SkipAhead >= exercise.Duration)
                                {
                                    this.logger.Debug("Skipping exercise '{0}' because its duration ({1}) is less than the remaining skip ahead ({2}).", exercise.Name, exercise.Duration, context.SkipAhead);
                                    context.AddProgress(exercise.Duration);
                                    return Observable.Return(Unit.Default);
                                }

                                this.logger.Debug("Executing exercise '{0}'.", exercise.Name);
                                return exercise.Execute(context);
                            }))
                .DefaultIfEmpty();
        }
        public IObservable <Unit> ExecuteAsync(ExecutionContext context)
        {
            context.AssertNotNull(nameof(context));

            return(Observable
                   .Concat(
                       this
                       .exercises
                       .Select(
                           exercise =>
            {
                if (context.SkipAhead > TimeSpan.Zero && context.SkipAhead >= exercise.Duration)
                {
                    this.logger.Debug("Skipping exercise '{0}' because its duration ({1}) is less than the remaining skip ahead ({2}).", exercise.Name, exercise.Duration, context.SkipAhead);
                    context.AddProgress(exercise.Duration);
                    return Observable.Return(Unit.Default);
                }

                this.logger.Debug("Executing exercise '{0}'.", exercise.Name);
                return exercise.ExecuteAsync(context);
            }))
                   .RunAsync(context.CancellationToken));
        }
        public void setting_current_exercise_resets_the_current_exercise_progress_to_zero()
        {
            var sut = new ExecutionContext();

            sut.SetCurrentExercise(new ExerciseBuilder()
                .WithSetCount(3)
                .WithRepetitionCount(10)
                .Build());
            sut.AddProgress(TimeSpan.FromMilliseconds(100));
            Assert.Equal(TimeSpan.FromMilliseconds(100), sut.CurrentExerciseProgress);

            sut.SetCurrentExercise(new ExerciseBuilder()
                .WithSetCount(3)
                .WithRepetitionCount(10)
                .Build());
            Assert.Equal(TimeSpan.Zero, sut.CurrentExerciseProgress);

            sut.AddProgress(TimeSpan.FromMilliseconds(150));
            Assert.Equal(TimeSpan.FromMilliseconds(150), sut.CurrentExerciseProgress);
        }
        public void add_progress_does_not_reduce_skip_ahead_if_it_is_already_zero()
        {
            var sut = new ExecutionContext(TimeSpan.FromSeconds(1));
            Assert.Equal(TimeSpan.FromSeconds(1), sut.SkipAhead);

            sut.AddProgress(TimeSpan.FromMilliseconds(900));
            Assert.Equal(TimeSpan.FromSeconds(0.1), sut.SkipAhead);

            sut.AddProgress(TimeSpan.FromMilliseconds(150));
            Assert.Equal(TimeSpan.Zero, sut.SkipAhead);

            sut.AddProgress(TimeSpan.FromMilliseconds(1000));
            Assert.Equal(TimeSpan.Zero, sut.SkipAhead);
        }
        public void add_progress_reduces_outstanding_skip_ahead()
        {
            var sut = new ExecutionContext(TimeSpan.FromSeconds(3));
            Assert.Equal(TimeSpan.FromSeconds(3), sut.SkipAhead);

            sut.AddProgress(TimeSpan.FromMilliseconds(100));
            Assert.Equal(TimeSpan.FromSeconds(2.9), sut.SkipAhead);

            sut.AddProgress(TimeSpan.FromMilliseconds(150));
            Assert.Equal(TimeSpan.FromSeconds(2.75), sut.SkipAhead);

            sut.AddProgress(TimeSpan.FromMilliseconds(1000));
            Assert.Equal(TimeSpan.FromSeconds(1.75), sut.SkipAhead);
        }
        public void progress_is_calculated_based_on_duration_and_progress_time_span(int durationInMs, int progressInMs, double expectedProgress)
        {
            var scheduler = new TestSchedulerService();
            var action = new ActionMock(MockBehavior.Loose);

            action
                .When(x => x.Duration)
                .Return(TimeSpan.FromMilliseconds(durationInMs));

            var model = new ExerciseBuilder()
                .WithBeforeExerciseAction(action)
                .Build();

            var executionContext = new ExecutionContext();
            var sut = new ExerciseViewModelBuilder()
                .WithSchedulerService(scheduler)
                .WithExecutionContext(executionContext)
                .WithModel(model)
                .Build();

            executionContext.SetCurrentExercise(model);
            executionContext.AddProgress(TimeSpan.FromMilliseconds(progressInMs));

            scheduler.AdvanceMinimal();

            Assert.Equal(expectedProgress, sut.Progress);
        }
        public void progress_time_span_is_reset_to_zero_if_the_execution_context_changes_to_null()
        {
            var scheduler = new TestSchedulerService();
            var model = new ExerciseBuilder()
                .Build();
            var executionContext = new ExecutionContext();
            var executionContextSubject = new Subject<ExecutionContext>();
            var sut = new ExerciseViewModelBuilder()
                .WithSchedulerService(scheduler)
                .WithExecutionContext(executionContextSubject)
                .WithModel(model)
                .Build();

            executionContextSubject.OnNext(executionContext);
            executionContext.SetCurrentExercise(model);

            executionContext.AddProgress(TimeSpan.FromSeconds(3));
            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.FromSeconds(3), sut.ProgressTimeSpan);

            executionContextSubject.OnNext(null);
            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.Zero, sut.ProgressTimeSpan);
        }
        public void progress_time_span_is_not_reset_to_zero_if_another_exercise_is_started()
        {
            var scheduler = new TestSchedulerService();
            var model1 = new ExerciseBuilder()
                .WithName("model 1")
                .Build();
            var model2 = new ExerciseBuilder()
                .WithName("model 2")
                .Build();
            var executionContext = new ExecutionContext();
            var sut = new ExerciseViewModelBuilder()
                .WithSchedulerService(scheduler)
                .WithExecutionContext(executionContext)
                .WithModel(model1)
                .Build();

            executionContext.SetCurrentExercise(model1);
            executionContext.AddProgress(TimeSpan.FromSeconds(3));

            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.FromSeconds(3), sut.ProgressTimeSpan);

            executionContext.SetCurrentExercise(model2);
            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.FromSeconds(3), sut.ProgressTimeSpan);

            executionContext.AddProgress(TimeSpan.FromSeconds(3));
            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.FromSeconds(3), sut.ProgressTimeSpan);
        }
        public void progress_time_span_reflects_any_progression_through_the_exercise()
        {
            var scheduler = new TestSchedulerService();
            var model = new ExerciseBuilder()
                .Build();
            var executionContext = new ExecutionContext();
            var sut = new ExerciseViewModelBuilder()
                .WithSchedulerService(scheduler)
                .WithExecutionContext(executionContext)
                .WithModel(model)
                .Build();

            executionContext.SetCurrentExercise(model);

            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.Zero, sut.ProgressTimeSpan);

            executionContext.AddProgress(TimeSpan.FromSeconds(3));
            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.FromSeconds(3), sut.ProgressTimeSpan);

            executionContext.AddProgress(TimeSpan.FromSeconds(2));
            scheduler.AdvanceMinimal();
            Assert.Equal(TimeSpan.FromSeconds(5), sut.ProgressTimeSpan);
        }