Add content/webroot and currect directory tests (#1103)
This commit is contained in:
parent
61b4473abe
commit
afa5d60821
|
|
@ -2,6 +2,7 @@
|
|||
// 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.Runtime.InteropServices;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -32,7 +33,9 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
hostBuilder.CaptureStartupErrors(true);
|
||||
|
||||
var iisConfigData = NativeMethods.HttpGetApplicationProperties();
|
||||
hostBuilder.UseContentRoot(iisConfigData.pwzFullApplicationPath);
|
||||
// Trim trailing slash to be consistent with other servers
|
||||
var contentRoot = iisConfigData.pwzFullApplicationPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||
hostBuilder.UseContentRoot(contentRoot);
|
||||
return hostBuilder.ConfigureServices(
|
||||
services => {
|
||||
services.AddSingleton(new IISNativeApplication(iisConfigData.pNativeApplication));
|
||||
|
|
|
|||
|
|
@ -175,7 +175,9 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS
|
|||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true
|
||||
RedirectStandardOutput = true,
|
||||
// VS sets current directory to C:\Program Files\IIS Express
|
||||
WorkingDirectory = Path.GetDirectoryName(iisExpressPath)
|
||||
};
|
||||
|
||||
AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.EnvironmentVariables);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS
|
|||
offset += count;
|
||||
} while (count != 0 && offset != buffer.Length);
|
||||
|
||||
readAsStreamAsync.Position = 0;
|
||||
_logger.Log(logLevel, Encoding.ASCII.GetString(buffer, 0, offset));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
// 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.Testing.xunit;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||
{
|
||||
[Collection(IISTestSiteCollection.Name)]
|
||||
public class HostingEnvironmentTests: FixtureLoggedTest
|
||||
{
|
||||
private readonly IISTestSiteFixture _fixture;
|
||||
|
||||
public HostingEnvironmentTests(IISTestSiteFixture fixture): base(fixture)
|
||||
{
|
||||
_fixture = fixture;
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[RequiresIIS(IISCapability.ShutdownToken)]
|
||||
public async Task HostingEnvironmentIsCorrect()
|
||||
{
|
||||
Assert.Equal(
|
||||
$"ContentRootPath {_fixture.DeploymentResult.ContentRoot}" + Environment.NewLine +
|
||||
$"WebRootPath {_fixture.DeploymentResult.ContentRoot}\\wwwroot" + Environment.NewLine +
|
||||
$"CurrentDirectory {Path.GetDirectoryName(_fixture.DeploymentResult.HostProcess.MainModule.FileName)}",
|
||||
await _fixture.Client.GetStringAsync("/HostingEnvironment"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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.IIS.FunctionalTests.Utilities;
|
||||
|
|
@ -58,6 +59,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
responseText = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Assert.True("backcompat;Windows".Equals(responseText) || "latest;null".Equals(responseText), "Auth");
|
||||
|
||||
Assert.Equal(
|
||||
$"ContentRootPath {deploymentResult.ContentRoot}" + Environment.NewLine +
|
||||
$"WebRootPath {deploymentResult.ContentRoot}\\wwwroot" + Environment.NewLine +
|
||||
$"CurrentDirectory {deploymentResult.ContentRoot}",
|
||||
await deploymentResult.HttpClient.GetStringAsync("/HostingEnvironment"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
|
||||
_deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory);
|
||||
|
||||
DeploymentResult = _deployer.DeployAsync().Result;
|
||||
DeploymentResult = (IISDeploymentResult)_deployer.DeployAsync().Result;
|
||||
Client = DeploymentResult.HttpClient;
|
||||
BaseUri = DeploymentResult.ApplicationBaseUri;
|
||||
ShutdownToken = DeploymentResult.HostShutdownToken;
|
||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
public string BaseUri { get; }
|
||||
public HttpClient Client { get; }
|
||||
public CancellationToken ShutdownToken { get; }
|
||||
public DeploymentResult DeploymentResult { get; }
|
||||
public IISDeploymentResult DeploymentResult { get; }
|
||||
|
||||
public TestConnection CreateTestConnection()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Import Project="..\..\..\build\testsite.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
@ -13,6 +13,10 @@
|
|||
<Compile Include="..\shared\**\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\**" CopyToOutputDirectory="Always" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(MicrosoftAspNetCoreHostingPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(MicrosoftAspNetCoreWebUtilitiesPackageVersion)" />
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@ namespace IISTestSite
|
|||
});
|
||||
}
|
||||
|
||||
private async Task HostingEnvironment(HttpContext context)
|
||||
{
|
||||
var hostingEnv = context.RequestServices.GetService<IHostingEnvironment>();
|
||||
|
||||
await context.Response.WriteAsync("ContentRootPath "+hostingEnv.ContentRootPath + Environment.NewLine);
|
||||
await context.Response.WriteAsync("WebRootPath "+hostingEnv.WebRootPath + Environment.NewLine);
|
||||
await context.Response.WriteAsync("CurrentDirectory "+Environment.CurrentDirectory);
|
||||
}
|
||||
|
||||
private void AuthenticationRestricted(IApplicationBuilder app)
|
||||
{
|
||||
app.Run(async ctx =>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@
|
|||
<Compile Include="..\shared\**\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\**" CopyToOutputDirectory="Always" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(MicrosoftAspNetCoreWebUtilitiesPackageVersion)" />
|
||||
|
|
|
|||
|
|
@ -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.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ namespace TestSites
|
|||
factory.AddConsole();
|
||||
factory.AddFilter("Console", level => level >= LogLevel.Information);
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>()
|
||||
.UseKestrel()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Security.Principal;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.IISIntegration.FunctionalTests;
|
||||
|
|
@ -104,5 +105,14 @@ namespace TestSites
|
|||
|
||||
return context.Response.WriteAsync(context.Request.Headers["ANCMRHPath"]);
|
||||
}
|
||||
|
||||
private async Task HostingEnvironment(HttpContext context)
|
||||
{
|
||||
var hostingEnv = context.RequestServices.GetService<IHostingEnvironment>();
|
||||
|
||||
await context.Response.WriteAsync("ContentRootPath "+hostingEnv.ContentRootPath + Environment.NewLine);
|
||||
await context.Response.WriteAsync("WebRootPath "+hostingEnv.WebRootPath + Environment.NewLine);
|
||||
await context.Response.WriteAsync("CurrentDirectory "+Environment.CurrentDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue