FunctionalTest for LocalizationSample
Remove LocalizationTest comments Move shared code into a private method Add CoreClr with Mono in non Windows test Fix typo
This commit is contained in:
parent
58ab5d6699
commit
6f5bddea69
|
|
@ -0,0 +1,49 @@
|
||||||
|
// 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.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Server.Testing;
|
||||||
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Localization.FunctionalTests
|
||||||
|
{
|
||||||
|
public class LocalizationSampleTest
|
||||||
|
{
|
||||||
|
private static readonly string _applicationPath = Path.GetFullPath(Path.Combine("../../samples", "LocalizationSample"));
|
||||||
|
|
||||||
|
[ConditionalTheory]
|
||||||
|
[OSSkipCondition(OperatingSystems.Linux)]
|
||||||
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
|
[InlineData(RuntimeFlavor.Clr, "http://localhost:5070/", RuntimeArchitecture.x86)]
|
||||||
|
[InlineData(RuntimeFlavor.CoreClr, "http://localhost:5071/", RuntimeArchitecture.x86)]
|
||||||
|
public Task RunSite_WindowsOnly(RuntimeFlavor runtimeFlavor, string applicationBaseUrl, RuntimeArchitecture runtimeArchitecture)
|
||||||
|
{
|
||||||
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
|
return testRunner.RunTestAndVerifyResponseHeading(
|
||||||
|
runtimeFlavor,
|
||||||
|
runtimeArchitecture,
|
||||||
|
applicationBaseUrl,
|
||||||
|
"My/Resources",
|
||||||
|
"fr-FR",
|
||||||
|
"<h1>Bonjour</h1>");
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConditionalTheory]
|
||||||
|
[OSSkipCondition(OperatingSystems.Windows)]
|
||||||
|
[InlineData(RuntimeFlavor.Mono, "http://localhost:5070/", RuntimeArchitecture.x64)]
|
||||||
|
[InlineData(RuntimeFlavor.CoreClr, "http://localhost:5071/", RuntimeArchitecture.x64)]
|
||||||
|
public Task RunSite_NonWindowsOnly(RuntimeFlavor runtimeFlavor, string applicationBaseUrl, RuntimeArchitecture runtimeArchitecture)
|
||||||
|
{
|
||||||
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
|
return testRunner.RunTestAndVerifyResponseHeading(
|
||||||
|
runtimeFlavor,
|
||||||
|
runtimeArchitecture,
|
||||||
|
applicationBaseUrl,
|
||||||
|
"My/Resources",
|
||||||
|
"fr-FR",
|
||||||
|
"<h1>Bonjour</h1>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// 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.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.Testing;
|
using Microsoft.AspNetCore.Server.Testing;
|
||||||
using Microsoft.AspNetCore.Testing.xunit;
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
|
|
@ -10,6 +11,8 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
{
|
{
|
||||||
public class LocalizationTest
|
public class LocalizationTest
|
||||||
{
|
{
|
||||||
|
private static readonly string _applicationPath = Path.GetFullPath(Path.Combine("..", "LocalizationWebsite"));
|
||||||
|
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)]
|
[OSSkipCondition(OperatingSystems.Linux)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
|
|
@ -18,12 +21,12 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_Windows(
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_Windows(
|
||||||
RuntimeFlavor runtimeFlavor,
|
RuntimeFlavor runtimeFlavor,
|
||||||
string applicationBaseUrl,
|
string applicationBaseUrl,
|
||||||
RuntimeArchitecture runtimeArchitechture)
|
RuntimeArchitecture runtimeArchitecture)
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
runtimeFlavor,
|
runtimeFlavor,
|
||||||
runtimeArchitechture,
|
runtimeArchitecture,
|
||||||
applicationBaseUrl,
|
applicationBaseUrl,
|
||||||
"ResourcesInFolder",
|
"ResourcesInFolder",
|
||||||
"fr-FR",
|
"fr-FR",
|
||||||
|
|
@ -38,12 +41,12 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_Windows(
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_Windows(
|
||||||
RuntimeFlavor runtimeFlavor,
|
RuntimeFlavor runtimeFlavor,
|
||||||
string applicationBaseUrl,
|
string applicationBaseUrl,
|
||||||
RuntimeArchitecture runtimeArchitechture)
|
RuntimeArchitecture runtimeArchitecture)
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
runtimeFlavor,
|
runtimeFlavor,
|
||||||
runtimeArchitechture,
|
runtimeArchitecture,
|
||||||
applicationBaseUrl,
|
applicationBaseUrl,
|
||||||
"ResourcesInFolder",
|
"ResourcesInFolder",
|
||||||
"fr-FR-test",
|
"fr-FR-test",
|
||||||
|
|
@ -58,12 +61,12 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
public Task Localization_ResourcesInFolder_ReturnNonLocalizedValue_CultureHierarchyTooDeep_Windows(
|
public Task Localization_ResourcesInFolder_ReturnNonLocalizedValue_CultureHierarchyTooDeep_Windows(
|
||||||
RuntimeFlavor runtimeFlavor,
|
RuntimeFlavor runtimeFlavor,
|
||||||
string applicationBaseUrl,
|
string applicationBaseUrl,
|
||||||
RuntimeArchitecture runtimeArchitechture)
|
RuntimeArchitecture runtimeArchitecture)
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
runtimeFlavor,
|
runtimeFlavor,
|
||||||
runtimeArchitechture,
|
runtimeArchitecture,
|
||||||
applicationBaseUrl,
|
applicationBaseUrl,
|
||||||
"ResourcesInFolder",
|
"ResourcesInFolder",
|
||||||
"fr-FR-test-again-too-deep-to-work",
|
"fr-FR-test-again-too-deep-to-work",
|
||||||
|
|
@ -75,7 +78,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR)]
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR)]
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_Mono()
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_Mono()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
RuntimeFlavor.Mono,
|
RuntimeFlavor.Mono,
|
||||||
RuntimeArchitecture.x86,
|
RuntimeArchitecture.x86,
|
||||||
|
|
@ -90,7 +93,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR)]
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR)]
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_Mono()
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_Mono()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
RuntimeFlavor.Mono,
|
RuntimeFlavor.Mono,
|
||||||
RuntimeArchitecture.x86,
|
RuntimeArchitecture.x86,
|
||||||
|
|
@ -105,7 +108,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_CoreCLR_NonWindows()
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_CoreCLR_NonWindows()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
RuntimeFlavor.CoreClr,
|
RuntimeFlavor.CoreClr,
|
||||||
RuntimeArchitecture.x64,
|
RuntimeArchitecture.x64,
|
||||||
|
|
@ -120,7 +123,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||||
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_CoreCLR_NonWindows()
|
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_CoreCLR_NonWindows()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
RuntimeFlavor.CoreClr,
|
RuntimeFlavor.CoreClr,
|
||||||
RuntimeArchitecture.x64,
|
RuntimeArchitecture.x64,
|
||||||
|
|
@ -138,12 +141,12 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_Windows(
|
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_Windows(
|
||||||
RuntimeFlavor runtimeFlavor,
|
RuntimeFlavor runtimeFlavor,
|
||||||
string applicationBaseUrl,
|
string applicationBaseUrl,
|
||||||
RuntimeArchitecture runtimeArchitechture)
|
RuntimeArchitecture runtimeArchitecture)
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
runtimeFlavor,
|
runtimeFlavor,
|
||||||
runtimeArchitechture,
|
runtimeArchitecture,
|
||||||
applicationBaseUrl,
|
applicationBaseUrl,
|
||||||
"ResourcesAtRootFolder",
|
"ResourcesAtRootFolder",
|
||||||
"fr-FR",
|
"fr-FR",
|
||||||
|
|
@ -155,7 +158,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR)]
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR)]
|
||||||
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_Mono()
|
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_Mono()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
RuntimeFlavor.Mono,
|
RuntimeFlavor.Mono,
|
||||||
RuntimeArchitecture.x86,
|
RuntimeArchitecture.x86,
|
||||||
|
|
@ -170,7 +173,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||||
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_CoreCLR_NonWindows()
|
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_CoreCLR_NonWindows()
|
||||||
{
|
{
|
||||||
var testRunner = new TestRunner();
|
var testRunner = new TestRunner(_applicationPath);
|
||||||
return testRunner.RunTestAndVerifyResponse(
|
return testRunner.RunTestAndVerifyResponse(
|
||||||
RuntimeFlavor.CoreClr,
|
RuntimeFlavor.CoreClr,
|
||||||
RuntimeArchitecture.x64,
|
RuntimeArchitecture.x64,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// 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;
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -14,21 +13,26 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
{
|
{
|
||||||
public class TestRunner
|
public class TestRunner
|
||||||
{
|
{
|
||||||
public async Task RunTestAndVerifyResponse(
|
private string _applicationPath;
|
||||||
|
|
||||||
|
public TestRunner(string applicationPath){
|
||||||
|
_applicationPath = applicationPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> RunTestAndGetResponse(
|
||||||
RuntimeFlavor runtimeFlavor,
|
RuntimeFlavor runtimeFlavor,
|
||||||
RuntimeArchitecture runtimeArchitechture,
|
RuntimeArchitecture runtimeArchitecture,
|
||||||
string applicationBaseUrl,
|
string applicationBaseUrl,
|
||||||
string environmentName,
|
string environmentName,
|
||||||
string locale,
|
string locale)
|
||||||
string expectedText)
|
|
||||||
{
|
{
|
||||||
var logger = new LoggerFactory()
|
var logger = new LoggerFactory()
|
||||||
.AddConsole()
|
.AddConsole()
|
||||||
.CreateLogger(string.Format("Localization Test Site:{0}:{1}:{2}", ServerType.Kestrel, runtimeFlavor, runtimeArchitechture));
|
.CreateLogger(string.Format("Localization Test Site:{0}:{1}:{2}", ServerType.Kestrel, runtimeFlavor, runtimeArchitecture));
|
||||||
|
|
||||||
using (logger.BeginScope("LocalizationTest"))
|
using (logger.BeginScope("LocalizationTest"))
|
||||||
{
|
{
|
||||||
var deploymentParameters = new DeploymentParameters(GetApplicationPath(), ServerType.Kestrel, runtimeFlavor, runtimeArchitechture)
|
var deploymentParameters = new DeploymentParameters(_applicationPath, ServerType.Kestrel, runtimeFlavor, runtimeArchitecture)
|
||||||
{
|
{
|
||||||
ApplicationBaseUriHint = applicationBaseUrl,
|
ApplicationBaseUriHint = applicationBaseUrl,
|
||||||
Command = "web",
|
Command = "web",
|
||||||
|
|
@ -54,16 +58,36 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
|
||||||
return httpClient.GetAsync(string.Empty);
|
return httpClient.GetAsync(string.Empty);
|
||||||
}, logger, deploymentResult.HostShutdownToken);
|
}, logger, deploymentResult.HostShutdownToken);
|
||||||
|
|
||||||
var responseText = await response.Content.ReadAsStringAsync();
|
return await response.Content.ReadAsStringAsync();
|
||||||
Console.WriteLine("Response Text " + responseText);
|
|
||||||
Assert.Equal(expectedText, responseText);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetApplicationPath()
|
public async Task RunTestAndVerifyResponse(
|
||||||
|
RuntimeFlavor runtimeFlavor,
|
||||||
|
RuntimeArchitecture runtimeArchitecture,
|
||||||
|
string applicationBaseUrl,
|
||||||
|
string environmentName,
|
||||||
|
string locale,
|
||||||
|
string expectedText)
|
||||||
{
|
{
|
||||||
return Path.GetFullPath(Path.Combine("..", "LocalizationWebsite"));
|
var responseText = await RunTestAndGetResponse(runtimeFlavor, runtimeArchitecture, applicationBaseUrl, environmentName, locale);
|
||||||
|
Console.WriteLine("Response Text " + responseText);
|
||||||
|
Assert.Equal(expectedText, responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RunTestAndVerifyResponseHeading(
|
||||||
|
RuntimeFlavor runtimeFlavor,
|
||||||
|
RuntimeArchitecture runtimeArchitecture,
|
||||||
|
string applicationBaseUrl,
|
||||||
|
string environmentName,
|
||||||
|
string locale,
|
||||||
|
string expectedHeadingText)
|
||||||
|
{
|
||||||
|
var responseText = await RunTestAndGetResponse(runtimeFlavor, runtimeArchitecture, applicationBaseUrl, environmentName, locale);
|
||||||
|
var headingIndex = responseText.IndexOf(expectedHeadingText);
|
||||||
|
Console.WriteLine("Response Header " + responseText);
|
||||||
|
Assert.True(headingIndex >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue