Use published apps in IIS tests (#7027)

This commit is contained in:
Pavel Krymets 2019-01-28 12:02:42 -08:00 committed by GitHub
parent 436d4452aa
commit 440204892e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 90 additions and 10 deletions

View File

@ -183,18 +183,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
await StartAsync(deploymentParameters);
}
[ConditionalFact(Skip="https://github.com/aspnet/AspNetCore/issues/3950")]
[ConditionalFact]
[RequiresIIS(IISCapability.PoolEnvironmentVariables)]
public async Task StartsWithPortableAndBootstraperExe()
{
var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite, publish: true);
// We need the right dotnet on the path in IIS
deploymentParameters.EnvironmentVariables["PATH"] = Path.GetDirectoryName(DotNetCommands.GetDotNetExecutable(deploymentParameters.RuntimeArchitecture));
// rest publisher as it doesn't support additional parameters
deploymentParameters.ApplicationPublisher = null;
// ReferenceTestTasks is workaround for https://github.com/dotnet/sdk/issues/2482
deploymentParameters.AdditionalPublishParameters = "-p:RuntimeIdentifier=win7-x64 -p:UseAppHost=true -p:SelfContained=false -p:ReferenceTestTasks=false";
deploymentParameters.AdditionalPublishParameters = "AppHost";
var deploymentResult = await DeployAsync(deploymentParameters);
Assert.True(File.Exists(Path.Combine(deploymentResult.ContentRoot, "InProcessWebSite.exe")));

View File

@ -0,0 +1,50 @@
// 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.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
{
public class PublishedApplicationPublisher: ApplicationPublisher
{
private readonly string _applicationPath;
public PublishedApplicationPublisher(string applicationPath) : base(applicationPath)
{
_applicationPath = applicationPath;
}
public override Task<PublishedApplication> Publish(DeploymentParameters deploymentParameters, ILogger logger)
{
// Treat AdditionalPublishParameters as profile name if defined
string profileName;
if (!string.IsNullOrEmpty(deploymentParameters.AdditionalPublishParameters))
{
profileName = deploymentParameters.AdditionalPublishParameters;
}
else if (deploymentParameters.ApplicationType == ApplicationType.Portable)
{
profileName = "Portable";
}
else
{
profileName = "Standalone-" + deploymentParameters.RuntimeArchitecture;
}
var configuration = this.GetType().GetTypeInfo().Assembly.GetCustomAttribute<AssemblyConfigurationAttribute>().Configuration;
var path = Path.Combine(_applicationPath, "bin", configuration, deploymentParameters.TargetFramework, "publish", profileName);
logger.LogInformation("Using prepublished application from {PublishDir}", path);
var target = CreateTempDirectory();
var source = new DirectoryInfo(path);
CachingApplicationPublisher.CopyFiles(source, target, logger);
return Task.FromResult(new PublishedApplication(target.FullName, logger));
}
}
}

View File

@ -19,13 +19,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
public class PublishedSitesFixture : IDisposable
{
public CachingApplicationPublisher InProcessTestSite { get; } = new CachingApplicationPublisher(Helpers.GetInProcessTestSitesPath());
public CachingApplicationPublisher OutOfProcessTestSite { get; } = new CachingApplicationPublisher(Helpers.GetOutOfProcessTestSitesPath());
public PublishedApplicationPublisher InProcessTestSite { get; } = new PublishedApplicationPublisher(Helpers.GetInProcessTestSitesPath());
public PublishedApplicationPublisher OutOfProcessTestSite { get; } = new PublishedApplicationPublisher(Helpers.GetOutOfProcessTestSitesPath());
public void Dispose()
{
InProcessTestSite.Dispose();
OutOfProcessTestSite.Dispose();
}
public IISDeploymentParameters GetBaseDeploymentParameters(HostingModel hostingModel = HostingModel.InProcess, bool publish = false)

View File

@ -116,11 +116,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
TargetFramework = Tfm.NetCoreApp30,
AncmVersion = AncmVersion.AspNetCoreModuleV2,
HostingModel = HostingModel.InProcess,
PublishApplicationBeforeDeployment = true,
PublishApplicationBeforeDeployment = true
};
_configure(deploymentParameters);
deploymentParameters.ApplicationPublisher = new PublishedApplicationPublisher(deploymentParameters.ApplicationPath);
_deployer = IISApplicationDeployerFactory.Create(deploymentParameters, _loggerFactory);
_deploymentResult = (IISDeploymentResult)_deployer.DeployAsync().Result;
}

View File

@ -6,6 +6,14 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<!-- UseAppHost is a workaround for https://github.com/aspnet/websdk/issues/422 -->
<TestAssetPublishProfile Include="Portable" Properties="UseAppHost=false;TargetFramework=netcoreapp3.0" />
<TestAssetPublishProfile Include="Standalone-x64" Properties="RuntimeIdentifier=win7-x64;" />
<TestAssetPublishProfile Include="Standalone-x86" Properties="RuntimeIdentifier=win7-x86;" />
<TestAssetPublishProfile Include="AppHost" Properties="RuntimeIdentifier=win7-x64;UseAppHost=true;SelfContained=false;" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\shared\**\*.cs" />
<Compile Include="..\InProcessWebSite\*.cs" />

View File

@ -7,6 +7,14 @@
<InProcessTestSite>true</InProcessTestSite>
</PropertyGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<!-- UseAppHost is a workaround for https://github.com/aspnet/websdk/issues/422 -->
<TestAssetPublishProfile Include="Portable" Properties="UseAppHost=false;TargetFramework=netcoreapp3.0" />
<TestAssetPublishProfile Include="Standalone-x64" Properties="RuntimeIdentifier=win7-x64;" />
<TestAssetPublishProfile Include="Standalone-x86" Properties="RuntimeIdentifier=win7-x86;" />
<TestAssetPublishProfile Include="AppHost" Properties="RuntimeIdentifier=win7-x64;UseAppHost=true;SelfContained=false;" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\shared\**\*.cs" />
<None Include="wwwroot\**" CopyToOutputDirectory="Always" />

View File

@ -7,6 +7,12 @@
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<TestAssetPublishProfile Include="Portable" Properties="UseAppHost=false;TargetFramework=netcoreapp3.0" />
<TestAssetPublishProfile Include="Standalone-x64" Properties="RuntimeIdentifier=win7-x64;" />
<TestAssetPublishProfile Include="Standalone-x86" Properties="RuntimeIdentifier=win7-x86;" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\shared\**\*.cs" />
</ItemGroup>

View File

@ -9,6 +9,7 @@
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
<!-- Work around until we get a new WebSdk -->
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
<BuildProjectReferences Condition="'$(_InsidePublishTestsAssets)' == 'True'">False</BuildProjectReferences>
</PropertyGroup>
<Import Project="assets.props" />
@ -78,4 +79,14 @@
<Exec Command="$(InjectDepsApp) &quot;$(PublishDepsFilePath)&quot; $(RuntimeIdentifier) " />
</Target>
<Target Name="PublishTestsAssets" AfterTargets="Build" Condition="'$(_InsidePublishTestsAssets)' != 'true' AND '@(TestAssetPublishProfile->Count())' != '0'">
<!--
_InsidePublishTestsAssets is to avoid invoking this target recursively
Platform;PlatformTarget removal is fix builds inside VS -->
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="Publish"
RemoveProperties="Platform;PlatformTarget"
Properties="ReferenceTestTasks=false;_InsidePublishTestsAssets=True;PublishDir=$(PublishDir)%(TestAssetPublishProfile.Identity)/;%(TestAssetPublishProfile.Properties)" />
</Target>
</Project>