public virtual void InitializeSkill()
        {
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings());
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                { "General", GeneralTestUtil.CreateRecognizer() },
                                { "SkillSample", SkillTestUtil.CreateRecognizer() }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new MicrosoftAppCredentials("appId", "password"));
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            var localizedTemplates = new Dictionary <string, string>();
            var templateFile       = "AllResponses";
            var supportedLocales   = new List <string>()
            {
                "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"
            };

            foreach (var locale in supportedLocales)
            {
                // LG template for en-us does not include locale in file extension.
                var localeTemplateFile = locale.Equals("en-us")
                    ? Path.Combine(".", "Responses", $"{templateFile}.lg")
                    : Path.Combine(".", "Responses", $"{templateFile}.{locale}.lg");

                localizedTemplates.Add(locale, localeTemplateFile);
            }

            TemplateEngine = new LocaleTemplateManager(localizedTemplates, "en-us");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-us");
            Services.AddSingleton(TemplateEngine);
            Services.AddTransient <MainDialog>();
            Services.AddTransient <SampleDialog>();
            Services.AddTransient <SampleAction>();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
Ejemplo n.º 2
0
        public new void Initialize()
        {
            var builder = new ContainerBuilder();

            ConversationState   = new ConversationState(new MemoryStorage());
            DialogState         = ConversationState.CreateProperty <DialogState>(nameof(DialogState));
            UserState           = new UserState(new MemoryStorage());
            TelemetryClient     = new NullBotTelemetryClient();
            SkillConfigurations = new Dictionary <string, SkillConfigurationBase>();

            // Add the LUIS model fakes used by the Skill
            Services = new MockSkillConfiguration();
            Services.LocaleConfigurations.Add("en", new LocaleConfiguration()
            {
                Locale       = "en-us",
                LuisServices = new Dictionary <string, ITelemetryLuisRecognizer>
                {
                    { "general", GeneralTestUtil.CreateRecognizer() },
                    { "FakeSkill", FakeSkillTestUtil.CreateRecognizer() }
                }
            });

            Services.LocaleConfigurations.Add("es", new LocaleConfiguration()
            {
                Locale       = "es-mx",
                LuisServices = new Dictionary <string, ITelemetryLuisRecognizer>
                {
                    { "general", GeneralTestUtil.CreateRecognizer() },
                    { "FakeSkill", FakeSkillTestUtil.CreateRecognizer() }
                }
            });

            // Dummy Authentication connection for Auth testing
            Services.AuthenticationConnections = new Dictionary <string, string>
            {
                { "DummyAuth", "DummyAuthConnection" }
            };

            builder.RegisterInstance(new BotStateSet(UserState, ConversationState));
            Container = builder.Build();

            BotResponseBuilder = new BotResponseBuilder();
            BotResponseBuilder.AddFormatter(new TextBotResponseFormatter());

            Dialogs = new DialogSet(DialogState);

            // Manually mange the conversation metadata when we need finer grained control
            ConversationReference = new ConversationReference
            {
                ChannelId  = "test",
                ServiceUrl = "https://test.com",
            };

            ConversationReference.User         = new ChannelAccount("user1", "User1");
            ConversationReference.Bot          = new ChannelAccount("bot", "Bot");
            ConversationReference.Conversation = new ConversationAccount(false, "convo1", "Conversation1");
        }
Ejemplo n.º 3
0
        public void SetupLuisService()
        {
            var botServices = Services.BuildServiceProvider().GetService <BotServices>();

            botServices.CognitiveModelSets.Add("en-us", new CognitiveModelSet()
            {
                LuisServices = new Dictionary <string, LuisRecognizer>()
                {
                    { "General", GeneralTestUtil.CreateRecognizer() },
                    { "MusicSkill", PlayMusicTestUtil.CreateRecognizer() }
                }
            });
        }
