public void execute_composes_actions_appropriately_for_short_durations()
        {
            var delayService     = new DelayServiceMock();
            var speechService    = new SpeechServiceMock();
            var performedActions = new List <string>();

            delayService
            .When(x => x.Delay(It.IsAny <TimeSpan>()))
            .Do <TimeSpan>(duration => performedActions.Add("Delayed for " + duration))
            .Return(Observable.Return(Unit.Default));

            speechService
            .When(x => x.Speak(It.IsAny <string>()))
            .Do <string>(speechText => performedActions.Add("Saying '" + speechText + "'"))
            .Return(Observable.Return(Unit.Default));

            var sut = new WaitWithPromptActionBuilder()
                      .WithDelayService(delayService)
                      .WithSpeechService(speechService)
                      .WithDuration(TimeSpan.FromSeconds(1))
                      .WithPromptSpeechText("break")
                      .Build();

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

            Assert.Equal(2, performedActions.Count);
            Assert.Equal("Saying 'break'", performedActions[0]);
            Assert.Equal("Delayed for 00:00:01", performedActions[1]);
        }
Пример #2
0
        public void execute_async_composes_actions_appropriately_for_long_durations()
        {
            var delayService     = new DelayServiceMock();
            var speechService    = new SpeechServiceMock();
            var performedActions = new List <string>();

            delayService
            .When(x => x.DelayAsync(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()))
            .Do <TimeSpan, CancellationToken>((duration, ct) => performedActions.Add("Delayed for " + duration))
            .Return(Observable.Return(Unit.Default));

            speechService
            .When(x => x.SpeakAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Do <string, CancellationToken>((speechText, cty) => performedActions.Add("Saying '" + speechText + "'"))
            .Return(Observable.Return(Unit.Default));

            var sut = new WaitWithPromptActionBuilder()
                      .WithDelayService(delayService)
                      .WithSpeechService(speechService)
                      .WithDuration(TimeSpan.FromSeconds(5))
                      .WithPromptSpeechText("break")
                      .Build();

            sut.ExecuteAsync(new ExecutionContext());

            Assert.Equal(7, performedActions.Count);
            Assert.Equal("Saying 'break'", performedActions[0]);
            Assert.Equal("Delayed for 00:00:01", performedActions[1]);
            Assert.Equal("Delayed for 00:00:01", performedActions[2]);
            Assert.Equal("Delayed for 00:00:01", performedActions[3]);
            Assert.Equal("Saying 'ready?'", performedActions[4]);
            Assert.Equal("Delayed for 00:00:01", performedActions[5]);
            Assert.Equal("Delayed for 00:00:01", performedActions[6]);
        }
        public void execute_async_says_exercise_name_first()
        {
            var speechService = new SpeechServiceMock(MockBehavior.Loose);
            var sut           = new ExerciseBuilder()
                                .WithName("some name")
                                .WithSpeechService(speechService)
                                .Build();

            sut.ExecuteAsync(new ExecutionContext());

            speechService
            .Verify(x => x.SpeakAsync("some name", It.IsAny <CancellationToken>()))
            .WasCalledExactlyOnce();
        }
Пример #4
0
        public void execute_passes_the_speech_text_onto_the_speech_service(string speechText)
        {
            var speechService = new SpeechServiceMock(MockBehavior.Loose);
            var sut           = new SayActionBuilder()
                                .WithSpeechService(speechService)
                                .WithSpeechText(speechText)
                                .Build();

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

            speechService
            .Verify(x => x.Speak(speechText))
            .WasCalledExactlyOnce();
        }
Пример #5
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();
        }
        public void execute_async_passes_the_speech_text_onto_the_speech_service(string speechText)
        {
            var speechService = new SpeechServiceMock(MockBehavior.Loose);
            var sut           = new SayActionBuilder()
                                .WithSpeechService(speechService)
                                .WithSpeechText(speechText)
                                .Build();

            sut.ExecuteAsync(new ExecutionContext());

            speechService
            .Verify(x => x.SpeakAsync(speechText, It.IsAny <CancellationToken>()))
            .WasCalledExactlyOnce();
        }
Пример #7
0
        public void execute_async_uses_the_specified_prompt_speech_text(string promptSpeechText)
        {
            var speechService = new SpeechServiceMock(MockBehavior.Loose);

            var sut = new WaitWithPromptActionBuilder()
                      .WithSpeechService(speechService)
                      .WithDuration(TimeSpan.FromSeconds(1))
                      .WithPromptSpeechText(promptSpeechText)
                      .Build();

            sut.ExecuteAsync(new ExecutionContext());

            speechService
            .Verify(x => x.SpeakAsync(promptSpeechText, It.IsAny <CancellationToken>()))
            .WasCalledExactlyOnce();
        }
Пример #8
0
        public void execute_pauses_if_context_is_paused()
        {
            var speechService = new SpeechServiceMock(MockBehavior.Loose);
            var sut           = new SayActionBuilder()
                                .WithSpeechService(speechService)
                                .Build();

            using (var context = new ExecutionContext())
            {
                context.IsPaused = true;

                sut.Execute(context).Subscribe();

                speechService
                .Verify(x => x.Speak(It.IsAny <string>()))
                .WasNotCalled();
            }
        }