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_throws_if_the_context_is_null()
        {
            var sut = new WaitWithPromptActionBuilder()
                .Build();

            Assert.Throws<ArgumentNullException>(() => sut.ExecuteAsync(null));
        }
예제 #4
0
        public void execute_async_throws_if_the_context_is_null()
        {
            var sut = new WaitWithPromptActionBuilder()
                      .Build();

            Assert.Throws <ArgumentNullException>(() => sut.ExecuteAsync(null));
        }
        public void duration_yields_the_duration_passed_into_ctor(int durationInMs)
        {
            var sut = new WaitWithPromptActionBuilder()
                      .WithDuration(TimeSpan.FromMilliseconds(durationInMs))
                      .Build();

            Assert.Equal(TimeSpan.FromMilliseconds(durationInMs), sut.Duration);
        }
        public void duration_yields_the_duration_passed_into_ctor(int durationInMs)
        {
            var sut = new WaitWithPromptActionBuilder()
                .WithDuration(TimeSpan.FromMilliseconds(durationInMs))
                .Build();

            Assert.Equal(TimeSpan.FromMilliseconds(durationInMs), sut.Duration);
        }
예제 #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();
        }
        public void execute_composes_actions_appropriately_for_long_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(5))
                .WithPromptSpeechText("break")
                .Build();

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

            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_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();
        }
        public void execute_async_composes_actions_appropriately_for_short_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(1))
                .WithPromptSpeechText("break")
                .Build();

            sut.ExecuteAsync(new ExecutionContext());

            Assert.Equal(2, performedActions.Count);
            Assert.Equal("Saying 'break'", performedActions[0]);
            Assert.Equal("Delayed for 00:00:01", performedActions[1]);
        }