Skip to content

Commit 0acb3d9

Browse files
committed
Fix test and feedback
1 parent 1f97466 commit 0acb3d9

File tree

4 files changed

+56
-31
lines changed

4 files changed

+56
-31
lines changed

src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ internal async Task RunAsyncCore(CancellationToken cancellationToken, WebAssembl
172172
var (rootComponents, renderer, initializationTcs) = state;
173173
try
174174
{
175-
if (Services.GetService<CultureStateProvider>() is CultureStateProvider cultureStateProvider)
176-
{
177-
cultureStateProvider.ApplyStoredCulture();
178-
}
179175
// Here, we add each root component but don't await the returned tasks so that the
180176
// components can be processed in parallel.
181177
var count = rootComponents.Count;

src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,24 +1202,6 @@ public void CanPersistPrerenderedState_WebAssemblyPrerenderedStateAvailableOnlyO
12021202
Browser.Equal("not restored", () => Browser.FindElement(By.Id("wasm")).Text);
12031203
}
12041204

1205-
[Fact]
1206-
public void CanPersistCultureFromServer()
1207-
{
1208-
_serverFixture.AdditionalArguments.Add("EnforceServerCultureOnClient=true");
1209-
1210-
Navigate($"{ServerPathBase}/Culture/SetCulture?culture=fr-FR&redirectUri={Uri.EscapeDataString($"{ServerPathBase}/persist-culture-state")}");
1211-
Browser.Exists(By.ClassName("return-from-culture-setter")).Click();
1212-
1213-
Browser.Equal("Prerender", () => Browser.FindElement(By.Id("prerender")).Text);
1214-
Browser.Equal("fr-FR", () => Browser.FindElement(By.Id("culture-set")).Text);
1215-
Browser.Equal("fr-FR", () => Browser.FindElement(By.Id("culture-ui-set")).Text);
1216-
1217-
Browser.Exists(By.Id("start-blazor")).Click();
1218-
1219-
Browser.Equal("Interactive", () => Browser.FindElement(By.Id("interactive")).Text);
1220-
Browser.Equal("fr-FR", () => Browser.FindElement(By.Id("culture-set")).Text);
1221-
}
1222-
12231205
[Fact]
12241206
public void DoesNotPersistCultureFromServerAsDefault()
12251207
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using Components.TestServer.RazorComponents;
6+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
7+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
8+
using Microsoft.AspNetCore.E2ETesting;
9+
using OpenQA.Selenium;
10+
using TestServer;
11+
using Xunit.Abstractions;
12+
13+
namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests;
14+
15+
[CollectionDefinition(nameof(InteractivityTest), DisableParallelization = true)]
16+
public class LocalizationTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>>
17+
{
18+
public LocalizationTest(
19+
BrowserFixture browserFixture,
20+
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
21+
ITestOutputHelper output)
22+
: base(browserFixture, serverFixture, output)
23+
{
24+
}
25+
26+
protected override void InitializeAsyncCore()
27+
{
28+
_serverFixture.AdditionalArguments.Add("EnforceServerCultureOnClient=true");
29+
base.InitializeAsyncCore();
30+
}
31+
32+
[Fact]
33+
public void CanPersistCultureFromServer()
34+
{
35+
Navigate($"{ServerPathBase}/Culture/SetCulture?culture=fr-FR&redirectUri={Uri.EscapeDataString($"{ServerPathBase}/persist-culture-state")}");
36+
Browser.Exists(By.ClassName("return-from-culture-setter")).Click();
37+
38+
Browser.Equal("Prerender", () => Browser.FindElement(By.Id("prerender")).Text);
39+
Browser.Equal("fr-FR", () => Browser.FindElement(By.Id("culture-set")).Text);
40+
Browser.Equal("fr-FR", () => Browser.FindElement(By.Id("culture-ui-set")).Text);
41+
42+
Browser.Exists(By.Id("start-blazor")).Click();
43+
44+
Browser.Equal("Interactive", () => Browser.FindElement(By.Id("interactive")).Text);
45+
Browser.Equal("fr-FR", () => Browser.FindElement(By.Id("culture-set")).Text);
46+
}
47+
}

src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
100100

101101
app.Map("/subdir", app =>
102102
{
103-
app.UseRequestLocalization(options =>
104-
{
105-
options.AddSupportedCultures("en-US", "fr-FR");
106-
options.AddSupportedUICultures("en-US", "fr-FR");
107-
options.RequestCultureProviders.Clear();
108-
options.RequestCultureProviders.Add(new CookieRequestCultureProvider());
109-
options.SetDefaultCulture("en-US");
110-
});
111-
112103
app.Map("/reexecution", reexecutionApp =>
113104
{
114105
app.Map("/trigger-404", app =>
@@ -134,6 +125,15 @@ private void ConfigureSubdirPipeline(IApplicationBuilder app, IWebHostEnvironmen
134125
{
135126
WebAssemblyTestHelper.ServeCoopHeadersIfWebAssemblyThreadingEnabled(app);
136127

128+
app.UseRequestLocalization(options =>
129+
{
130+
options.AddSupportedCultures("en-US", "fr-FR");
131+
options.AddSupportedUICultures("en-US", "fr-FR");
132+
options.RequestCultureProviders.Clear();
133+
options.RequestCultureProviders.Add(new CookieRequestCultureProvider());
134+
options.SetDefaultCulture("en-US");
135+
});
136+
137137
if (!env.IsDevelopment())
138138
{
139139
app.UseExceptionHandler("/Error", createScopeForErrors: true);

0 commit comments

Comments
 (0)