Exemplo n.º 1
0
        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            //used to read env variables for host/port
            var configuration = new ConfigurationBuilder()
                                .AddEnvironmentVariables()
                                .Build();

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseConfiguration(configuration)
                       .UseIISIntegration()
                       .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
                logging.AddDebug();
            })
                       .ConfigureAppConfiguration((hostingContext, config) =>
            {
                var env = hostingContext.HostingEnvironment;
                config.SetBasePath(Directory.GetCurrentDirectory());
                config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
                config.AddEnvironmentVariables();
                config.AddCommandLine(args);
            })
                       .UseStartup <Startup>()
                       .UseUrls(POIConfiguration.GetUri(configuration));

            return(host);
        }
Exemplo n.º 2
0
        public void GetUri_Returns_DefailtUriAndPort_WhenNotInSettings()
        {
            //arrange
            IConfiguration configuration = GetTestConfiguration();

            //act
            var uri = POIConfiguration.GetUri(configuration);

            //assert
            var expectedUri = "https://github.com:9090";

            Assert.Equal(expectedUri, uri);
        }
Exemplo n.º 3
0
        public void GetUri_Returns_BaseUrlAndPortFromSettings()
        {
            //arrange
            var inMemorySettings = GetTestSettings();

            inMemorySettings.Remove("WEB_SERVER_BASE_URI");
            inMemorySettings.Remove("WEB_PORT");
            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddInMemoryCollection(inMemorySettings)
                                           .Build();

            //act
            var uri = POIConfiguration.GetUri(configuration);

            //assert
            var expectedUri = "http://localhost:8080";

            Assert.Equal(expectedUri, uri);
        }