public async Task ActivityPromptResumeDialogShouldReturnDialogEndOfTurn()
        {
            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);
                }

                var secondResults = await eventPrompt.ResumeDialogAsync(dc, DialogReason.NextCalled);

                if (secondResults.Status == DialogTurnStatus.Waiting)
                {
                    await turnContext.SendActivityAsync("Test complete.");
                }
            })
            .Send("hello")
            .AssertReply("please send an event.")
            .Send("test")
            .AssertReply("Retrying - please send an event.")
            .AssertReply("Test complete.")
            .StartTestAsync();
        }
Пример #2
0
        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();
        }