Skip to content

Commit db4cc14

Browse files
committed
Add functional test
1 parent 017bb4d commit db4cc14

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using LocalizationWebsite.Models;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Localization;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Localization;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace LocalizationWebsite
13+
{
14+
public class StartupBuilderAPIs
15+
{
16+
public void ConfigureServices(IServiceCollection services)
17+
{
18+
services.AddLocalization(options => options.ResourcesPath = "Resources");
19+
}
20+
21+
public void Configure(
22+
IApplicationBuilder app,
23+
ILoggerFactory loggerFactory,
24+
IStringLocalizer<Customer> customerStringLocalizer)
25+
{
26+
var supportedCultures = new[] { "en-US", "fr-FR" };
27+
app.UseRequestLocalization(options =>
28+
options
29+
.AddSupportedCultures(supportedCultures)
30+
.AddSupportedUICultures(supportedCultures)
31+
.SetDefaultCulture("ar-YE")
32+
);
33+
34+
app.Run(async (context) =>
35+
{
36+
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
37+
var requestCulture = requestCultureFeature.RequestCulture;
38+
await context.Response.WriteAsync(customerStringLocalizer["Hello"]);
39+
});
40+
}
41+
}
42+
}

test/Microsoft.AspNetCore.Localization.FunctionalTests/LocalizationTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue()
7777
"Bonjour from StartupResourcesAtRootFolder Bonjour from Test in root folder Bonjour from Customer in Models folder");
7878
}
7979

80+
[Fact]
81+
public Task Localization_BuilderAPIs()
82+
{
83+
return RunTest(
84+
typeof(StartupBuilderAPIs),
85+
"ar-YE",
86+
"Hello");
87+
}
88+
8089
private async Task RunTest(Type startupType, string culture, string expected)
8190
{
8291
var webHostBuilder = new WebHostBuilder().UseStartup(startupType);

0 commit comments

Comments
 (0)