public void GetConfigurationTest() { // arrage var httpClient = new HttpClient(); // act IWebChatService webChatService = new WebChatService(httpClient, EnvironmentName, ContentRootPath); WebChatConfig config = webChatService.GetConfiguration(); // assert Assert.Equal(configuration.Secret, config.Secret); }
public WebChatService(HttpClient httpClient, 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 WebChatConfig(); configuration.GetSection("WebChatConfig").Bind(config); if (string.IsNullOrEmpty(config.Secret)) { throw new ArgumentException("Missing value in WebChatConfig -> Secret"); } this.httpClient = httpClient ?? throw new ArgumentException("Missing value in HttpClient"); }