public async Task RetryAttachmentPrompt() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(convoState); var dialogs = new DialogSet(dialogState); var eventPrompt = new EventActivityPrompt("EventActivityPrompt", _validator); dialogs.Add(eventPrompt); var eventActivity = new Activity { Type = ActivityTypes.Event, Value = 2 }; await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext); var results = await dc.ContinueAsync(); if (!turnContext.Responded && !results.HasActive && !results.HasResult) { var options = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "please send an event." } }; await dc.PromptAsync("EventActivityPrompt", options); } else if (!results.HasActive && results.HasResult) { var content = results.Result.ToString(); await turnContext.SendActivityAsync(content); } }) .Send("hello") .AssertReply("please send an event.") .Send("hello again") .AssertReply("Please send an 'event'-type Activity with a value of 2.") .Send(eventActivity) .AssertReply("2") .StartTestAsync(); }
public void ActivityPromptWithEmptyIdShouldFail() { var emptyId = ""; var textPrompt = new EventActivityPrompt(emptyId, _validator); }
public async Task ActivityPromptShouldSendRetryPromptIfValidationFailed() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); var dialogs = new DialogSet(dialogState); PromptValidator <Activity> validator = (prompt, cancellationToken) => { return(Task.FromResult(false)); }; var eventPrompt = new EventActivityPrompt("EventActivityPrompt", validator); dialogs.Add(eventPrompt); var eventActivity = new Activity { Type = ActivityTypes.Event, Value = 2 }; await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); var results = await dc.ContinueDialogAsync(cancellationToken); if (results.Status == DialogTurnStatus.Empty) { var options = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "please send an event.", }, RetryPrompt = new Activity { Type = ActivityTypes.Message, Text = "Retrying - please send an event.", }, }; await dc.PromptAsync("EventActivityPrompt", options); } else if (results.Status == DialogTurnStatus.Complete) { var content = (Activity)results.Result; await turnContext.SendActivityAsync(content, cancellationToken); } else if (results.Status == DialogTurnStatus.Waiting) { await turnContext.SendActivityAsync("Test complete."); } }) .Send("hello") .AssertReply("please send an event.") .Send("test") .AssertReply("Retrying - please send an event.") .StartTestAsync(); }
public async Task ActivityPromptResumeDialogShouldPromptNotRetry() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); var dialogs = new DialogSet(dialogState); var eventPrompt = new EventActivityPrompt("EventActivityPrompt", (prompt, cancellationToken) => Task.FromResult(false)); dialogs.Add(eventPrompt); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); switch (turnContext.Activity.Text) { case "begin": var options = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "please send an event.", }, RetryPrompt = new Activity { Type = ActivityTypes.Message, Text = "Retrying - please send an event.", }, }; await dc.PromptAsync("EventActivityPrompt", options); break; case "continue": await eventPrompt.ContinueDialogAsync(dc); break; case "resume": await eventPrompt.ResumeDialogAsync(dc, DialogReason.NextCalled); break; } }) .Send("begin") .AssertReply("please send an event.") .Send("continue") .AssertReply("Retrying - please send an event.") .Send("resume") // 'ResumeDialogAsync' of ActivityPrompt does NOT cause a Retry .AssertReply("please send an event.") .StartTestAsync(); }
public void ActivityPromptWithEmptyIdShouldFail() { var emptyId = string.Empty; var textPrompt = new EventActivityPrompt(emptyId, Validator); }