From 9949306ca3229c41fc952edee981d34ece62c637 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Tue, 16 Oct 2018 12:48:17 -0700 Subject: [PATCH 1/2] Update package branding for 2.2 RTM --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index a8d060b064..9b41b556d7 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ 2.2.0 - preview3 + rtm $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final t000 From 27efce1042914569097d6c68db404e5286ad7b20 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 29 Oct 2018 17:39:18 -0700 Subject: [PATCH 2/2] Do not use the default 5000 port for functional tests --- .../WebHostFunctionalTests.cs | 48 +++-------- .../CreateDefaultBuilderApp/Program.cs | 32 ++++---- .../CreateDefaultBuilderApp/appsettings.json | 3 +- .../CreateDefaultBuilderOfTApp/Program.cs | 80 ++++++++++++++++++- .../CreateDefaultBuilderOfTApp/Startup.cs | 75 ----------------- .../appsettings.json | 5 +- .../DependencyInjectionApp/Program.cs | 9 +-- 7 files changed, 115 insertions(+), 137 deletions(-) delete mode 100644 test/TestSites/CreateDefaultBuilderOfTApp/Startup.cs diff --git a/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs b/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs index a017c66d8e..d2e71f5778 100644 --- a/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs +++ b/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs @@ -4,31 +4,20 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; using Xunit; -using Xunit.Abstractions; using Xunit.Sdk; namespace Microsoft.AspNetCore.Tests { public class WebHostFunctionalTests : LoggedTest { - private readonly string _testSitesPath; - - public WebHostFunctionalTests(ITestOutputHelper output) : base(output) - { - _testSitesPath = GetTestSitesPath(); - } - [Fact] public async Task Start_RequestDelegate_Url() { @@ -60,8 +49,6 @@ namespace Microsoft.AspNetCore.Tests { // Assert server is Kestrel Assert.Equal("Kestrel", response.Headers.Server.ToString()); - // Set from default config - Assert.Equal("http://localhost:5002/", deploymentResult.ApplicationBaseUri); // The application name will be sent in response when all asserts succeed in the test app. Assert.Equal(applicationName, responseText); } @@ -87,8 +74,6 @@ namespace Microsoft.AspNetCore.Tests { // Assert server is Kestrel Assert.Equal("Kestrel", response.Headers.Server.ToString()); - // Set from default config - Assert.Equal("http://localhost:5002/", deploymentResult.ApplicationBaseUri); // The application name will be sent in response when all asserts succeed in the test app. Assert.Equal(applicationName, responseText); } @@ -139,7 +124,7 @@ namespace Microsoft.AspNetCore.Tests } } "); - using (var webHost = WebHost.Start(context => context.Response.WriteAsync("Hello, World!"))) + using (var webHost = WebHost.Start("http://127.0.0.1:0", context => context.Response.WriteAsync("Hello, World!"))) { var factory = (ILoggerFactory)webHost.Services.GetService(typeof(ILoggerFactory)); var logger = factory.CreateLogger("Test"); @@ -171,13 +156,13 @@ namespace Microsoft.AspNetCore.Tests public async Task RunsInIISExpressInProcess() { var applicationName = "CreateDefaultBuilderApp"; - var deploymentParameters = new DeploymentParameters(Path.Combine(_testSitesPath, applicationName), ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) + var deploymentParameters = new DeploymentParameters(Path.Combine(GetTestSitesPath(), applicationName), ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { TargetFramework = "netcoreapp2.2", HostingModel = HostingModel.InProcess, AncmVersion = AncmVersion.AspNetCoreModuleV2 }; - + SetEnvironmentVariables(deploymentParameters, "Development"); using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, LoggerFactory)) @@ -227,22 +212,18 @@ namespace Microsoft.AspNetCore.Tests bool setTestEnvVars = false, string environment = "Development") { - using (StartLog(out var loggerFactory, applicationName)) + var deploymentParameters = new DeploymentParameters(Path.Combine(GetTestSitesPath(), applicationName), ServerType.Kestrel, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64); + + if (setTestEnvVars) { - var logger = loggerFactory.CreateLogger(nameof(WebHost.Start)); - var deploymentParameters = new DeploymentParameters(Path.Combine(_testSitesPath, applicationName), ServerType.Kestrel, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64); + SetEnvironmentVariables(deploymentParameters, environment); + } - if (setTestEnvVars) - { - SetEnvironmentVariables(deploymentParameters, environment); - } + using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, LoggerFactory)) + { + var deploymentResult = await deployer.DeployAsync(); - using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) - { - var deploymentResult = await deployer.DeployAsync(); - - await assertAction(deploymentResult, logger); - } + await assertAction(deploymentResult, Logger); } } @@ -271,10 +252,5 @@ namespace Microsoft.AspNetCore.Tests throw new Exception($"Solution root could not be found using {applicationBasePath}"); } - - private static int GetWebHostPort(IWebHost webHost) - => webHost.ServerFeatures.Get().Addresses - .Select(serverAddress => new Uri(serverAddress).Port) - .FirstOrDefault(); } } diff --git a/test/TestSites/CreateDefaultBuilderApp/Program.cs b/test/TestSites/CreateDefaultBuilderApp/Program.cs index e0002ced01..5d58a6f97b 100644 --- a/test/TestSites/CreateDefaultBuilderApp/Program.cs +++ b/test/TestSites/CreateDefaultBuilderApp/Program.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -15,24 +14,29 @@ namespace CreateDefaultBuilderApp { static void Main(string[] args) { - string responseMessage = string.Empty; + string responseMessage = null; WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) - .ConfigureServices((context, services) => - { - responseMessage = GetResponseMessage(context, services); - }) - .Configure(app => - { - app.Run(context => + .ConfigureServices((context, services) => responseMessage = responseMessage ?? GetResponseMessage(context)) + .ConfigureKestrel(options => options + .Configure(options.ConfigurationLoader.Configuration) + .Endpoint("HTTP", endpointOptions => { - return context.Response.WriteAsync(responseMessage); - }); - }) + if (responseMessage == null + && !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"])) + { + responseMessage = "Default Kestrel configuration not read."; + } + })) + .Configure(app => app.Run(context => + { + var hostingEnvironment = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName); + })) .Build().Run(); } - private static string GetResponseMessage(WebHostBuilderContext context, IServiceCollection services) + private static string GetResponseMessage(WebHostBuilderContext context) { // Verify ContentRootPath set var contentRoot = Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT"); @@ -71,7 +75,7 @@ namespace CreateDefaultBuilderApp // TODO: Verify AddDebug called // TODO: Verify UseIISIntegration called - return context.HostingEnvironment.ApplicationName; + return null; } } } \ No newline at end of file diff --git a/test/TestSites/CreateDefaultBuilderApp/appsettings.json b/test/TestSites/CreateDefaultBuilderApp/appsettings.json index 393b080efb..1d28ed80fc 100644 --- a/test/TestSites/CreateDefaultBuilderApp/appsettings.json +++ b/test/TestSites/CreateDefaultBuilderApp/appsettings.json @@ -3,7 +3,8 @@ "Kestrel": { "Endpoints": { "HTTP": { - "Url": "http://localhost:5002" + "Url": "http://127.0.0.1:0", + "KestrelEndPointSettingName": "KestrelEndPointSettingValue" } } } diff --git a/test/TestSites/CreateDefaultBuilderOfTApp/Program.cs b/test/TestSites/CreateDefaultBuilderOfTApp/Program.cs index fbdc90efee..3419340dc3 100644 --- a/test/TestSites/CreateDefaultBuilderOfTApp/Program.cs +++ b/test/TestSites/CreateDefaultBuilderOfTApp/Program.cs @@ -1,14 +1,92 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.HostFiltering; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; namespace CreateDefaultBuilderOfTApp { public class Program { - static void Main(string[] args) => WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) .Build().Run(); + static void Main(string[] args) + { + string responseMessage = null; + + WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) + .ConfigureServices((context, service) => responseMessage = responseMessage ?? GetResponseMessage(context)) + .ConfigureKestrel(options => options + .Configure(options.ConfigurationLoader.Configuration) + .Endpoint("HTTP", endpointOptions => + { + if (responseMessage == null + && !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"])) + { + responseMessage = "Default Kestrel configuration not read."; + } + })) + .Configure(app => app.Run(context => + { + // Verify allowed hosts were loaded + var hostFilteringOptions = app.ApplicationServices.GetRequiredService>(); + var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts); + if (responseMessage == null && !string.Equals("example.com,127.0.0.1", hosts, StringComparison.Ordinal)) + { + responseMessage = "AllowedHosts not loaded into Options."; + } + + var hostingEnvironment = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName); + })) + .Build() + .Run(); + } + + private static string GetResponseMessage(WebHostBuilderContext context) + { + // Verify ContentRootPath set + var contentRoot = Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT"); + if (!string.Equals(contentRoot, context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal)) + { + return $"ContentRootPath incorrect. Expected: {contentRoot} Actual: {context.HostingEnvironment.ContentRootPath}"; + } + + // Verify appsettings.json loaded + if (!string.Equals("settingsValue", context.Configuration["settingsKey"], StringComparison.Ordinal)) + { + return $"appsettings.json not loaded into Configuration."; + } + + // Verify appsettings.environment.json loaded + if (!string.Equals("devSettingsValue", context.Configuration["devSettingsKey"], StringComparison.Ordinal)) + { + return $"appsettings.{context.HostingEnvironment.EnvironmentName}.json not loaded into Configuration."; + } + + // TODO: Verify UserSecrets loaded + + // Verify environment variables loaded + if (!string.Equals("envValue", context.Configuration["envKey"], StringComparison.Ordinal)) + { + return $"Environment variables not loaded into Configuration."; + } + + // Verify command line arguments loaded + if (!string.Equals("cliValue", context.Configuration["cliKey"], StringComparison.Ordinal)) + { + return $"Command line arguments not loaded into Configuration."; + } + + // TODO: Verify AddConsole called + // TODO: Verify AddDebug called + // TODO: Verify UseIISIntegration called + + return null; + } } } \ No newline at end of file diff --git a/test/TestSites/CreateDefaultBuilderOfTApp/Startup.cs b/test/TestSites/CreateDefaultBuilderOfTApp/Startup.cs deleted file mode 100644 index 4d607bffc0..0000000000 --- a/test/TestSites/CreateDefaultBuilderOfTApp/Startup.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.HostFiltering; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; - -namespace CreateDefaultBuilderOfTApp -{ - class Startup - { - public void Configure(IApplicationBuilder app, WebHostBuilderContext webHostBuilderContext) - { - app.Run(context => - { - var message = GetResponseMessage(webHostBuilderContext, app.ApplicationServices.GetRequiredService>()); - return context.Response.WriteAsync(message); - }); - } - - private static string GetResponseMessage(WebHostBuilderContext context, IOptions hostFilteringOptions) - { - // Verify ContentRootPath set - var contentRoot = Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT"); - if (!string.Equals(contentRoot, context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal)) - { - return $"ContentRootPath incorrect. Expected: {contentRoot} Actual: {context.HostingEnvironment.ContentRootPath}"; - } - - // Verify appsettings.json loaded - if (!string.Equals("settingsValue", context.Configuration["settingsKey"], StringComparison.Ordinal)) - { - return $"appsettings.json not loaded into Configuration."; - } - - // Verify appsettings.environment.json loaded - if (!string.Equals("devSettingsValue", context.Configuration["devSettingsKey"], StringComparison.Ordinal)) - { - return $"appsettings.{context.HostingEnvironment.EnvironmentName}.json not loaded into Configuration."; - } - - // TODO: Verify UserSecrets loaded - - // Verify environment variables loaded - if (!string.Equals("envValue", context.Configuration["envKey"], StringComparison.Ordinal)) - { - return $"Environment variables not loaded into Configuration."; - } - - // Verify command line arguments loaded - if (!string.Equals("cliValue", context.Configuration["cliKey"], StringComparison.Ordinal)) - { - return $"Command line arguments not loaded into Configuration."; - } - - // Verify allowed hosts were loaded - var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts); - if (!string.Equals("example.com,localhost", hosts, StringComparison.Ordinal)) - { - return $"AllowedHosts not loaded into Options."; - } - - // TODO: Verify AddConsole called - // TODO: Verify AddDebug called - // TODO: Verify UseIISIntegration called - - return context.HostingEnvironment.ApplicationName; - } - } -} diff --git a/test/TestSites/CreateDefaultBuilderOfTApp/appsettings.json b/test/TestSites/CreateDefaultBuilderOfTApp/appsettings.json index 27eb1aaf44..a2f89f1a54 100644 --- a/test/TestSites/CreateDefaultBuilderOfTApp/appsettings.json +++ b/test/TestSites/CreateDefaultBuilderOfTApp/appsettings.json @@ -1,10 +1,11 @@ { "settingsKey": "settingsValue", - "AllowedHosts": "example.com;localhost", + "AllowedHosts": "example.com;127.0.0.1", "Kestrel": { "Endpoints": { "HTTP": { - "Url": "http://localhost:5002" + "Url": "http://127.0.0.1:0", + "KestrelEndPointSettingName": "KestrelEndPointSettingValue" } } } diff --git a/test/TestSites/DependencyInjectionApp/Program.cs b/test/TestSites/DependencyInjectionApp/Program.cs index 6e4850002b..c8877442e5 100644 --- a/test/TestSites/DependencyInjectionApp/Program.cs +++ b/test/TestSites/DependencyInjectionApp/Program.cs @@ -2,18 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.Extensions.Logging.Console; -using Microsoft.Extensions.Logging.Debug; namespace CreateDefaultBuilderApp { @@ -22,7 +15,7 @@ namespace CreateDefaultBuilderApp static void Main(string[] args) { WebHost.CreateDefaultBuilder() - .UseUrls("http://localhost:5002") + .UseUrls("http://127.0.0.1:0") .ConfigureServices((context, services) => { services.AddSingleton(typeof(IService<>), typeof(Service<>));