<commit_before>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Xunit;

namespace System.Globalization.Tests
{
    public class CultureInfoAsync
    {        
        [Fact]
        public void TestCurrentCulturesAsync()
        {
            CultureInfo currentCulture = CultureInfo.CurrentCulture;
            CultureInfo currentUICulture = CultureInfo.CurrentUICulture;

            CultureInfo newCurrentCulture = new CultureInfo(currentCulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");
            CultureInfo newCurrentUICulture = new CultureInfo(currentUICulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");
            
            CultureInfo.CurrentCulture = newCurrentCulture;
            CultureInfo.CurrentUICulture = newCurrentUICulture;
            
            try
            {
                Task t = Task.Run(() => {
                    Assert.Equal(CultureInfo.CurrentCulture, newCurrentCulture);
                    Assert.Equal(CultureInfo.CurrentUICulture, newCurrentUICulture);
                });

                ((IAsyncResult)t).AsyncWaitHandle.WaitOne();
                t.Wait();                
            }
            finally
            {
                CultureInfo.CurrentCulture = currentCulture;
                CultureInfo.CurrentUICulture = currentUICulture;
            }
        }
        
        [Fact]
        public void TestCurrentCulturesWithAwait()
        {
            CultureInfo currentCulture = CultureInfo.CurrentCulture;
            CultureInfo currentUICulture = CultureInfo.CurrentUICulture;

            CultureInfo newCurrentCulture = new CultureInfo(currentCulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");
            CultureInfo newCurrentUICulture = new CultureInfo(currentUICulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");
            
            CultureInfo.CurrentCulture = newCurrentCulture;
            CultureInfo.CurrentUICulture = newCurrentUICulture;
            
            Func<Task> mainAsync = async delegate 
            {
                await Task.Delay(1).ConfigureAwait(false);
                
                Assert.Equal(CultureInfo.CurrentCulture, newCurrentCulture);
                Assert.Equal(CultureInfo.CurrentUICulture, newCurrentUICulture);
            };
            
            try 
            {
                mainAsync().Wait();
            }
            finally
            {
                CultureInfo.CurrentCulture = currentCulture;
                CultureInfo.CurrentUICulture = currentUICulture;               
            }                
        }
    }
}
<commit_msg>Make "remote" more CultureInfo.CurrentCulture setting tests (#40891)<commit_after>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;

namespace System.Globalization.Tests
{
    public class CultureInfoAsync
    {        
        [Fact]
        public void TestCurrentCulturesAsync()
        {
            RemoteExecutor.Invoke(() =>
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                CultureInfo currentUICulture = CultureInfo.CurrentUICulture;

                CultureInfo newCurrentCulture = new CultureInfo(currentCulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");
                CultureInfo newCurrentUICulture = new CultureInfo(currentUICulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");

                CultureInfo.CurrentCulture = newCurrentCulture;
                CultureInfo.CurrentUICulture = newCurrentUICulture;

                try
                {
                    Task t = Task.Run(() =>
                    {
                        Assert.Equal(CultureInfo.CurrentCulture, newCurrentCulture);
                        Assert.Equal(CultureInfo.CurrentUICulture, newCurrentUICulture);
                    });

                    ((IAsyncResult)t).AsyncWaitHandle.WaitOne();
                    t.Wait();
                }
                finally
                {
                    CultureInfo.CurrentCulture = currentCulture;
                    CultureInfo.CurrentUICulture = currentUICulture;
                }
            }).Dispose();
        }
        
        [Fact]
        public void TestCurrentCulturesWithAwait()
        {
            RemoteExecutor.Invoke(() =>
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                CultureInfo currentUICulture = CultureInfo.CurrentUICulture;

                CultureInfo newCurrentCulture = new CultureInfo(currentCulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");
                CultureInfo newCurrentUICulture = new CultureInfo(currentUICulture.Name.Equals("ja-JP", StringComparison.OrdinalIgnoreCase) ? "en-US" : "ja-JP");

                CultureInfo.CurrentCulture = newCurrentCulture;
                CultureInfo.CurrentUICulture = newCurrentUICulture;

                async Task MainAsync()
                {
                    await Task.Delay(1).ConfigureAwait(false);

                    Assert.Equal(CultureInfo.CurrentCulture, newCurrentCulture);
                    Assert.Equal(CultureInfo.CurrentUICulture, newCurrentUICulture);
                }

                try
                {
                    MainAsync().Wait();
                }
                finally
                {
                    CultureInfo.CurrentCulture = currentCulture;
                    CultureInfo.CurrentUICulture = currentUICulture;
                }
            }).Dispose();
        }
    }
}

{'fraction_non_alphanumeric': 0.08064254421547948, 'fraction_numerical': 0.0011358104819081617, 'mean_word_length': 1.7790802524797114, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6815198', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1392, 'n_words': 275}