public async Task TextPrompt() { ConversationState convoState = new ConversationState(new MemoryStorage()); var testProperty = convoState.CreateProperty("test", () => new Dictionary <string, object>()); TestAdapter adapter = new TestAdapter() .Use(convoState); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var state = await testProperty.GetAsync(turnContext); var prompt = new TextPrompt(); var dialogCompletion = await prompt.ContinueAsync(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.BeginAsync(turnContext, state, new PromptOptions { PromptString = "Enter some text." }); } else if (dialogCompletion.IsCompleted) { var textResult = (TextResult)dialogCompletion.Result; await turnContext.SendActivityAsync($"Bot received the text '{textResult.Value}'."); } }) .Send("hello") .AssertReply("Enter some text.") .Send("some text") .AssertReply("Bot received the text 'some text'.") .StartTestAsync(); }
public async Task TextPromptValidator() { ConversationState convoState = new ConversationState(new MemoryStorage()); var testProperty = convoState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>()); TestAdapter adapter = new TestAdapter() .Use(convoState); PromptValidator <TextResult> validator = async(ctx, result) => { if (result.Value.Length <= 3) { result.Status = PromptStatus.TooSmall; } await Task.CompletedTask; }; await new TestFlow(adapter, async(turnContext, cancellationToken) => { var state = await testProperty.GetAsync(turnContext); var prompt = new TextPrompt(validator); var dialogCompletion = await prompt.ContinueAsync(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.BeginAsync(turnContext, state, new PromptOptions { PromptString = "Enter some text.", RetryPromptString = "Make sure the text is greater than three characters." }); } else if (dialogCompletion.IsCompleted) { var textResult = (TextResult)dialogCompletion.Result; await turnContext.SendActivityAsync($"Bot received the text '{textResult.Value}'."); } }) .Send("hello") .AssertReply("Enter some text.") .Send("hi") .AssertReply("Make sure the text is greater than three characters.") .Send("hello") .AssertReply("Bot received the text 'hello'.") .StartTestAsync(); }
public async Task TextPrompt() { var activities = TranscriptUtilities.GetFromTestContext(TestContext); PromptValidatorEx.PromptValidator <TextResult> validator = async(ctx, result) => { if (result.Value.Length <= 3) { result.Status = PromptStatus.TooSmall; } await Task.CompletedTask; }; var convState = new ConversationState(new MemoryStorage()); var testProperty = convState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>()); TestAdapter adapter = new TestAdapter() .Use(convState); await new TestFlow(adapter, async(turnContext) => { if (turnContext.Activity.Type == ActivityTypes.Message) { var state = await testProperty.GetAsync(turnContext); var prompt = new TextPrompt(validator); var dialogCompletion = await prompt.ContinueAsync(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.BeginAsync(turnContext, state, new PromptOptions { PromptString = "Enter some text.", RetryPromptString = "Make sure the text is greater than three characters." }); } else if (dialogCompletion.IsCompleted) { var textResult = (TextResult)dialogCompletion.Result; await turnContext.SendActivityAsync($"Bot received the text '{textResult.Value}'."); } } }) .Test(activities) .StartTestAsync(); }