Add functional test

This commit is contained in:
hishamco 2018-01-24 00:22:19 +03:00
parent 017bb4dd4f
commit db4cc14522
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,42 @@
// 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 LocalizationWebsite.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
namespace LocalizationWebsite
{
public class StartupBuilderAPIs
{
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
}
public void Configure(
IApplicationBuilder app,
ILoggerFactory loggerFactory,
IStringLocalizer<Customer> customerStringLocalizer)
{
var supportedCultures = new[] { "en-US", "fr-FR" };
app.UseRequestLocalization(options =>
options
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures)
.SetDefaultCulture("ar-YE")
);
app.Run(async (context) =>
{
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
var requestCulture = requestCultureFeature.RequestCulture;
await context.Response.WriteAsync(customerStringLocalizer["Hello"]);
});
}
}
}

View File

@ -77,6 +77,15 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
"Bonjour from StartupResourcesAtRootFolder Bonjour from Test in root folder Bonjour from Customer in Models folder");
}
[Fact]
public Task Localization_BuilderAPIs()
{
return RunTest(
typeof(StartupBuilderAPIs),
"ar-YE",
"Hello");
}
private async Task RunTest(Type startupType, string culture, string expected)
{
var webHostBuilder = new WebHostBuilder().UseStartup(startupType);