Ejemplo n.º 1
0
        public async Task ShouldNOTrecognizeOtherText()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

            await new TestFlow(adapter, async(context) =>
            {
                var state = ConversationState <TestState> .Get(context);

                var choicePrompt = new ChoicePrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await choicePrompt.Prompt(context, colorChoices, "favorite color?");
                }
                else
                {
                    var choiceResult = await choicePrompt.Recognize(context, colorChoices);
                    if (choiceResult.Succeeded())
                    {
                        await context.SendActivity(choiceResult.Value.Value.ToString());
                    }
                    else
                    {
                        await context.SendActivity(choiceResult.Status);
                    }
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("what was that?")
            .AssertReply("NotRecognized")
            .StartTest();
        }
Ejemplo n.º 2
0
 public async Task ShouldSendPromptUsingSuggestedActions()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.SuggestedAction;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply(SuggestedActionsValidator("favorite color?",
                                            new SuggestedActions
     {
         Actions = new List <CardAction>
         {
             new CardAction {
                 Type = "imBack", Value = "red", Title = "red"
             },
             new CardAction {
                 Type = "imBack", Value = "green", Title = "green"
             },
             new CardAction {
                 Type = "imBack", Value = "blue", Title = "blue"
             },
         }
     }))
     .StartTest();
 }
Ejemplo n.º 3
0
 public async Task ShouldSendPrompt()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt = new ChoicePrompt(Culture.English);
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply(StartsWithValidator("favorite color?"))
     .StartTest();
 }
Ejemplo n.º 4
0
 public async Task ShouldSendActivityBasedPromptWithSsml()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt = new ChoicePrompt(Culture.English);
         await choicePrompt.Prompt(context, MessageFactory.Text("test"), "spoken test");
     })
     .Send("hello")
     .AssertReply(SpeakValidator("test", "spoken test"))
     .StartTest();
 }
Ejemplo n.º 5
0
 public async Task ShouldSendPromptAsANumberedList()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.List;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply("favorite color?\n\n   1. red\n   2. green\n   3. blue")
     .StartTest();
 }
Ejemplo n.º 6
0
 public async Task ShouldSendPromptAsAnInlineList()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.Inline;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply("favorite color? (1) red, (2) green, or (3) blue")
     .StartTest();
 }
Ejemplo n.º 7
0
 public async Task ShouldSendPromptWithoutAddingAListButAddingSsml()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.None;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?", "spoken prompt");
     })
     .Send("hello")
     .AssertReply(SpeakValidator("favorite color?", "spoken prompt"))
     .StartTest();
 }
Ejemplo n.º 8
0
        public async Task ShouldCallCustomValidator()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

            PromptValidator <ChoiceResult> validator = (ITurnContext context, ChoiceResult result) =>
            {
                result.Status = "validation failed";
                result.Value  = null;
                return(Task.CompletedTask);
            };

            await new TestFlow(adapter, async(context) =>
            {
                var state = ConversationState <TestState> .Get(context);

                var choicePrompt = new ChoicePrompt(Culture.English, validator);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await choicePrompt.Prompt(context, colorChoices, "favorite color?");
                }
                else
                {
                    var choiceResult = await choicePrompt.Recognize(context, colorChoices);
                    if (choiceResult.Succeeded())
                    {
                        await context.SendActivity(choiceResult.Value.Value.ToString());
                    }
                    else
                    {
                        await context.SendActivity(choiceResult.Status);
                    }
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("I'll take the red please.")
            .AssertReply("validation failed")
            .StartTest();
        }
Ejemplo n.º 9
0
        public async Task ShouldHandleAnUndefinedRequest()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

            PromptValidator <ChoiceResult> validator = (ITurnContext context, ChoiceResult result) =>
            {
                Assert.IsTrue(false);
                return(Task.CompletedTask);
            };

            await new TestFlow(adapter, async(context) =>
            {
                var state = ConversationState <TestState> .Get(context);

                var choicePrompt = new ChoicePrompt(Culture.English, validator);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await choicePrompt.Prompt(context, colorChoices, "favorite color?");
                }
                else
                {
                    var choiceResult = await choicePrompt.Recognize(context, colorChoices);
                    if (choiceResult.Succeeded())
                    {
                        await context.SendActivity(choiceResult.Value.Value.ToString());
                    }
                    else
                    {
                        await context.SendActivity(choiceResult.Status);
                    }
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("value shouldn't have been recognized.")
            .AssertReply("NotRecognized")
            .StartTest();
        }