From 4b5a32d3b95299445163137b3443fb8f89389e27 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 31 Jul 2018 19:32:48 -0700 Subject: [PATCH] Use TestApplication (#1118) --- build/dependencies.props | 52 +++++++------- build/testsite.props | 3 +- .../Common.FunctionalTests/AppOfflineTests.cs | 16 +++-- .../Inprocess/EventLogTests.cs | 12 +++- .../Inprocess/LoggingTests.cs | 20 ++++-- .../Inprocess/StartupExceptionTests.cs | 14 +++- .../OutOfProcess/HelloWorldTest.cs | 14 ++-- .../PublishedSitesFixture.cs | 70 +++++++++++++++++++ .../Utilities/FunctionalTestsBase.cs | 5 ++ .../Utilities/Helpers.cs | 19 +---- .../InProcess/AuthenticationTests.cs | 9 ++- .../InProcess/ShutdownTests.cs | 12 ++-- .../InProcess/StartupTests.cs | 36 +++------- .../OutOfProcess/GlobalVersionTests.cs | 44 +++++++----- .../OutOfProcess/HttpsTest.cs | 22 +++--- .../OutOfProcess/NtlmAuthentationTest.cs | 14 ++-- .../OutOfProcess/WindowsAuthTests.cs | 11 +-- .../UpgradeFeatureDetectionTests.cs | 15 ++-- 18 files changed, 236 insertions(+), 152 deletions(-) create mode 100644 test/Common.FunctionalTests/PublishedSitesFixture.cs diff --git a/build/dependencies.props b/build/dependencies.props index fe40c919f6..a181793011 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,38 +4,38 @@ 0.10.13 - 2.2.0-preview1-17102 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 0.6.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 + 2.2.0-preview1-17099 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 0.6.0-a-preview1-test-application-17108 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 15.6.82 15.6.82 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 - 2.2.0-preview1-34823 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 + 2.2.0-preview1-34825 2.0.9 2.1.2 2.2.0-preview1-26618-02 1.0.1 - 2.2.0-preview1-34823 + 2.2.0-preview1-34825 15.6.1 11.1.0 2.0.3 diff --git a/build/testsite.props b/build/testsite.props index ab74d58d72..3f84d67f31 100644 --- a/build/testsite.props +++ b/build/testsite.props @@ -7,6 +7,7 @@ $(MSBuildThisFileDirectory)applicationhost.iis.config x64 $(Platform) + false @@ -51,7 +52,7 @@ - + diff --git a/test/Common.FunctionalTests/AppOfflineTests.cs b/test/Common.FunctionalTests/AppOfflineTests.cs index 169be93035..d8d0861d3a 100644 --- a/test/Common.FunctionalTests/AppOfflineTests.cs +++ b/test/Common.FunctionalTests/AppOfflineTests.cs @@ -14,10 +14,18 @@ using Microsoft.Extensions.Logging; using Xunit; using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; -namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Inprocess +namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class AppOfflineTests : IISFunctionalTestBase { + private readonly PublishedSitesFixture _fixture; + + public AppOfflineTests(PublishedSitesFixture fixture) + { + _fixture = fixture; + } + [ConditionalTheory] [InlineData(HostingModel.InProcess)] [InlineData(HostingModel.OutOfProcess)] @@ -36,8 +44,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Inprocess [InlineData(HostingModel.OutOfProcess, 502, "502.5")] public async Task AppOfflineDroppedWhileSiteFailedToStartInShim_AppOfflineServed(HostingModel hostingModel, int statusCode, string content) { - - var deploymentParameters = Helpers.GetBaseDeploymentParameters(hostingModel: hostingModel, publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel: hostingModel, publish: true); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", "nonexistent")); var deploymentResult = await DeployAsync(deploymentParameters); @@ -193,10 +200,9 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Inprocess } } - private async Task DeployApp(HostingModel hostingModel = HostingModel.InProcess) { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(hostingModel: hostingModel, publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel: hostingModel, publish: true); return await DeployAsync(deploymentParameters); } diff --git a/test/Common.FunctionalTests/Inprocess/EventLogTests.cs b/test/Common.FunctionalTests/Inprocess/EventLogTests.cs index a2476cea1b..d8353181d3 100644 --- a/test/Common.FunctionalTests/Inprocess/EventLogTests.cs +++ b/test/Common.FunctionalTests/Inprocess/EventLogTests.cs @@ -9,12 +9,20 @@ using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class EventLogTests : IISFunctionalTestBase { + private readonly PublishedSitesFixture _fixture; + + public EventLogTests(PublishedSitesFixture fixture) + { + _fixture = fixture; + } + [ConditionalFact] public async Task CheckStartupEventLogMessage() { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); var deploymentResult = await DeployAsync(deploymentParameters); await Helpers.AssertStarts(deploymentResult); @@ -26,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task CheckShutdownEventLogMessage() { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.GracefulShutdown = true; var deploymentResult = await DeployAsync(deploymentParameters); await Helpers.AssertStarts(deploymentResult); diff --git a/test/Common.FunctionalTests/Inprocess/LoggingTests.cs b/test/Common.FunctionalTests/Inprocess/LoggingTests.cs index 15e9c8c1d9..0ff23a392f 100644 --- a/test/Common.FunctionalTests/Inprocess/LoggingTests.cs +++ b/test/Common.FunctionalTests/Inprocess/LoggingTests.cs @@ -14,14 +14,22 @@ using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class LoggingTests : IISFunctionalTestBase { + private readonly PublishedSitesFixture _fixture; + + public LoggingTests(PublishedSitesFixture fixture) + { + _fixture = fixture; + } + [ConditionalTheory] [InlineData("CheckErrLogFile")] [InlineData("CheckLogFile")] public async Task CheckStdoutLoggingToFile(string path) { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogEnabled", "true")); @@ -63,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task InvalidFilePathForLogs_ServerStillRuns() { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogEnabled", "true")); @@ -82,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var tempFile = Path.GetTempFileName(); try { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.EnvironmentVariables["ASPNETCORE_MODULE_DEBUG_FILE"] = tempFile; deploymentParameters.AddDebugLogToWebConfig(tempFile); @@ -107,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("CheckLogFile")] public async Task CheckStdoutLoggingToPipe_DoesNotCrashProcess(string path) { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.GracefulShutdown = true; var deploymentResult = await DeployAsync(deploymentParameters); @@ -126,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("CheckLogFile")] public async Task CheckStdoutLoggingToPipeWithFirstWrite(string path) { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.GracefulShutdown = true; var firstWriteString = path + path; @@ -156,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests try { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.EnvironmentVariables["ASPNETCORE_MODULE_DEBUG_FILE"] = firstTempFile; deploymentParameters.AddDebugLogToWebConfig(secondTempFile); diff --git a/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs b/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs index 93683b8a78..980341dbc4 100644 --- a/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs +++ b/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs @@ -10,8 +10,16 @@ using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class StartupExceptionTests : IISFunctionalTestBase { + private readonly PublishedSitesFixture _fixture; + + public StartupExceptionTests(PublishedSitesFixture fixture) + { + _fixture = fixture; + } + [ConditionalTheory] [InlineData("CheckLogFile")] [InlineData("CheckErrLogFile")] @@ -21,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests // Reason is because by default for IISExpress, we expect there to not be a web.config file. // However, for IIS, we need a web.config file because the default on generated on publish // doesn't include V2. We can remove the publish flag once IIS supports non-publish running - var deploymentParameters = Helpers.GetBaseDeploymentParameters("StartupExceptionWebsite", publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.StartupExceptionWebsite, publish: true); var randomNumberString = new Random(Guid.NewGuid().GetHashCode()).Next(10000000).ToString(); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_INPROCESS_STARTUP_VALUE"] = path; @@ -45,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("CheckOversizedStdOutWrites")] public async Task CheckStdoutWithLargeWrites(string path) { - var deploymentParameters = Helpers.GetBaseDeploymentParameters("StartupExceptionWebsite", publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.StartupExceptionWebsite, publish: true); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_INPROCESS_STARTUP_VALUE"] = path; var deploymentResult = await DeployAsync(deploymentParameters); @@ -62,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task Gets500_30_ErrorPage() { - var deploymentParameters = Helpers.GetBaseDeploymentParameters("StartupExceptionWebsite", publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.StartupExceptionWebsite, publish: true); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs b/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs index e868207bb8..d2a56caea5 100644 --- a/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs +++ b/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs @@ -2,21 +2,22 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; using Microsoft.AspNetCore.Server.IntegrationTesting; -using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; using Microsoft.AspNetCore.Testing.xunit; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class HelloWorldTests : IISFunctionalTestBase { - public HelloWorldTests(ITestOutputHelper output = null) : base(output) + private readonly PublishedSitesFixture _fixture; + + public HelloWorldTests(PublishedSitesFixture fixture) { + _fixture = fixture; } public static TestMatrix TestVariants @@ -31,10 +32,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { // The default in hosting sets windows auth to true. // Set it to the IISExpress.config file - var deploymentParameters = new IISDeploymentParameters(variant) - { - ApplicationPath = Helpers.GetOutOfProcessTestSitesPath() - }; + var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/test/Common.FunctionalTests/PublishedSitesFixture.cs b/test/Common.FunctionalTests/PublishedSitesFixture.cs new file mode 100644 index 0000000000..90104f6652 --- /dev/null +++ b/test/Common.FunctionalTests/PublishedSitesFixture.cs @@ -0,0 +1,70 @@ +// 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.Server.IntegrationTesting; +using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; +using Xunit; + +namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests +{ + /// + /// This type just maps collection names to available fixtures + /// + [CollectionDefinition(Name)] + public class PublishedSitesCollection : ICollectionFixture + { + public const string Name = nameof(PublishedSitesCollection); + } + + public class PublishedSitesFixture : IDisposable + { + public CachingApplicationPublisher InProcessTestSite { get; } = new CachingApplicationPublisher(Helpers.GetInProcessTestSitesPath()); + public CachingApplicationPublisher OutOfProcessTestSite { get; } = new CachingApplicationPublisher(Helpers.GetOutOfProcessTestSitesPath()); + public CachingApplicationPublisher StartupExceptionWebsite { get; } = new CachingApplicationPublisher(Helpers.GetTestWebSitePath("StartupExceptionWebsite")); + public CachingApplicationPublisher OverriddenServerWebSite { get; } = new CachingApplicationPublisher(Helpers.GetTestWebSitePath("OverriddenServerWebSite")); + + public void Dispose() + { + InProcessTestSite.Dispose(); + OutOfProcessTestSite.Dispose(); + StartupExceptionWebsite.Dispose(); + OverriddenServerWebSite.Dispose(); + } + + public IISDeploymentParameters GetBaseDeploymentParameters(HostingModel hostingModel = HostingModel.InProcess, bool publish = false) + { + var publisher = hostingModel == HostingModel.InProcess ? InProcessTestSite : OutOfProcessTestSite; + return GetBaseDeploymentParameters(publisher, hostingModel, publish); + } + public IISDeploymentParameters GetBaseDeploymentParameters(TestVariant variant, bool publish = false) + { + var publisher = variant.HostingModel == HostingModel.InProcess ? InProcessTestSite : OutOfProcessTestSite; + return GetBaseDeploymentParameters(publisher, new DeploymentParameters(variant), publish); + } + + public IISDeploymentParameters GetBaseDeploymentParameters(ApplicationPublisher publisher, HostingModel hostingModel = HostingModel.InProcess, bool publish = false) + { + return GetBaseDeploymentParameters( + publisher, + new DeploymentParameters(publisher.ApplicationPath, DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) + { + HostingModel = hostingModel + }, + publish); + } + + public IISDeploymentParameters GetBaseDeploymentParameters(ApplicationPublisher publisher, DeploymentParameters baseParameters, bool publish = false) + { + return new IISDeploymentParameters(baseParameters) + { + ApplicationPublisher = publisher, + ApplicationPath = publisher.ApplicationPath, + TargetFramework = Tfm.NetCoreApp22, + ApplicationType = ApplicationType.Portable, + AncmVersion = AncmVersion.AspNetCoreModuleV2, + PublishApplicationBeforeDeployment = publish, + }; + } + } +} diff --git a/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs b/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs index d23b7836e5..171bbbf22f 100644 --- a/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs +++ b/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs @@ -1,6 +1,7 @@ // 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 System.Threading.Tasks; using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; @@ -31,6 +32,10 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting parameters.ServerConfigTemplateContent = parameters.ServerConfigTemplateContent ?? File.ReadAllText("IISExpress.config"); } + if (parameters.ApplicationPublisher == null) + { + throw new InvalidOperationException("All tests should use ApplicationPublisher"); + } _deployer = IISApplicationDeployerFactory.Create(parameters, LoggerFactory); diff --git a/test/Common.FunctionalTests/Utilities/Helpers.cs b/test/Common.FunctionalTests/Utilities/Helpers.cs index c067ff46e6..77eb37d524 100644 --- a/test/Common.FunctionalTests/Utilities/Helpers.cs +++ b/test/Common.FunctionalTests/Utilities/Helpers.cs @@ -25,24 +25,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public static string GetInProcessTestSitesPath() => GetTestWebSitePath("InProcessWebSite"); public static string GetOutOfProcessTestSitesPath() => GetTestWebSitePath("OutOfProcessWebSite"); - - // Defaults to inprocess specific deployment parameters - public static IISDeploymentParameters GetBaseDeploymentParameters(string site = null, HostingModel hostingModel = HostingModel.InProcess, bool publish = false) - { - if (site == null) - { - site = hostingModel == HostingModel.InProcess ? "InProcessWebSite" : "OutOfProcessWebSite"; - } - - return new IISDeploymentParameters(GetTestWebSitePath(site), DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) - { - TargetFramework = Tfm.NetCoreApp22, - ApplicationType = ApplicationType.Portable, - AncmVersion = AncmVersion.AspNetCoreModuleV2, - HostingModel = hostingModel, - PublishApplicationBeforeDeployment = publish, - }; - } + public static async Task AssertStarts(IISDeploymentResult deploymentResult, string path = "/HelloWorld") { diff --git a/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs b/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs index 5105b753c8..af442c4521 100644 --- a/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs +++ b/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs @@ -11,13 +11,20 @@ using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class AuthenticationTests : IISFunctionalTestBase { + private readonly PublishedSitesFixture _fixture; + + public AuthenticationTests(PublishedSitesFixture fixture) + { + _fixture = fixture; + } [ConditionalFact] public async Task Authentication_InProcess() { - var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.AddWindowsAuthToServerConfig(); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs b/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs index 45c9e080aa..1e397731e7 100644 --- a/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs +++ b/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs @@ -9,21 +9,23 @@ using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Testing.xunit; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class ShutdownTests : IISFunctionalTestBase { + private readonly PublishedSitesFixture _fixture; - public ShutdownTests(ITestOutputHelper output) : base(output) + public ShutdownTests(PublishedSitesFixture fixture) { + _fixture = fixture; } [ConditionalFact] public async Task ServerShutsDownWhenMainExits() { - var parameters = Helpers.GetBaseDeploymentParameters(publish: true); + var parameters = _fixture.GetBaseDeploymentParameters(publish: true); var result = await DeployAsync(parameters); try { @@ -39,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task GracefulShutdown_DoesNotCrashProcess() { - var parameters = Helpers.GetBaseDeploymentParameters(publish: true); + var parameters = _fixture.GetBaseDeploymentParameters(publish: true); parameters.GracefulShutdown = true; var result = await DeployAsync(parameters); @@ -51,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task ForcefulShutdown_DoesrashProcess() { - var parameters = Helpers.GetBaseDeploymentParameters(publish: true); + var parameters = _fixture.GetBaseDeploymentParameters(publish: true); var result = await DeployAsync(parameters); var response = await result.RetryingHttpClient.GetAsync("/HelloWorld"); diff --git a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs b/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs index 36812d3f2e..218cb4b174 100644 --- a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs +++ b/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs @@ -11,18 +11,21 @@ using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; using Microsoft.AspNetCore.Testing.xunit; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class StartupTests : IISFunctionalTestBase { - private readonly string _dotnetLocation = DotNetCommands.GetDotNetExecutable(RuntimeArchitecture.x64); + private readonly PublishedSitesFixture _fixture; - public StartupTests(ITestOutputHelper output) : base(output) + public StartupTests(PublishedSitesFixture fixture) { + _fixture = fixture; } + private readonly string _dotnetLocation = DotNetCommands.GetDotNetExecutable(RuntimeArchitecture.x64); + [ConditionalFact] public async Task ExpandEnvironmentVariableInWebConfig() { @@ -42,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData(".\\dotnet.exe")] public async Task InvalidProcessPath_ExpectServerError(string path) { - var deploymentParameters = GetBaseDeploymentParameters(); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", path)); @@ -99,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task AssertStarts(Action preDeploy = null) { - var deploymentParameters = GetBaseDeploymentParameters(); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); preDeploy?.Invoke(deploymentParameters); @@ -121,11 +124,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task HelloWorld(TestVariant variant) { - var deploymentParameters = new IISDeploymentParameters(variant) - { - ApplicationPath = Helpers.GetInProcessTestSitesPath(), - PublishApplicationBeforeDeployment = true - }; + var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant, publish: true); var deploymentResult = await DeployAsync(deploymentParameters); @@ -138,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task DetectsOveriddenServer() { - var deploymentResult = await DeployAsync(GetBaseDeploymentParameters("OverriddenServerWebSite")); + var deploymentResult = await DeployAsync(_fixture.GetBaseDeploymentParameters(_fixture.OverriddenServerWebSite, publish: true)); var response = await deploymentResult.HttpClient.GetAsync("/"); Assert.False(response.IsSuccessStatusCode); @@ -150,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task CheckInvalidHostingModelParameter() { - var deploymentParameters = GetBaseDeploymentParameters(); + var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("hostingModel", "bogus")); var deploymentResult = await DeployAsync(deploymentParameters); @@ -161,18 +160,5 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests EventLogHelpers.VerifyEventLogEvent(TestSink, "Unknown hosting model 'bogus'. Please specify either hostingModel=\"inprocess\" or hostingModel=\"outofprocess\" in the web.config file."); } - - // Defaults to inprocess specific deployment parameters - public static IISDeploymentParameters GetBaseDeploymentParameters(string site = "InProcessWebSite") - { - return new IISDeploymentParameters(Helpers.GetTestWebSitePath(site), DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) - { - TargetFramework = Tfm.NetCoreApp22, - ApplicationType = ApplicationType.Portable, - AncmVersion = AncmVersion.AspNetCoreModuleV2, - HostingModel = HostingModel.InProcess, - PublishApplicationBeforeDeployment = site == "InProcessWebSite", - }; - } } } diff --git a/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs b/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs index 8ad7a70665..3ab5918753 100644 --- a/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs +++ b/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs @@ -13,13 +13,20 @@ using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class GlobalVersionTests : IISFunctionalTestBase { + private readonly PublishedSitesFixture _fixture; + + public GlobalVersionTests(PublishedSitesFixture fixture) + { + _fixture = fixture; + } + private const string _aspNetCoreDll = "aspnetcorev2_outofprocess.dll"; private const string _handlerVersion20 = "2.0.0"; private const string _helloWorldRequest = "HelloWorld"; private const string _helloWorldResponse = "Hello World"; - private const string _outOfProcessVersionVariable = "/p:AspNetCoreModuleOutOfProcessVersion="; [ConditionalFact] public async Task GlobalVersion_DefaultWorks() @@ -65,11 +72,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task GlobalVersion_NewVersionNumber(string version) { var deploymentParameters = GetGlobalVersionBaseDeploymentParameters(); - deploymentParameters.AdditionalPublishParameters = $"{_outOfProcessVersionVariable}{version}"; deploymentParameters.HandlerSettings["handlerVersion"] = version; var deploymentResult = await DeployAsync(deploymentParameters); + var originalANCMPath = GetANCMRequestHandlerPath(deploymentResult, _handlerVersion20); + var newANCMPath = GetANCMRequestHandlerPath(deploymentResult, version); + Directory.Move(originalANCMPath, newANCMPath); + var response = await deploymentResult.RetryingHttpClient.GetAsync(_helloWorldRequest); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); @@ -89,9 +99,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var newANCMPath = GetANCMRequestHandlerPath(deploymentResult, version); - var di = Directory.CreateDirectory(Path.GetDirectoryName(newANCMPath)); - - File.Copy(originalANCMPath, newANCMPath, true); + CopyDirectory(originalANCMPath, newANCMPath); deploymentResult.RetryingHttpClient.DefaultRequestHeaders.Add("ANCMRHPath", newANCMPath); var response = await deploymentResult.RetryingHttpClient.GetAsync("CheckRequestHandlerVersion"); @@ -125,9 +133,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var newANCMPath = GetANCMRequestHandlerPath(deploymentResult, version); - var di = Directory.CreateDirectory(Path.GetDirectoryName(newANCMPath)); - - File.Copy(originalANCMPath, newANCMPath, true); + CopyDirectory(originalANCMPath, newANCMPath); deploymentResult.RetryingHttpClient.DefaultRequestHeaders.Add("ANCMRHPath", newANCMPath); response = await deploymentResult.RetryingHttpClient.GetAsync("CheckRequestHandlerVersion"); @@ -139,23 +145,25 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private IISDeploymentParameters GetGlobalVersionBaseDeploymentParameters() { - return new IISDeploymentParameters(Helpers.GetOutOfProcessTestSitesPath(), DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) + return _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess, publish: true); + } + + private void CopyDirectory(string from, string to) + { + var toInfo = new DirectoryInfo(to); + toInfo.Create(); + + foreach (var file in new DirectoryInfo(from).GetFiles()) { - TargetFramework = Tfm.NetCoreApp22, - ApplicationType = ApplicationType.Portable, - AncmVersion = AncmVersion.AspNetCoreModuleV2, - HostingModel = HostingModel.OutOfProcess, - PublishApplicationBeforeDeployment = true, - AdditionalPublishParameters = $"{_outOfProcessVersionVariable}{_handlerVersion20}" - }; + file.CopyTo(Path.Combine(toInfo.FullName, file.Name)); + } } private string GetANCMRequestHandlerPath(IISDeploymentResult deploymentResult, string version) { return Path.Combine(deploymentResult.ContentRoot, deploymentResult.DeploymentParameters.RuntimeArchitecture.ToString(), - version, - _aspNetCoreDll); + version); } private void AssertLoadedVersion(string version) diff --git a/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs b/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs index ff9996c851..91c5291b0a 100644 --- a/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs +++ b/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs @@ -18,10 +18,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests // So these tests always have to use ports in this range, and we can't rely on OS-allocated ports without a whole lot of ceremony around // creating self-signed certificates and registering SSL bindings with HTTP.sys // Test specific to IISExpress + [Collection(PublishedSitesCollection.Name)] public class HttpsTest : IISFunctionalTestBase { - public HttpsTest(ITestOutputHelper output) : base(output) + private readonly PublishedSitesFixture _fixture; + + public HttpsTest(PublishedSitesFixture fixture) { + _fixture = fixture; } public static TestMatrix TestVariants @@ -34,12 +38,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task HttpsHelloWorld(TestVariant variant) { var port = TestPortHelper.GetNextSSLPort(); - var deploymentParameters = new IISDeploymentParameters(variant) - { - ApplicationPath = Helpers.GetOutOfProcessTestSitesPath(), - ApplicationBaseUriHint = $"https://localhost:{port}/" - }; - + var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + deploymentParameters.ApplicationBaseUriHint = $"https://localhost:{port}/"; deploymentParameters.AddHttpsToServerConfig(); var deploymentResult = await DeployAsync(deploymentParameters); @@ -73,12 +73,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task HttpsHelloWorldCerts(TestVariant variant, bool sendClientCert) { var port = TestPortHelper.GetNextSSLPort(); - var deploymentParameters = new IISDeploymentParameters(variant) - { - ApplicationPath = Helpers.GetOutOfProcessTestSitesPath(), - ApplicationBaseUriHint = $"https://localhost:{port}/", - }; - + var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + deploymentParameters.ApplicationBaseUriHint = $"https://localhost:{port}/"; deploymentParameters.AddHttpsToServerConfig(); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs b/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs index 437f019f52..b67b3b103a 100644 --- a/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs +++ b/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs @@ -13,14 +13,19 @@ using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class NtlmAuthenticationTests : IISFunctionalTestBase { // Test only runs on IISExpress today as our CI machines do not have // Windows auth installed globally. // TODO either enable windows auth on our CI or use containers to test this // behavior - public NtlmAuthenticationTests(ITestOutputHelper output) : base(output) + + private readonly PublishedSitesFixture _fixture; + + public NtlmAuthenticationTests(PublishedSitesFixture fixture) { + _fixture = fixture; } public static TestMatrix TestVariants @@ -32,11 +37,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task NtlmAuthentication(TestVariant variant) { - var deploymentParameters = new IISDeploymentParameters(variant) - { - ApplicationPath = Helpers.GetOutOfProcessTestSitesPath(), - ApplicationBaseUriHint = $"http://localhost:0/" - }; + var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + deploymentParameters.ApplicationBaseUriHint = $"https://localhost:0/"; deploymentParameters.AddWindowsAuthToServerConfig(); diff --git a/test/IISExpress.FunctionalTests/OutOfProcess/WindowsAuthTests.cs b/test/IISExpress.FunctionalTests/OutOfProcess/WindowsAuthTests.cs index 038f57029d..b46b314d08 100644 --- a/test/IISExpress.FunctionalTests/OutOfProcess/WindowsAuthTests.cs +++ b/test/IISExpress.FunctionalTests/OutOfProcess/WindowsAuthTests.cs @@ -12,10 +12,14 @@ using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class WindowsAuthTests : IISFunctionalTestBase { - public WindowsAuthTests(ITestOutputHelper output = null) : base(output) + private readonly PublishedSitesFixture _fixture; + + public WindowsAuthTests(PublishedSitesFixture fixture) { + _fixture = fixture; } public static TestMatrix TestVariants @@ -28,10 +32,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task WindowsAuthTest(TestVariant variant) { - var deploymentParameters = new IISDeploymentParameters(variant) - { - ApplicationPath = Helpers.GetOutOfProcessTestSitesPath(), - }; + var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); deploymentParameters.AddWindowsAuthToServerConfig(); // The default in hosting sets windows auth to true. diff --git a/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs b/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs index 316a87f9b3..492ae8db87 100644 --- a/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs +++ b/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs @@ -9,16 +9,18 @@ using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; using Microsoft.AspNetCore.Testing.xunit; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { + [Collection(PublishedSitesCollection.Name)] public class UpgradeFeatureDetectionTests : IISFunctionalTestBase { private readonly string _isWebsocketsSupported = Environment.OSVersion.Version >= new Version(6, 2) ? "Enabled" : "Disabled"; + private readonly PublishedSitesFixture _fixture; - public UpgradeFeatureDetectionTests(ITestOutputHelper output) : base(output) + public UpgradeFeatureDetectionTests(PublishedSitesFixture fixture) { + _fixture = fixture; } [ConditionalFact] @@ -60,14 +62,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task UpgradeFeatureDetectionDeployer(bool disableWebSocket, string sitePath, string expected, HostingModel hostingModel) { - var deploymentParameters = new IISDeploymentParameters(sitePath, DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) - { - TargetFramework = Tfm.NetCoreApp22, - ApplicationType = ApplicationType.Portable, - AncmVersion = AncmVersion.AspNetCoreModuleV2, - HostingModel = hostingModel, - PublishApplicationBeforeDeployment = hostingModel == HostingModel.InProcess - }; + var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel, publish: true); if (disableWebSocket) {