예제 #1
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]);
        }
예제 #2
0
        public void execute_async_throws_if_the_context_is_null()
        {
            var sut = new WaitWithPromptActionBuilder()
                      .Build();

            Assert.Throws <ArgumentNullException>(() => sut.ExecuteAsync(null));
        }
        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_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_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_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();
        }