Exemplo n.º 1
0
        public void execute_skips_actions_that_are_shorter_than_the_skip_ahead_even_if_the_context_is_paused()
        {
            var action1       = new ActionMock(MockBehavior.Loose);
            var action2       = new ActionMock(MockBehavior.Loose);
            var action3       = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            action1
            .When(x => x.Duration)
            .Return(TimeSpan.FromSeconds(10));

            action2
            .When(x => x.Duration)
            .Return(TimeSpan.FromSeconds(3));

            action3
            .When(x => x.Duration)
            .Return(TimeSpan.FromSeconds(1));

            action1
            .When(x => x.Execute(It.IsAny <ExecutionContext>()))
            .Throw();

            action2
            .When(x => x.Execute(It.IsAny <ExecutionContext>()))
            .Throw();

            eventMatcher1
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher3
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                      .WithMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                      .WithMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                      .WithMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                      .Build();
            var executionContext = new ExecutionContext(TimeSpan.FromSeconds(13));

            executionContext.IsPaused = true;
            sut
            .Execute(executionContext)
            .Subscribe();

            action3
            .Verify(x => x.Execute(executionContext))
            .WasCalledExactlyOnce();
        }
Exemplo n.º 2
0
        public void execute_updates_the_current_exercise_in_the_context()
        {
            var sut = new ExerciseBuilder()
                      .Build();
            var context = new ExecutionContext();

            sut.Execute(context).Subscribe();

            Assert.Same(sut, context.CurrentExercise);
        }
Exemplo n.º 3
0
        public void execute_completes_even_if_there_are_no_actions()
        {
            var sut = new ExerciseBuilder()
                      .Build();
            var executionContext = new ExecutionContext();

            var completed = false;

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

            Assert.True(completed);
        }
Exemplo n.º 4
0
        public void execute_says_exercise_name_first()
        {
            var speechService = new SpeechServiceMock(MockBehavior.Loose);
            var sut           = new ExerciseBuilder()
                                .WithName("some name")
                                .WithSpeechService(speechService)
                                .Build();

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

            speechService
            .Verify(x => x.Speak("some name"))
            .WasCalledExactlyOnce();
        }
Exemplo n.º 5
0
        public void execute_executes_all_appropriate_actions()
        {
            var action1       = new ActionMock(MockBehavior.Loose);
            var action2       = new ActionMock(MockBehavior.Loose);
            var action3       = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            eventMatcher1
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is DuringRepetitionEvent);

            eventMatcher3
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is AfterSetEvent);

            var sut = new ExerciseBuilder()
                      .WithSetCount(2)
                      .WithRepetitionCount(3)
                      .WithMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                      .WithMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                      .WithMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                      .Build();
            var executionContext = new ExecutionContext();

            sut
            .Execute(executionContext)
            .Subscribe();

            action1
            .Verify(x => x.Execute(executionContext))
            .WasCalledExactlyOnce();

            action2
            .Verify(x => x.Execute(executionContext))
            .WasCalledExactly(times: 6);

            action3
            .Verify(x => x.Execute(executionContext))
            .WasCalledExactly(times: 2);
        }
Exemplo n.º 6
0
        public void execute_updates_the_current_set_in_the_context()
        {
            var sut = new ExerciseBuilder()
                      .WithSetCount(3)
                      .Build();
            var context     = new ExecutionContext();
            var currentSets = context
                              .ObservableForProperty(x => x.CurrentSet)
                              .Select(x => x.Value)
                              .CreateCollection();

            sut.Execute(context).Subscribe();

            Assert.Equal(3, currentSets.Count);
            Assert.Equal(1, currentSets[0]);
            Assert.Equal(2, currentSets[1]);
            Assert.Equal(3, currentSets[2]);
        }
Exemplo n.º 7
0
        public void execute_updates_the_current_repetitions_in_the_context()
        {
            var sut = new ExerciseBuilder()
                      .WithRepetitionCount(5)
                      .Build();
            var context            = new ExecutionContext();
            var currentRepetitions = context
                                     .ObservableForProperty(x => x.CurrentRepetition)
                                     .Select(x => x.Value)
                                     .CreateCollection();

            sut.Execute(context).Subscribe();

            Assert.Equal(5, currentRepetitions.Count);
            Assert.Equal(1, currentRepetitions[0]);
            Assert.Equal(2, currentRepetitions[1]);
            Assert.Equal(3, currentRepetitions[2]);
            Assert.Equal(4, currentRepetitions[3]);
            Assert.Equal(5, currentRepetitions[4]);
        }
Exemplo n.º 8
0
        public void execute_does_not_skip_zero_duration_actions()
        {
            var action       = new ActionMock(MockBehavior.Loose);
            var eventMatcher = new EventMatcherMock();

            eventMatcher
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                      .WithMatcherWithAction(new MatcherWithAction(eventMatcher, action))
                      .Build();
            var executionContext = new ExecutionContext();

            sut
            .Execute(executionContext)
            .Subscribe();

            action
            .Verify(x => x.Execute(executionContext))
            .WasCalledExactlyOnce();
        }
