public async Task BasicDateTimePrompt()
        {
            ConversationState convoState = new ConversationState(new MemoryStorage());
            var testProperty             = convoState.CreateProperty <Dictionary <string, object> >("test");

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var state  = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                var prompt = new DateTimePrompt(Culture.English);

                var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.BeginAsync(turnContext, state, new PromptOptions {
                        PromptString = "What date would you like?"
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var dateTimeResult = (DateTimeResult)dialogCompletion.Result;
                    var resolution     = dateTimeResult.Resolution.First();
                    var reply          = $"Timex:'{resolution.Timex}' Value:'{resolution.Value}'";
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("5th December 2018 at 9am")
            .AssertReply("Timex:'2018-12-05T09' Value:'2018-12-05 09:00:00'")
            .StartTestAsync();
        }
        public async Task MultipleResolutionsDateTimePrompt()
        {
            ConversationState convoState = new ConversationState(new MemoryStorage());
            var testProperty             = convoState.CreateProperty <Dictionary <string, object> >("test");

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var state  = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                var prompt = new DateTimePrompt(Culture.English);

                var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.BeginAsync(turnContext, state, new PromptOptions {
                        PromptString = "What date would you like?"
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var dateTimeResult   = (DateTimeResult)dialogCompletion.Result;
                    var timexExpressions = dateTimeResult.Resolution.Select(r => r.Timex).Distinct();
                    var reply            = string.Join(" ", timexExpressions);
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("Wednesday 4 oclock")
            .AssertReply("XXXX-WXX-3T04 XXXX-WXX-3T16")
            .StartTestAsync();
        }
示例#3
0
        public async Task DateTimePrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            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 DateTimePrompt(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "What date would you like?", RetryPromptString = "Sorry, but that is not a date. What date would you like?"
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var dateTimeResult = (DateTimeResult)dialogCompletion.Result;
                    var resolution     = dateTimeResult.Resolution.First();
                    var reply          = $"Timex:'{resolution.Timex}' Value:'{resolution.Value}'";
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
        public void SetDialogConfiguration(DialogSet dialogSet)
        {
            AddPictureOfTheDayDialog(dialogSet);
            AddMarsRoverDataDialog(dialogSet);
            AddAsteroidDataDialog(dialogSet);

            //mars rover date prompt
            DateTimePrompt earthDatePrompt = new DateTimePrompt("EarthDatePrompt", DateValidatorAsync);

            dialogSet.Add(earthDatePrompt);

            NumberPrompt <int> numberOfPicturesPrompt = new NumberPrompt <int>("NumberOfPicturesPrompt", NumberValidatorAsync);

            dialogSet.Add(numberOfPicturesPrompt);

            //asteroid start && end date prompts
            DateTimePrompt startDatePrompt = new DateTimePrompt("StartDatePrompt", DateValidatorAsync);

            dialogSet.Add(startDatePrompt);
            DateTimePrompt endDatePrompt = new DateTimePrompt("EndDatePrompt", DateValidatorAsync);

            dialogSet.Add(endDatePrompt);

            //add choice options dialog
            var choicePrompt = new ChoicePrompt("GetChoices");

            dialogSet.Add(choicePrompt);

            //add generic confirmation dialog
            var confirmationPrompt = new ConfirmPrompt("ConfirmationDialog");

            dialogSet.Add(confirmationPrompt);
        }
示例#5
0
 public async Task DateTimePrompt_ShouldSendPrompt()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var dateTimePrompt = new DateTimePrompt(Culture.English);
         await dateTimePrompt.Prompt(context, "What date would you like?");
     })
     .Send("hello")
     .AssertReply("What date would you like?")
     .StartTest();
 }
示例#6
0
        public async Task MultipleResolutionsDateTimePrompt()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

            TestAdapter adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName))
                                  .Use(new AutoSaveStateMiddleware(convoState))
                                  .Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

            // Create new DialogSet.
            var dialogs = new DialogSet(dialogState);

            // Create and add number prompt to DialogSet.
            var dateTimePrompt = new DateTimePrompt("DateTimePrompt", defaultLocale: Culture.English);

            dialogs.Add(dateTimePrompt);

            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 = "What date would you like?"
                        }
                    };
                    await dc.PromptAsync("DateTimePrompt", options, cancellationToken);
                }
                else if (results.Status == DialogTurnStatus.Complete)
                {
                    var resolutions      = (IList <DateTimeResolution>)results.Result;
                    var timexExpressions = resolutions.Select(r => r.Timex).Distinct();
                    var reply            = MessageFactory.Text(string.Join(" ", timexExpressions));
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("Wednesday 4 oclock")
            .AssertReply("XXXX-WXX-3T04 XXXX-WXX-3T16")
            .StartTestAsync();
        }
