public async Task ShouldRecognizeAChoice() { 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 ChoicePrompt(Culture.English); prompt.Style = ListStyle.None; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptString = "favorite color?", Choices = ChoiceFactory.ToChoices(colorChoices) }); } else if (dialogCompletion.IsCompleted) { var choiceResult = (ChoiceResult)dialogCompletion.Result; await turnContext.SendActivity($"{choiceResult.Value.Value}"); } }) .Send("hello") .AssertReply(StartsWithValidator("favorite color?")) .Send("red") .AssertReply("red") .StartTest(); }
public async Task ShouldSendPromptAsAnInlineList() { 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 ChoicePrompt(Culture.English); prompt.Style = ListStyle.Inline; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptString = "favorite color?", Choices = ChoiceFactory.ToChoices(colorChoices) }); } }) .Send("hello") .AssertReply("favorite color? (1) red, (2) green, or (3) blue") .StartTest(); }
public async Task ShouldSendActivityBasedPromptWithSsml() { 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 ChoicePrompt(Culture.English); var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { // TODO: the current model adds the Speak to the activity - that seem surprising (and unnecessary) PromptActivity = MessageFactory.Text("test"), Speak = "spoken test" }); } }) .Send("hello") .AssertReply(SpeakValidator("test", "spoken test")) .StartTest(); }
public async Task ShouldSendActivityBasedPrompt() { 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 ChoicePrompt(Culture.English); prompt.Style = ListStyle.None; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptActivity = MessageFactory.Text("test"), Choices = ChoiceFactory.ToChoices(colorChoices) }); } }) .Send("hello") .AssertReply("test") .StartTest(); }
public async Task ShouldSendPromptWithoutAddingAListButAddingSsml() { 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 ChoicePrompt(Culture.English); prompt.Style = ListStyle.None; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptString = "favorite color?", Speak = "spoken prompt", Choices = ChoiceFactory.ToChoices(colorChoices) }); } }) .Send("hello") .AssertReply(SpeakValidator("favorite color?", "spoken prompt")) .StartTest(); }
public async Task ShouldCallCustomValidator() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); PromptValidator <ChoiceResult> validator = (ITurnContext context, ChoiceResult result) => { // TODO: the current model has no way for this status to bubble up result.Status = "validation failed"; result.Value = null; return(Task.CompletedTask); }; await new TestFlow(adapter, async(turnContext) => { var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var prompt = new ChoicePrompt(Culture.English, validator); prompt.Style = ListStyle.None; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptString = "favorite color?", Choices = ChoiceFactory.ToChoices(colorChoices) }); } else if (dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { if (dialogCompletion.Result == null) { await turnContext.SendActivity("validation failed"); } } }) .Send("hello") .AssertReply(StartsWithValidator("favorite color?")) .Send("I'll take the red please.") .AssertReply("validation failed") .StartTest(); }
public async Task ShouldHandleAnUndefinedRequest() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); PromptValidator <ChoiceResult> validator = (ITurnContext context, ChoiceResult result) => { Assert.IsTrue(false); return(Task.CompletedTask); }; await new TestFlow(adapter, async(turnContext) => { var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var prompt = new ChoicePrompt(Culture.English, validator); prompt.Style = ListStyle.None; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptString = "favorite color?", Choices = ChoiceFactory.ToChoices(colorChoices) }); } else if (dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { if (dialogCompletion.Result == null) { await turnContext.SendActivity("NotRecognized"); } } }) .Send("hello") .AssertReply(StartsWithValidator("favorite color?")) .Send("value shouldn't have been recognized.") .AssertReply("NotRecognized") .StartTest(); }
public async Task ShouldSendPromptUsingSuggestedActions() { 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 ChoicePrompt(Culture.English); prompt.Style = ListStyle.SuggestedAction; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptString = "favorite color?", Choices = ChoiceFactory.ToChoices(colorChoices) }); } }) .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(); }
public async Task ShouldNOTrecognizeOtherText() { 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 ChoicePrompt(Culture.English); prompt.Style = ListStyle.None; var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new ChoicePromptOptions { PromptString = "favorite color?", Choices = ChoiceFactory.ToChoices(colorChoices) }); } // TODO: this is a very awkward way to check for failure in the current model else if (dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { if (dialogCompletion.Result == null) { await turnContext.SendActivity("NotRecognized"); } } }) .Send("hello") .AssertReply(StartsWithValidator("favorite color?")) .Send("what was that?") .AssertReply("NotRecognized") .StartTest(); }