Skip to content

Commit

Permalink
Merge pull request #33291 from cincuranet/fix-local-locale
Browse files Browse the repository at this point in the history
Forcibly sets "en-US" locale.

* English locale is needed for comparisons, string to number parsing, etc. operations to succeed.
* It does not deal with locale on the database side, which might result in i.e. different sorting and hence tests failing.
  • Loading branch information
cincuranet authored Mar 12, 2024
2 parents d05e031 + fa1862f commit 98c33c7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<Compile Include="..\..\src\Shared\MemberInfoExtensions.cs" Link="MemberInfoExtensions.cs" />
<Compile Include="..\Shared\ModuleInitializer.cs" Link="ModuleInitializer.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<None Include="Scaffolding\Baselines\**\*" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\ModuleInitializer.cs" Link="ModuleInitializer.cs" />
</ItemGroup>

<ItemGroup>
<Using Include="System.Data.Common" />
<Using Include="System.Diagnostics" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<None Include="Scaffolding\Baselines\**\*" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\ModuleInitializer.cs" Link="ModuleInitializer.cs" />
</ItemGroup>

<ItemGroup>
<Using Include="System.Data.Common" />
<Using Include="System.Diagnostics" />
Expand Down
4 changes: 4 additions & 0 deletions test/EFCore.Tests/EFCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\ModuleInitializer.cs" Link="ModuleInitializer.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EFCore.InMemory.FunctionalTests\EFCore.InMemory.FunctionalTests.csproj" />
<ProjectReference Include="..\EFCore.Specification.Tests\EFCore.Specification.Tests.csproj" />
Expand Down
23 changes: 23 additions & 0 deletions test/Shared/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Runtime.CompilerServices;

internal static class ModuleInitializer
{
[ModuleInitializer]
internal static void Initialize()
{
InitializeLocale();
}

private static void InitializeLocale()
{
var culture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
}

0 comments on commit 98c33c7

Please sign in to comment.