示例#7
0
        public async Task DateTimePromptWithValidator()
        {
            string folder      = Environment.CurrentDirectory;
            var    convoState  = new ConversationState(new MemoryStorage());
            var    dialogState = convoState.CreateProperty <DialogState>("dialogState");

            TestAdapter adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName))
                                  .Use(new AutoSaveStateMiddleware(convoState))
                                  .Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

            // Create new DialogSet.
            var dialogs = new DialogSet(dialogState);

            // Create and add number prompt to DialogSet.
            var dateTimePrompt = new DateTimePrompt("DateTimePrompt", CustomValidator, defaultLocale: Culture.English);

            dialogs.Add(dateTimePrompt);

            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 = "What date would you like?"
                        }
                    };
                    await dc.PromptAsync("DateTimePrompt", options, cancellationToken);
                }
                else if (results.Status == DialogTurnStatus.Complete)
                {
                    var resolution = ((IList <DateTimeResolution>)results.Result).First();
                    var reply      = MessageFactory.Text($"Timex:'{resolution.Timex}' Value:'{resolution.Value}'");
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("5th December 2018 at 9am")
            .AssertReply("Timex:'2018-12-05' Value:'2018-12-05'")
            .StartTestAsync();
        }
        public async Task MultipleResolutionsDateTimePrompt()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

            // Create new DialogSet.
            var dialogs = new DialogSet(dialogState);

            // Create and add number prompt to DialogSet.
            var dateTimePrompt = new DateTimePrompt("DateTimePrompt", defaultLocale: Culture.English);

            dialogs.Add(dateTimePrompt);

            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 = "What date would you like?"
                        }
                    };
                    await dc.PromptAsync("DateTimePrompt", options);
                }
                else if (!results.HasActive && results.HasResult)
                {
                    var resolutions      = (IList <DateTimeResolution>)results.Result;
                    var timexExpressions = resolutions.Select(r => r.Timex).Distinct();
                    var reply            = string.Join(" ", timexExpressions);
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("Wednesday 4 oclock")
            .AssertReply("XXXX-WXX-3T04 XXXX-WXX-3T16")
            .StartTestAsync();
        }
        public async Task BasicDateTimePrompt()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

            // Create new DialogSet.
            var dialogs = new DialogSet(dialogState);

            // Create and add number prompt to DialogSet.
            var dateTimePrompt = new DateTimePrompt("DateTimePrompt", defaultLocale: Culture.English);

            dialogs.Add(dateTimePrompt);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken);

                var results = await dc.ContinueAsync();
                if (results.Status == DialogTurnStatus.Empty)
                {
                    var options = new PromptOptions {
                        Prompt = new Activity {
                            Type = ActivityTypes.Message, Text = "What date would you like?"
                        }
                    };
                    await dc.PromptAsync("DateTimePrompt", options, cancellationToken);
                }
                else if (results.Status == DialogTurnStatus.Complete)
                {
                    var resolution = ((IList <DateTimeResolution>)results.Result).First();
                    var reply      = MessageFactory.Text($"Timex:'{resolution.Timex}' Value:'{resolution.Value}'");
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("5th December 2018 at 9am")
            .AssertReply("Timex:'2018-12-05T09' Value:'2018-12-05 09:00:00'")
            .StartTestAsync();
        }
示例#10
0
        public async Task DateTimePrompt_ShouldRecognizeDateTime_CustomValidator()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

            PromptValidator <DateTimeResult> validator = (context, result) =>
            {
                result.Status = PromptStatus.NotRecognized;
                return(Task.CompletedTask);
            };

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

                var dateTimePrompt = new DateTimePrompt(Culture.English, validator);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await dateTimePrompt.Prompt(context, "What date would you like?");
                }
                else
                {
                    var dateTimeResult = await dateTimePrompt.Recognize(context);
                    if (dateTimeResult.Succeeded())
                    {
                        var resolution = dateTimeResult.Resolution.First();
                        var reply      = $"Timex:'{resolution.Timex}' Value:'{resolution.Value}'";
                        await context.SendActivity(reply);
                    }
                    else
                    {
                        await context.SendActivity(dateTimeResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("5th December 2018 at 9am")
            .AssertReply("NotRecognized")
            .StartTest();
        }
示例#11
0
        public async Task DateTimePrompt_ShouldRecognizeDateTime_Range()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

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

                var dateTimePrompt = new DateTimePrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await dateTimePrompt.Prompt(context, "What window would you like to book?");
                }
                else
                {
                    var dateTimeResult = await dateTimePrompt.Recognize(context);
                    if (dateTimeResult.Succeeded())
                    {
                        var resolution = dateTimeResult.Resolution.First();
                        var reply      = $"Timex:'{resolution.Timex}'";
                        await context.SendActivity(reply);
                    }
                    else
                    {
                        await context.SendActivity(dateTimeResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("What window would you like to book?")
            .Send("4pm wednesday to 3pm Saturday")
            .AssertReply("Timex:'(XXXX-WXX-3T16,XXXX-WXX-6T15,PT71H)'")
            .StartTest();
        }
示例#12
0
        public async Task DateTimePrompt_ShouldRecognizeDateTime_Value()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

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

                var dateTimePrompt = new DateTimePrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await dateTimePrompt.Prompt(context, "What date would you like?");
                }
                else
                {
                    var dateTimeResult = await dateTimePrompt.Recognize(context);
                    if (dateTimeResult.Succeeded())
                    {
                        var resolution = dateTimeResult.Resolution.First();
                        var reply      = $"Timex:'{resolution.Timex}' Value:'{resolution.Value}'";
                        await context.SendActivity(reply);
                    }
                    else
                    {
                        await context.SendActivity(dateTimeResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("5th December 2018 at 9am")
            .AssertReply("Timex:'2018-12-05T09' Value:'2018-12-05 09:00:00'")
            .StartTest();
        }
示例#13
0
        public async Task DateTimePrompt_ShouldRecognizeDateTime_StartEnd()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

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

                var dateTimePrompt = new DateTimePrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await dateTimePrompt.Prompt(context, "What month are you interested in?");
                }
                else
                {
                    var dateTimeResult = await dateTimePrompt.Recognize(context);
                    if (dateTimeResult.Succeeded())
                    {
                        var resolution = dateTimeResult.Resolution.First();
                        var reply      = $"Timex:'{resolution.Timex}' Start:'{resolution.Start}' End:'{resolution.End}'";
                        await context.SendActivity(reply);
                    }
                    else
                    {
                        await context.SendActivity(dateTimeResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("What month are you interested in?")
            .Send("May 1967")
            .AssertReply("Timex:'1967-05' Start:'1967-05-01' End:'1967-06-01'")
            .StartTest();
        }