Exemplo n.º 9
0
        public void execute_says_exercise_name_first()
        {
            var speechService = new SpeechServiceMock(MockBehavior.Loose);
            var sut = new ExerciseBuilder()
                .WithName("some name")
                .WithSpeechService(speechService)
                .Build();

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

            speechService
                .Verify(x => x.Speak("some name"))
                .WasCalledExactlyOnce();
        }
Exemplo n.º 10
0
        public void execute_updates_the_current_set_in_the_context()
        {
            var sut = new ExerciseBuilder()
                .WithSetCount(3)
                .Build();
            var context = new ExecutionContext();
            var currentSets = context
                .ObservableForProperty(x => x.CurrentSet)
                .Select(x => x.Value)
                .CreateCollection();

            sut.Execute(context).Subscribe();

            Assert.Equal(3, currentSets.Count);
            Assert.Equal(1, currentSets[0]);
            Assert.Equal(2, currentSets[1]);
            Assert.Equal(3, currentSets[2]);
        }
Exemplo n.º 11
0
        public void execute_updates_the_current_repetitions_in_the_context()
        {
            var sut = new ExerciseBuilder()
                .WithRepetitionCount(5)
                .Build();
            var context = new ExecutionContext();
            var currentRepetitions = context
                .ObservableForProperty(x => x.CurrentRepetition)
                .Select(x => x.Value)
                .CreateCollection();

            sut.Execute(context).Subscribe();

            Assert.Equal(5, currentRepetitions.Count);
            Assert.Equal(1, currentRepetitions[0]);
            Assert.Equal(2, currentRepetitions[1]);
            Assert.Equal(3, currentRepetitions[2]);
            Assert.Equal(4, currentRepetitions[3]);
            Assert.Equal(5, currentRepetitions[4]);
        }
Exemplo n.º 12
0
        public void execute_updates_the_current_exercise_in_the_context()
        {
            var sut = new ExerciseBuilder()
                .Build();
            var context = new ExecutionContext();

            sut.Execute(context).Subscribe();

            Assert.Same(sut, context.CurrentExercise);
        }
Exemplo n.º 13
0
        public void execute_skips_actions_that_are_shorter_than_the_skip_ahead_even_if_the_context_is_paused()
        {
            var action1 = new ActionMock(MockBehavior.Loose);
            var action2 = new ActionMock(MockBehavior.Loose);
            var action3 = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            action1
                .When(x => x.Duration)
                .Return(TimeSpan.FromSeconds(10));

            action2
                .When(x => x.Duration)
                .Return(TimeSpan.FromSeconds(3));

            action3
                .When(x => x.Duration)
                .Return(TimeSpan.FromSeconds(1));

            action1
                .When(x => x.Execute(It.IsAny<ExecutionContext>()))
                .Throw();

            action2
                .When(x => x.Execute(It.IsAny<ExecutionContext>()))
                .Throw();

            eventMatcher1
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher3
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                .Build();

            using (var executionContext = new ExecutionContext(TimeSpan.FromSeconds(13)))
            {
                executionContext.IsPaused = true;
                sut.Execute(executionContext).Subscribe();

                action3
                    .Verify(x => x.Execute(executionContext))
                    .WasCalledExactlyOnce();
            }
        }
Exemplo n.º 14
0
        public void execute_does_not_skip_zero_duration_actions()
        {
            var action = new ActionMock(MockBehavior.Loose);
            var eventMatcher = new EventMatcherMock();

            eventMatcher
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher, action))
                .Build();

            using (var executionContext = new ExecutionContext())
            {
                sut.Execute(executionContext).Subscribe();

                action
                    .Verify(x => x.Execute(executionContext))
                    .WasCalledExactlyOnce();
            }
        }
Exemplo n.º 15
0
        public void execute_executes_all_appropriate_actions()
        {
            var action1 = new ActionMock(MockBehavior.Loose);
            var action2 = new ActionMock(MockBehavior.Loose);
            var action3 = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            eventMatcher1
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is DuringRepetitionEvent);

            eventMatcher3
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is AfterSetEvent);

            var sut = new ExerciseBuilder()
                .WithSetCount(2)
                .WithRepetitionCount(3)
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                .Build();

            using (var executionContext = new ExecutionContext())
            {
                sut.Execute(executionContext).Subscribe();

                action1
                    .Verify(x => x.Execute(executionContext))
                    .WasCalledExactlyOnce();

                action2
                    .Verify(x => x.Execute(executionContext))
                    .WasCalledExactly(times: 6);

                action3
                    .Verify(x => x.Execute(executionContext))
                    .WasCalledExactly(times: 2);
            }
        }
Exemplo n.º 16
0
        public void execute_completes_even_if_there_are_no_actions()
        {
            var sut = new ExerciseBuilder()
                .Build();

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

                Assert.True(completed);
            }
        }