public async Task Pizza_fr_Script()
        {
            var pathScript = TestFiles.DeploymentItemPathsForCaller(TestContext, this.GetType()).Single();

            await VerifyFormScript(pathScript,
                                   "fr", () => PizzaOrder.BuildForm(), FormOptions.None, new PizzaOrder(), Array.Empty <EntityRecommendation>(),
                                   "bonjour",
                                   "2",
                                   "moyen",
                                   "4",
                                   "?",
                                   "1 2",
                                   "retourner",
                                   "c",
                                   "non",
                                   "fine",
                                   "1",
                                   "?",
                                   "bovine, oignons, ice cream",
                                   "oignons",
                                   "statut",
                                   "abc",
                                   "1 state street",
                                   "oui",
                                   "1 2",
                                   "non",
                                   "2,5",
                                   "25/2/1962 3pm",
                                   "non",
                                   "1234",
                                   "123-4567",
                                   "non",
                                   "nappages",
                                   "non epinards",
                                   "oui"
                                   );
        }
        public async Task SimpleForm_Limits_Script()
        {
            var pathScript = TestFiles.DeploymentItemPathsForCaller(TestContext, this.GetType()).Single();

            await VerifyFormScript(pathScript,
                                   "en-us",
                                   () => new FormBuilder <SimpleForm>().Build(),
                                   FormOptions.None, new SimpleForm(), Array.Empty <EntityRecommendation>(),
                                   "hi",
                                   "integer",
                                   // Test the limits of int vs long
                                   ((long)int.MaxValue + 1).ToString(),
                                   ((long)int.MinValue - 1).ToString(),

                                   // Test the limits beyond long
                                   long.MaxValue.ToString() + "1",
                                   long.MinValue.ToString() + "1",

                                   // Min and max accepted values
                                   int.MaxValue.ToString(),
                                   "back",
                                   int.MinValue.ToString(),

                                   // Test the limits of float vs. double
                                   ((double)float.MaxValue + 1.0).ToString(),
                                   ((double)float.MinValue * 2.0).ToString(),

                                   // Test limits beyond double
                                   (double.MaxValue).ToString().Replace("308", "309"),
                                   (double.MinValue).ToString().Replace("308", "309"),

                                   // Min and max accepted values
                                   float.MaxValue.ToString(),
                                   "back",
                                   float.MinValue.ToString(),
                                   "quit");
        }
        public async Task Pizza_Entities_Script()
        {
            var pathScript = TestFiles.DeploymentItemPathsForCaller(TestContext, this.GetType()).Single();

            await VerifyFormScript(pathScript,
                                   "en-us", () => PizzaOrder.BuildForm(), FormOptions.None, new PizzaOrder(),
                                   new Luis.Models.EntityRecommendation[] {
                new Luis.Models.EntityRecommendation("DeliveryAddress", entity: "2"),
                new Luis.Models.EntityRecommendation("Kind", entity: "byo"),
                // This should be skipped because it is not active
                new Luis.Models.EntityRecommendation("Signature", entity: "Hawaiian"),
                new Luis.Models.EntityRecommendation("BYO.Toppings", entity: "onions"),
                new Luis.Models.EntityRecommendation("BYO.Toppings", entity: "peppers"),
                new Luis.Models.EntityRecommendation("BYO.Toppings", entity: "ice"),
                new Luis.Models.EntityRecommendation("NumberOfPizzas", entity: "5"),
                new Luis.Models.EntityRecommendation("NotFound", entity: "OK")
            },
                                   "hi",
                                   "1", // onions for topping clarification
                                   "2", // address choice from validation
                                   "med",
                                        // Kind "4",
                                   "drink bread",
                                   "thin",
                                   "1",
                                   // "beef, onion, ice cream",
                                   // Already have address
                                   "y",
                                   "1 2",
                                   "none",
                                   "2.5",
                                   "2/25/1962 3pm",
                                   "no",
                                   "123-4567",
                                   "y"
                                   );
        }
        public async Task SimpleForm_Dependency_Script()
        {
            var pathScript = TestFiles.DeploymentItemPathsForCaller(TestContext, this.GetType()).Single();

            await VerifyFormScript(pathScript,
                                   "en-us",
                                   () => new FormBuilder <SimpleForm>()
                                   .Field("Float")
                                   .Field("SomeChoices",
                                          validate : async(state, value) =>
            {
                var result = new ValidateResult {
                    IsValid = true, Value = value
                };
                if ((SimpleChoices)value == SimpleChoices.One)
                {
                    state.Float = null;
                }
                return(result);
            })
                                   .Confirm("All OK?")
                                   .Build(),
                                   FormOptions.None, new SimpleForm(), Array.Empty <EntityRecommendation>(),
                                   "Hi",
                                   "1.0",
                                   "one",
                                   "2.0",
                                   "no",
                                   "Some Choices",
                                   "one",
                                   "3.0",
                                   "no",
                                   "some choices",
                                   "two",
                                   "yes"
                                   );
        }
