aspnetcore/test/IISIntegration.FunctionalTests/UpgradeFeatureDetectionTest...

100 lines
4.0 KiB
C#

// 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;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
{
public class UpgradeFeatureDetectionTests : LoggedTest
{
private string _isWebsocketsSupported = Environment.OSVersion.Version >= new Version(6, 2) ? "Enabled" : "Disabled";
public UpgradeFeatureDetectionTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public Task UpgradeFeatureDetectionDisabled_InProcess_IISExpress()
{
return UpgradeFeatureDetectionDeployer("AppHostConfig/WebsocketsNotSupported.config",
Helpers.GetInProcessTestSitesPath(),
"Disabled");
}
[Fact]
public Task UpgradeFeatureDetectionEnabled_InProcess_IISExpress()
{
return UpgradeFeatureDetectionDeployer("AppHostConfig/Http.config",
Helpers.GetInProcessTestSitesPath(),
_isWebsocketsSupported);
}
[Fact]
public Task UpgradeFeatureDetectionDisabled_OutOfProcess_IISExpress()
{
return UpgradeFeatureDetectionDeployer("AppHostConfig/WebsocketsNotSupported.config",
Helpers.GetOutOfProcessTestSitesPath(),
"Disabled");
}
[Fact]
public Task UpgradeFeatureDetectionEnabled_OutOfProcess_IISExpress()
{
return UpgradeFeatureDetectionDeployer("AppHostConfig/Http.config",
Helpers.GetOutOfProcessTestSitesPath(),
_isWebsocketsSupported);
}
private async Task UpgradeFeatureDetectionDeployer(string configPath, string sitePath, string expected)
{
var testName = $"HelloWorld";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("HelloWorldTest");
var deploymentParameters = new DeploymentParameters(sitePath, ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64)
{
EnvironmentName = "UpgradeFeatureDetection", // Will pick the Start class named 'StartupHelloWorld',
ServerConfigTemplateContent = File.ReadAllText(configPath),
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = Tfm.NetCoreApp22,
ApplicationType = ApplicationType.Portable,
AncmVersion = AncmVersion.AspNetCoreModuleV2
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync("UpgradeFeatureDetection");
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal(expected, responseText);
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
}
}
}