Ejemplo n.º 4
0
        public virtual void Initialize()
        {
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings());
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en", new CognitiveModelSet
                        {
                            DispatchService = DispatchTestUtil.CreateRecognizer(),
                            LuisServices    = new Dictionary <string, ITelemetryRecognizer>
                            {
                                { "General", GeneralTestUtil.CreateRecognizer() }
                            },
                            QnAServices = new Dictionary <string, ITelemetryQnAMaker>
                            {
                                { "Faq", FaqTestUtil.CreateRecognizer() },
                                { "Chitchat", ChitchatTestUtil.CreateRecognizer() }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new MicrosoftAppCredentials("appId", "password"));
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            Services.AddTransient <CancelDialog>();
            Services.AddTransient <EscalateDialog>();
            Services.AddTransient <MainDialog>();
            Services.AddTransient <OnboardingDialog>();
            Services.AddTransient <CheckoutDialog>();

            Services.AddTransient <List <SkillDialog> >();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Ejemplo n.º 5
0
        public virtual void InitializeSkill()
        {
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings());
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en", new CognitiveModelSet
                        {
                            LuisServices = new Dictionary <string, ITelemetryRecognizer>
                            {
                                { "General", GeneralTestUtil.CreateRecognizer() },
                                { "skill", SkillTestUtil.CreateRecognizer() }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new MicrosoftAppCredentials("appId", "password"));
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            ResponseManager = new ResponseManager(
                new string[] { "en", "de", "es", "fr", "it", "zh" },
                new MainResponses(),
                new SharedResponses(),
                new SampleResponses());

            Services.AddSingleton(ResponseManager);
            Services.AddTransient <MainDialog>();
            Services.AddTransient <SampleDialog>();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Ejemplo n.º 6
0
        public virtual void Initialize()
        {
            var builder = new ContainerBuilder();

            ConversationState = new ConversationState(new MemoryStorage());
            UserState         = new UserState(new MemoryStorage());
            TelemetryClient   = new NullBotTelemetryClient();
            BotServices       = new BotServices()
            {
                DispatchRecognizer = DispatchTestUtil.CreateRecognizer(),
                LuisServices       = new Dictionary <string, ITelemetryLuisRecognizer>
                {
                    { "general", GeneralTestUtil.CreateRecognizer() }
                },
                QnAServices = new Dictionary <string, ITelemetryQnAMaker>
                {
                    { "faq", FaqTestUtil.CreateRecognizer() },
                    { "chitchat", ChitchatTestUtil.CreateRecognizer() }
                }
            };

            builder.RegisterInstance(new BotStateSet(UserState, ConversationState));
            Container = builder.Build();
        }
Ejemplo n.º 7
0
        public virtual void Initialize()
        {
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings());
            Services.AddSingleton(new BotServices()
            {
                // Non US languages are empty as Dispatch/LUIS not required for localization tests.
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet
                        {
                            DispatchService = DispatchTestUtil.CreateRecognizer(),
                            LuisServices    = new Dictionary <string, LuisRecognizer>
                            {
                                { "General", GeneralTestUtil.CreateRecognizer() }
                            },
                            QnAConfiguration = new Dictionary <string, Microsoft.Bot.Builder.AI.QnA.QnAMakerEndpoint>
                            {
                                {
                                    "Chitchat", new QnAMakerEndpoint
                                    {
                                        KnowledgeBaseId = _knowledgeBaseId,
                                        EndpointKey     = _endpointKey,
                                        Host            = _hostname
                                    }
                                }
                            }
                        }
                    },
                    {
                        "zh-cn", new CognitiveModelSet {
                        }
                    },
                    {
                        "fr-fr", new CognitiveModelSet {
                        }
                    },
                    {
                        "es-es", new CognitiveModelSet {
                        }
                    },
                    {
                        "de-de", new CognitiveModelSet {
                        }
                    },
                    {
                        "it-it", new CognitiveModelSet {
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new MicrosoftAppCredentials("appId", "password"));
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));

            // For localization testing
            CultureInfo.CurrentUICulture = new CultureInfo("en-us");

            var localizedTemplates = new Dictionary <string, string>();
            var templateFile       = "AllResponses";
            var supportedLocales   = new List <string>()
            {
                "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"
            };

            foreach (var locale in supportedLocales)
            {
                // LG template for en-us does not include locale in file extension.
                var localeTemplateFile = locale.Equals("en-us")
                    ? Path.Combine(".", "Responses", $"{templateFile}.lg")
                    : Path.Combine(".", "Responses", $"{templateFile}.{locale}.lg");

                localizedTemplates.Add(locale, localeTemplateFile);
            }

            TestLocaleTemplateManager = new LocaleTemplateManager(localizedTemplates, "en-us");
            Services.AddSingleton(TestLocaleTemplateManager);

            Services.AddTransient <MockMainDialog>();
            Services.AddTransient <OnboardingDialog>();
            Services.AddTransient <SwitchSkillDialog>();
            Services.AddTransient <List <SkillDialog> >();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <IBot, DefaultActivityHandler <MockMainDialog> >();

            TestUserProfileState      = new UserProfileState();
            TestUserProfileState.Name = "Bot";
        }
Ejemplo n.º 8
0
        public virtual void Initialize()
        {
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings());
            Services.AddSingleton(new BotServices()
            {
                // Non US languages are empty as Dispatch/LUIS not required for localization tests.
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet
                        {
                            DispatchService = DispatchTestUtil.CreateRecognizer(),
                            LuisServices    = new Dictionary <string, LuisRecognizer>
                            {
                                { "General", GeneralTestUtil.CreateRecognizer() }
                            },
                        }
                    },
                    {
                        "zh-cn", new CognitiveModelSet {
                        }
                    },
                    {
                        "fr-fr", new CognitiveModelSet {
                        }
                    },
                    {
                        "es-es", new CognitiveModelSet {
                        }
                    },
                    {
                        "de-de", new CognitiveModelSet {
                        }
                    },
                    {
                        "it-it", new CognitiveModelSet {
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new MicrosoftAppCredentials("appId", "password"));
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            // For localization testing
            CultureInfo.CurrentUICulture = new CultureInfo("en-us");

            var localizedTemplates = new Dictionary <string, List <string> >();
            var templateFiles      = new List <string>()
            {
                "MainResponses", "OnboardingResponses"
            };
            var supportedLocales = new List <string>()
            {
                "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"
            };

            foreach (var locale in supportedLocales)
            {
                var localeTemplateFiles = new List <string>();
                foreach (var template in templateFiles)
                {
                    // LG template for en-us does not include locale in file extension.
                    if (locale.Equals("en-us"))
                    {
                        localeTemplateFiles.Add(Path.Combine(".", "Responses", $"{template}.lg"));
                    }
                    else
                    {
                        localeTemplateFiles.Add(Path.Combine(".", "Responses", $"{template}.{locale}.lg"));
                    }
                }

                localizedTemplates.Add(locale, localeTemplateFiles);
            }

            LocaleTemplateEngine = new LocaleTemplateEngineManager(localizedTemplates, "en-us");
            Services.AddSingleton(LocaleTemplateEngine);

            Services.AddTransient <MainDialog>();
            Services.AddTransient <OnboardingDialog>();
            Services.AddTransient <SwitchSkillDialog>();
            Services.AddTransient <List <SkillDialog> >();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();

            TestUserProfileState      = new UserProfileState();
            TestUserProfileState.Name = "Bot";
        }
Ejemplo n.º 9
0
        public new void Initialize()
        {
            var builder = new ContainerBuilder();

            ConversationState   = new ConversationState(new MemoryStorage());
            DialogState         = ConversationState.CreateProperty <DialogState>(nameof(DialogState));
            UserState           = new UserState(new MemoryStorage());
            ProactiveState      = new ProactiveState(new MemoryStorage());
            TelemetryClient     = new NullBotTelemetryClient();
            BackgroundTaskQueue = new BackgroundTaskQueue();
            EndpointService     = new EndpointService();
            SkillConfigurations = new Dictionary <string, SkillConfigurationBase>();

            // Add the LUIS model fakes used by the Skill
            Services = new MockSkillConfiguration();
            Services.LocaleConfigurations.Add("en", new LocaleConfiguration()
            {
                Locale       = "en-us",
                LuisServices = new Dictionary <string, ITelemetryLuisRecognizer>
                {
                    { "general", GeneralTestUtil.CreateRecognizer() },
                    { "FakeSkill", FakeSkillTestUtil.CreateRecognizer() }
                }
            });

            Services.LocaleConfigurations.Add("es", new LocaleConfiguration()
            {
                Locale       = "es-mx",
                LuisServices = new Dictionary <string, ITelemetryLuisRecognizer>
                {
                    { "general", GeneralTestUtil.CreateRecognizer() },
                    { "FakeSkill", FakeSkillTestUtil.CreateRecognizer() }
                }
            });

            // Dummy Authentication connection for Auth testing
            Services.AuthenticationConnections = new Dictionary <string, string>
            {
                { "DummyAuth", "DummyAuthConnection" }
            };

            builder.RegisterInstance(new BotStateSet(UserState, ConversationState));
            Container = builder.Build();

            Dialogs = new DialogSet(DialogState);

            ResponseManager = new ResponseManager(
                new IResponseIdCollection[]
            {
                new SampleAuthResponses(),
                new MainResponses(),
                new SharedResponses(),
                new SampleResponses()
            },
                new string[] { "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn" });

            // Manually mange the conversation metadata when we need finer grained control
            ConversationReference = new ConversationReference
            {
                ChannelId  = "test",
                ServiceUrl = "https://test.com",
            };

            ConversationReference.User         = new ChannelAccount("user1", "User1");
            ConversationReference.Bot          = new ChannelAccount("bot", "Bot");
            ConversationReference.Conversation = new ConversationAccount(false, "convo1", "Conversation1");
        }