Exemple #5
0
        public async Task BotDispatcher()
        {
            var token   = new CancellationTokenSource().Token;
            var pathOld = TestFiles.DeploymentItemPathsForCaller(TestContext, this.GetType()).Single();
            var pathNew = TestFiles.TestResultPathFor(TestContext, Path.GetFileName(pathOld));

            using (var writer = File.CreateText(pathNew))
            {
                var message = (Activity)MakeTestMessage();

                var bot = ExampleBot.MakeBot(MakeMockedLuisService);
                // TODO: Microsoft.Extensions.DependencyInjection
                ((Bot)bot).Container = ((Bot)bot).Container.BeginLifetimeScope(
                    builder =>
                {
                    // register singleton StreamWriter
                    builder
                    .RegisterInstance(writer)
                    .AsSelf();

                    // log all activities to and from bot
                    builder
                    .RegisterType <TestActivityLogger>()
                    .AsImplementedInterfaces()
                    .SingleInstance();

                    // truncate AlwaysSendDirect_BotToUser/IConnectorClient with null implementation
                    builder
                    .RegisterType <NullBotToUser>()
                    .Keyed <IBotToUser>(typeof(AlwaysSendDirect_BotToUser))
                    .InstancePerLifetimeScope();
                });

                var texts = new[]
                {
                    "echo reset an empty stack",
                    "reset",

                    "echo start chit chat dialog with normal quit",
                    "hello",
                    "lol wut",
                    "goodbye",

                    "echo start chit chat dialog with cancel quit",
                    "hello",
                    "lol wut",
                    "cancel",

                    "echo start list builder dialog with cancel quit",
                    "list",
                    "itemA",
                    "itemB",
                    "cancel",

                    "echo start list builder dialog with message forward with cancel quit",
                    "list itemC",
                    "itemD",
                    "cancel",

                    "echo start list builder dialog with reset",
                    "list",
                    "itemE",
                    "reset",
                    "itemF",
                    "cancel",

                    "echo chit chat dialog is not re-entrant",
                    "hello",
                    "hello",
                    "cancel",

                    "echo list dialog is not re-entrant",
                    "list",
                    "list",
                    "cancel",

                    "echo list builder dialog interrupts chit chat dialog",
                    "hello",
                    "list itemG",
                    "cancel",

                    "echo chit chat dialog interrupts list builder dialog then resume list builder dialog",
                    "list itemH",
                    "hello",
                    "cancel",
                    "yes",
                    "itemI",
                    "cancel",

                    "echo chit chat dialog interrupts list builder dialog then cancel list builder dialog",
                    "list itemH",
                    "hello",
                    "cancel",
                    "no",

                    // proactive (NEED TO MOCK TIMER)
                    //"echo proactive",
                    //UtteranceSetAlarm,

                    // clean up
                    "reset",
                };

                for (int index = 0; index < texts.Length; ++index)
                {
                    var text = texts[index];

                    message.Text = "stack";
                    await bot.PostAsync(message, token);

                    message.Text = text;
                    await bot.PostAsync(message, token);
                }

                message.Text = "stack";
                await bot.PostAsync(message, token);
            }

            CollectionAssert.AreEqual(File.ReadAllLines(pathOld), File.ReadAllLines(pathNew));
        }