Make functional tests run for desktop
* Convert functional tests to run using TestServer * Allow functional tests to run in parallel. Fixes #360 Fixes #390
This commit is contained in:
parent
fe3b5ea4dd
commit
a403d39405
|
|
@ -1,6 +1,6 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<Import Project="..\..\build\dependencies.props" />
|
<Import Project="..\..\build\common.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,38 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// 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.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
using LocalizationSample;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
{
|
{
|
||||||
public class LocalizationSampleTest
|
public class LocalizationSampleTest
|
||||||
{
|
{
|
||||||
private static readonly string _applicationPath = Path.Combine("samples", "LocalizationSample");
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task RunSite()
|
public async Task LocalizationSampleSmokeTest()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner(_applicationPath);
|
// Arrange
|
||||||
|
var webHostBuilder = new WebHostBuilder().UseStartup(typeof(Startup));
|
||||||
|
var testHost = new TestServer(webHostBuilder);
|
||||||
|
var locale = "fr-FR";
|
||||||
|
var client = testHost.CreateClient();
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, "My/Resources");
|
||||||
|
var cookieValue = $"c={locale}|uic={locale}";
|
||||||
|
request.Headers.Add("Cookie", $"{CookieRequestCultureProvider.DefaultCookieName}={cookieValue}");
|
||||||
|
|
||||||
return testRunner.RunTestAndVerifyResponseHeading(
|
// Act
|
||||||
RuntimeArchitecture.x64,
|
var response = await client.SendAsync(request);
|
||||||
"My/Resources",
|
|
||||||
"fr-FR",
|
// Assert
|
||||||
"<h1>Bonjour</h1>");
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
Assert.Contains("<h1>Bonjour</h1>", await response.Content.ReadAsStringAsync());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,24 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.IO;
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
using LocalizationWebsite;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
{
|
{
|
||||||
public class LocalizationTest
|
public class LocalizationTest
|
||||||
{
|
{
|
||||||
private static readonly string _applicationPath = Path.Combine("test", "LocalizationWebsite");
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Localization_CustomCulture()
|
public Task Localization_CustomCulture()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner(_applicationPath);
|
return RunTest(
|
||||||
|
typeof(StartupCustomCulturePreserved),
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
|
||||||
RuntimeArchitecture.x64,
|
|
||||||
"CustomCulturePreserved",
|
|
||||||
"en-US",
|
"en-US",
|
||||||
"kr10.00");
|
"kr10.00");
|
||||||
}
|
}
|
||||||
|
|
@ -27,11 +26,8 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Localization_ResourcesInClassLibrary_ReturnLocalizedValue()
|
public Task Localization_ResourcesInClassLibrary_ReturnLocalizedValue()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner(_applicationPath);
|
return RunTest(
|
||||||
|
typeof(StartupResourcesInClassLibrary),
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
|
||||||
RuntimeArchitecture.x64,
|
|
||||||
"ResourcesInClassLibrary",
|
|
||||||
"fr-FR",
|
"fr-FR",
|
||||||
"Bonjour from ResourcesClassLibraryNoAttribute Bonjour from ResourcesClassLibraryNoAttribute Bonjour from ResourcesClassLibraryWithAttribute Bonjour from ResourcesClassLibraryWithAttribute");
|
"Bonjour from ResourcesClassLibraryNoAttribute Bonjour from ResourcesClassLibraryNoAttribute Bonjour from ResourcesClassLibraryWithAttribute Bonjour from ResourcesClassLibraryWithAttribute");
|
||||||
}
|
}
|
||||||
|
|
@ -39,11 +35,8 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue()
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner(_applicationPath);
|
return RunTest(
|
||||||
|
typeof(StartupResourcesInFolder),
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
|
||||||
RuntimeArchitecture.x64,
|
|
||||||
"ResourcesInFolder",
|
|
||||||
"fr-FR",
|
"fr-FR",
|
||||||
"Bonjour from StartupResourcesInFolder Bonjour from Test in resources folder Bonjour from Customer in resources folder Hello");
|
"Bonjour from StartupResourcesInFolder Bonjour from Test in resources folder Bonjour from Customer in resources folder Hello");
|
||||||
}
|
}
|
||||||
|
|
@ -51,11 +44,8 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback()
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner(_applicationPath);
|
return RunTest(
|
||||||
|
typeof(StartupResourcesInFolder),
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
|
||||||
RuntimeArchitecture.x64,
|
|
||||||
"ResourcesInFolder",
|
|
||||||
"fr-FR-test",
|
"fr-FR-test",
|
||||||
"Bonjour from StartupResourcesInFolder Bonjour from Test in resources folder Bonjour from Customer in resources folder Hello");
|
"Bonjour from StartupResourcesInFolder Bonjour from Test in resources folder Bonjour from Customer in resources folder Hello");
|
||||||
}
|
}
|
||||||
|
|
@ -63,11 +53,8 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Localization_ResourcesInFolder_ReturnNonLocalizedValue_CultureHierarchyTooDeep()
|
public Task Localization_ResourcesInFolder_ReturnNonLocalizedValue_CultureHierarchyTooDeep()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner(_applicationPath);
|
return RunTest(
|
||||||
|
typeof(StartupResourcesInFolder),
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
|
||||||
RuntimeArchitecture.x64,
|
|
||||||
"ResourcesInFolder",
|
|
||||||
"fr-FR-test-again-too-deep-to-work",
|
"fr-FR-test-again-too-deep-to-work",
|
||||||
"Hello Hello Hello Hello");
|
"Hello Hello Hello Hello");
|
||||||
}
|
}
|
||||||
|
|
@ -75,13 +62,26 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue()
|
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner(_applicationPath);
|
return RunTest(
|
||||||
|
typeof(StartupResourcesAtRootFolder),
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
|
||||||
RuntimeArchitecture.x64,
|
|
||||||
"ResourcesAtRootFolder",
|
|
||||||
"fr-FR",
|
"fr-FR",
|
||||||
"Bonjour from StartupResourcesAtRootFolder Bonjour from Test in root folder Bonjour from Customer in Models folder");
|
"Bonjour from StartupResourcesAtRootFolder Bonjour from Test in root folder Bonjour from Customer in Models folder");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task RunTest(Type startupType, string culture, string expected)
|
||||||
|
{
|
||||||
|
var webHostBuilder = new WebHostBuilder().UseStartup(startupType);
|
||||||
|
var testHost = new TestServer(webHostBuilder);
|
||||||
|
|
||||||
|
var client = testHost.CreateClient();
|
||||||
|
var request = new HttpRequestMessage();
|
||||||
|
var cookieValue = $"c={culture}|uic={culture}";
|
||||||
|
request.Headers.Add("Cookie", $"{CookieRequestCultureProvider.DefaultCookieName}={cookieValue}");
|
||||||
|
|
||||||
|
var response = await client.SendAsync(request);
|
||||||
|
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
Assert.Contains(expected, await response.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,13 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\samples\LocalizationSample\LocalizationSample.csproj" />
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Localization\Microsoft.AspNetCore.Localization.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Localization\Microsoft.AspNetCore.Localization.csproj" />
|
||||||
|
<ProjectReference Include="..\LocalizationWebsite\LocalizationWebsite.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting" Version="$(AspNetIntegrationTestingVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]
|
|
||||||
|
|
@ -1,109 +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 System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
|
||||||
{
|
|
||||||
public class TestRunner
|
|
||||||
{
|
|
||||||
private const string ApplicationBasePath = "http://localhost:0";
|
|
||||||
|
|
||||||
private string _applicationPath;
|
|
||||||
|
|
||||||
public TestRunner(string applicationPath)
|
|
||||||
{
|
|
||||||
_applicationPath = Path.Combine(ResolveRootFolder(AppContext.BaseDirectory), applicationPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string ResolveRootFolder(string projectFolder)
|
|
||||||
{
|
|
||||||
var di = new DirectoryInfo(projectFolder);
|
|
||||||
|
|
||||||
while (di.Parent != null)
|
|
||||||
{
|
|
||||||
var globalJsonPath = Path.Combine(di.FullName, "version.xml");
|
|
||||||
|
|
||||||
if (File.Exists(globalJsonPath))
|
|
||||||
{
|
|
||||||
return di.FullName;
|
|
||||||
}
|
|
||||||
|
|
||||||
di = di.Parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we don't find any files then make the project folder the root
|
|
||||||
return projectFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<string> RunTestAndGetResponse(
|
|
||||||
RuntimeArchitecture runtimeArchitecture,
|
|
||||||
string environmentName,
|
|
||||||
string locale)
|
|
||||||
{
|
|
||||||
var loggerFactory = new LoggerFactory();
|
|
||||||
|
|
||||||
var deploymentParameters = new DeploymentParameters(_applicationPath, ServerType.Kestrel, RuntimeFlavor.CoreClr, runtimeArchitecture)
|
|
||||||
{
|
|
||||||
ApplicationBaseUriHint = ApplicationBasePath,
|
|
||||||
EnvironmentName = environmentName,
|
|
||||||
TargetFramework = "netcoreapp2.0"
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
|
|
||||||
{
|
|
||||||
var deploymentResult = await deployer.DeployAsync();
|
|
||||||
|
|
||||||
var cookie = new Cookie(CookieRequestCultureProvider.DefaultCookieName, "c=" + locale + "|uic=" + locale);
|
|
||||||
var cookieContainer = new CookieContainer();
|
|
||||||
cookieContainer.Add(new Uri(deploymentResult.ApplicationBaseUri), cookie);
|
|
||||||
|
|
||||||
var httpClientHandler = new HttpClientHandler();
|
|
||||||
httpClientHandler.CookieContainer = cookieContainer;
|
|
||||||
|
|
||||||
using (var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) })
|
|
||||||
{
|
|
||||||
var logger = loggerFactory.CreateLogger(string.Format("Localization Test Site:{0}:{1}", ServerType.Kestrel, runtimeArchitecture));
|
|
||||||
|
|
||||||
// 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 httpClient.GetAsync(string.Empty);
|
|
||||||
}, logger, deploymentResult.HostShutdownToken);
|
|
||||||
|
|
||||||
return await response.Content.ReadAsStringAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task RunTestAndVerifyResponse(
|
|
||||||
RuntimeArchitecture runtimeArchitecture,
|
|
||||||
string environmentName,
|
|
||||||
string locale,
|
|
||||||
string expectedText)
|
|
||||||
{
|
|
||||||
var responseText = await RunTestAndGetResponse(runtimeArchitecture, environmentName, locale);
|
|
||||||
Console.WriteLine("Response Text " + responseText);
|
|
||||||
Assert.Equal(expectedText, responseText);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task RunTestAndVerifyResponseHeading(
|
|
||||||
RuntimeArchitecture runtimeArchitecture,
|
|
||||||
string environmentName,
|
|
||||||
string locale,
|
|
||||||
string expectedHeadingText)
|
|
||||||
{
|
|
||||||
var responseText = await RunTestAndGetResponse(runtimeArchitecture, environmentName, locale);
|
|
||||||
var headingIndex = responseText.IndexOf(expectedHeadingText);
|
|
||||||
Console.WriteLine("Response Header " + responseText);
|
|
||||||
Assert.True(headingIndex >= 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue