public LuisRouterHelper(string environmentName, string contentRootPath) { var builder = new ConfigurationBuilder() .SetBasePath(contentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{environmentName}.json", optional: true) .AddEnvironmentVariables(); var configuration = builder.Build(); config = new LuisRouterConfig(); configuration.GetSection("LuisRouterConfig").Bind(config); }
public async void GetConfigurationTest() { // arrage var httpClient = new HttpClient(); var storage = new MemoryStorage(); var userState = new UserState(storage); var conversationState = new ConversationState(storage); var adapter = new TestAdapter().Use(new AutoSaveStateMiddleware(conversationState)); var dialogState = conversationState.CreateProperty <DialogState>("dialogState"); var dialogs = new DialogSet(dialogState); var steps = new WaterfallStep[] { async(step, cancellationToken) => { await step.Context.SendActivityAsync("response"); // act ILuisRouterService luisRouterService = new LuisRouterService(httpClient, EnvironmentName, ContentRootPath, userState); LuisRouterConfig config = luisRouterService.GetConfiguration(); // assert Assert.Equal(configuration.BingSpellCheckSubscriptionKey, config.BingSpellCheckSubscriptionKey); Assert.Collection <LuisApp>(configuration.LuisApplications, x => Xunit.Assert.Contains("name", x.Name)); Assert.Equal(configuration.LuisRouterUrl, config.LuisRouterUrl); return(Dialog.EndOfTurn); } }; dialogs.Add(new WaterfallDialog( "test", steps)); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); await dc.ContinueDialogAsync(cancellationToken); if (!turnContext.Responded) { await dc.BeginDialogAsync("test", null, cancellationToken); } }) .Send("ask") .AssertReply("response") .StartTestAsync(); }
public LuisRouterService(HttpClient httpClient, string environmentName, string contentRootPath, UserState userState, IBotTelemetryClient botTelemetryClient = null) { var builder = new ConfigurationBuilder() .SetBasePath(contentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{environmentName}.json", optional: true) .AddEnvironmentVariables(); var configuration = builder.Build(); config = new LuisRouterConfig(); configuration.GetSection("LuisRouterConfig").Bind(config); this.httpClient = httpClient ?? throw new ArgumentException("Missing value in HttpClient"); this.botTelemetryClient = botTelemetryClient; this.UserState = userState; this.LuisServices = BuildDictionary(botTelemetryClient); this.TokenPreference = userState.CreateProperty <string>("TokenPreference"); }