コード例 #1
0
        public async Task NumberPromptRetry()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new NumberPrompt <int>(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new PromptOptions
                    {
                        PromptString      = "Enter a number.",
                        RetryPromptString = "You must enter a number."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var numberResult = (NumberResult <int>)dialogCompletion.Result;
                    await turnContext.SendActivity($"Bot received the number '{numberResult.Value}'.");
                }
            })
            .Send("hello")
            .AssertReply("Enter a number.")
            .Send("hello")
            .AssertReply("You must enter a number.")
            .Send("64")
            .AssertReply("Bot received the number '64'.")
            .StartTest();
        }
コード例 #2
0
ファイル: NumberPromptTest.cs プロジェクト: lulzzz/ImageHunt
        public async Task ContinueCallPromptResult()
        {
            // Arrange
            var target1  = new NumberPrompt <int>("", async(turnContext, o) => Check.That(o).Equals(15), null);
            var context  = A.Fake <ITurnContext>();
            var activity = new Activity()
            {
                ActivityType = ActivityType.Message, Text = "15"
            };

            A.CallTo(() => context.Activity).Returns(activity);
            // Act
            await target1.Continue(context);

            // Assert
        }
コード例 #3
0
        public async Task NumberPromptValidator()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            PromptValidator <NumberResult <int> > validator = async(ctx, result) =>
            {
                if (result.Value < 0)
                {
                    result.Status = PromptStatus.TooSmall;
                }
                if (result.Value > 100)
                {
                    result.Status = PromptStatus.TooBig;
                }
                await Task.CompletedTask;
            };

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new NumberPrompt <int>(Culture.English, validator);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new PromptOptions
                    {
                        PromptString      = "Enter a number.",
                        RetryPromptString = "You must enter a positive number less than 100."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var numberResult = (NumberResult <int>)dialogCompletion.Result;
                    await turnContext.SendActivity($"Bot received the number '{numberResult.Value}'.");
                }
            })
            .Send("hello")
            .AssertReply("Enter a number.")
            .Send("150")
            .AssertReply("You must enter a positive number less than 100.")
            .Send("64")
            .AssertReply("Bot received the number '64'.")
            .StartTest();
        }
コード例 #4
0
ファイル: NumberPromptTest.cs プロジェクト: lulzzz/ImageHunt
        public async Task ContinueGetValue()
        {
            // Arrange
            var target1  = new NumberPrompt <int>("", null, null);
            var target2  = new NumberPrompt <double>("", null, null);
            var context  = A.Fake <ITurnContext>();
            var activity = new Activity()
            {
                ActivityType = ActivityType.Message, Text = "15"
            };

            A.CallTo(() => context.Activity).Returns(activity);
            // Act
            await target1.Continue(context);

            await target2.Continue(context);

            // Assert
            Check.That(target1.Value).Equals(15);
            Check.That(target2.Value).Equals(15.0);
        }