public IWebHost BuildWebHost(string[] args, bool isService) { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepository, new FileInfo("config/log4net.config")); //Parse Application Arguments var argConfig = new ConfigurationBuilder() .AddCommandLine(args).Build(); var environment = "Development"; var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); if (env != null && env.Any()) { environment = env; } env = argConfig["environment"]; if (env != null && env.Any()) { environment = env; } var pathToContentRoot = ConfigurationPathUtils.ConfigurePathToContentRoot(isService); Logger.Info($"pathToContentRoot = {pathToContentRoot}"); Logger.Info($"environmentName = {environment}"); Logger.Info($"isService = {isService}"); var builder = new ConfigurationBuilder() .SetBasePath(pathToContentRoot) .AddJsonFile("config/ApplicationSettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"config/ApplicationSettings.{environment}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .AddCommandLine(args); var configuration = builder.Build(); var serverUrlsSection = configuration.GetSection("ServerUrls"); var serverUrlsItems = serverUrlsSection.AsEnumerable(); var urls = from kvp in serverUrlsItems where !string.IsNullOrWhiteSpace(kvp.Value) select kvp.Value; var host = new WebHostBuilder() .CaptureStartupErrors(true) // the default .UseSetting("detailedErrors", "true") .UseKestrel(options => options.AddServerHeader = false) .UseUrls(urls.ToArray()) .UseContentRoot(pathToContentRoot) .UseStartup <Startup>() .UseConfiguration(configuration) .UseEnvironment(environment) .Build(); return(host); }
public ApiIntegrationTest(ConfigFixture fixture) { Fixture = fixture; var contentRoot = ConfigurationPathUtils.ConfigurePathToContentRoot(false); var environment = "ApiTest"; var configBuilder = new ConfigurationBuilder() .SetBasePath(contentRoot) .AddEnvironmentVariables() .AddJsonFile(Path.Combine(contentRoot, "config/ApplicationSettings.json"), optional: false, reloadOnChange: true) .AddJsonFile(Path.Combine(contentRoot, $"config/ApplicationSettings.{environment}.json"), optional: false, reloadOnChange: true); var configuration = configBuilder.Build(); var builder = new WebHostBuilder() .UseEnvironment(environment) .UseConfiguration(configuration) .UseStartup <TestStartup>(); Server = new TestServer(builder); Client = Server.CreateClient(); }
public LoggingFixture() { ContentRoot = ConfigurationPathUtils.ConfigurePathToContentRoot(false); LoggerFactory = new LoggerFactory().AddLog4Net(Path.Combine(ContentRoot, "config/log4net.config")); }