public TestLocale( PromptCultureModel cultureModel, string expectedPrompt = null, string inputThatResultsInOne = null, string inputThatResultsInZero = null) { if (cultureModel.Locale.Length != 5) { throw new ArgumentException("validLocale must be in format: es-es"); } Culture = cultureModel; ValidLocale = cultureModel.Locale.ToString().ToLower(); ExpectedPrompt = expectedPrompt; InputThatResultsInOne = inputThatResultsInOne; InputThatResultsInZero = inputThatResultsInZero; // es-ES CapEnding = GetCapEnding(ValidLocale); // es-Es TitleEnding = GetTitleEnding(ValidLocale); // ES CapTwoLetter = GetCapTwoLetter(ValidLocale); // es LowerTwoLetter = GetLowerTwoLetter(ValidLocale); }
public void ShouldReturnAllSupportedCultures() { var expected = new PromptCultureModel[] { Bulgarian, Chinese, Dutch, English, French, German, Hindi, Italian, Japanese, Korean, Portuguese, Spanish, Swedish, Turkish }; var supportedCultures = GetSupportedCultures(); Assert.True(expected.All(expectedCulture => { return(supportedCultures.Any(supportedCulture => expectedCulture.Locale == supportedCulture.Locale)); })); Assert.True(supportedCultures.All(supportedCulture => { return(expected.Any(expectedCulture => supportedCulture.Locale == expectedCulture.Locale)); })); }
public async Task ShouldAcceptAndRecognizeCustomLocaleDict() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); // Create new DialogSet. var dialogs = new DialogSet(dialogState); var culture = new PromptCultureModel() { InlineOr = " customOr ", InlineOrMore = " customOrMore ", Locale = "custom-custom", Separator = "customSeparator", NoInLanguage = "customNo", YesInLanguage = "customYes", }; var customDict = new Dictionary <string, ChoiceFactoryOptions>() { { culture.Locale, new ChoiceFactoryOptions(culture.Separator, culture.InlineOr, culture.InlineOrMore, true) }, }; dialogs.Add(new ChoicePrompt("ChoicePrompt", customDict, null, culture.Locale)); var helloLocale = MessageFactory.Text("hello"); helloLocale.Locale = culture.Locale; 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) { await dc.PromptAsync( "ChoicePrompt", new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "favorite color?", Locale = culture.Locale }, Choices = _colorChoices, }, cancellationToken); } }) .Send(helloLocale) .AssertReply((activity) => { // Use ChoiceFactory to build the expected answer, manually var expectedChoices = ChoiceFactory.Inline(_colorChoices, null, null, new ChoiceFactoryOptions() { InlineOr = culture.InlineOr, InlineOrMore = culture.InlineOrMore, InlineSeparator = culture.Separator, }).Text; Assert.AreEqual($"favorite color?{expectedChoices}", activity.AsMessageActivity().Text); }) .StartTestAsync(); }
public async Task ConfirmPrompt_Locale_Override_ChoiceDefaults(string activityLocale, string defaultLocale, string prompt, string utterance, string expectedResponse) { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); // Create new DialogSet. var dialogs = new DialogSet(dialogState); var culture = new PromptCultureModel() { InlineOr = " customOr ", InlineOrMore = " customOrMore ", Locale = "custom-custom", Separator = "customSeparator", NoInLanguage = "customNo", YesInLanguage = "customYes", }; var customDict = new Dictionary <string, (Choice, Choice, ChoiceFactoryOptions)>() { { culture.Locale, (new Choice(culture.YesInLanguage), new Choice(culture.NoInLanguage), new ChoiceFactoryOptions(culture.Separator, culture.InlineOr, culture.InlineOrMore, true)) }, }; // Prompt should default to English if locale is a non-supported value dialogs.Add(new ConfirmPrompt("ConfirmPrompt", customDict, null, defaultLocale)); await new TestFlow(adapter, async(turnContext, cancellationToken) => { turnContext.Activity.Locale = culture.Locale; var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); var results = await dc.ContinueDialogAsync(cancellationToken); if (results.Status == DialogTurnStatus.Empty) { await dc.PromptAsync("ConfirmPrompt", new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "Prompt." } }, cancellationToken); } else if (results.Status == DialogTurnStatus.Complete) { if ((bool)results.Result) { await turnContext.SendActivityAsync(MessageFactory.Text("1"), cancellationToken); } else { await turnContext.SendActivityAsync(MessageFactory.Text("0"), cancellationToken); } } }) .Send("hello") .AssertReply("Prompt. " + prompt) .Send(utterance) .AssertReply(expectedResponse) .StartTestAsync(); }