mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[Tests]Disallow user override of culture options while running tests (#28207)
* [Tests]Disallow user override of culture options while running tests * Revert unintended changes to the system's plugin * Embed utc in the date to run utc tests on other timezones
This commit is contained in:
@@ -24,9 +24,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
|
||||
// Set culture to 'en-us'
|
||||
originalCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
|
||||
// Set culture to 'en-us'
|
||||
originalCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
{
|
||||
// Set culture to 'en-us'
|
||||
originalCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
|
||||
@@ -21,14 +21,22 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
{
|
||||
// Set culture to 'en-us'
|
||||
originalCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
|
||||
}
|
||||
|
||||
private DateTime GetDateTimeForTest()
|
||||
private DateTime GetDateTimeForTest(bool embedUtc = false)
|
||||
{
|
||||
return new DateTime(2022, 03, 02, 22, 30, 45);
|
||||
var dateTime = new DateTime(2022, 03, 02, 22, 30, 45);
|
||||
if (embedUtc)
|
||||
{
|
||||
return DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
|
||||
}
|
||||
else
|
||||
{
|
||||
return dateTime;
|
||||
}
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
@@ -181,8 +189,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void UtcFormatsWithShortTimeAndShortDate(string formatLabel, string expectedFormat)
|
||||
{
|
||||
// Setup
|
||||
var helperResults = AvailableResultsList.GetList(true, false, false, GetDateTimeForTest());
|
||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
var helperResults = AvailableResultsList.GetList(true, false, false, GetDateTimeForTest(true));
|
||||
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
|
||||
// Act
|
||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
||||
@@ -201,8 +209,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void UtcFormatsWithShortTimeAndLongDate(string formatLabel, string expectedFormat)
|
||||
{
|
||||
// Setup
|
||||
var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest());
|
||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest(true));
|
||||
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
|
||||
// Act
|
||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
||||
@@ -221,8 +229,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void UtcFormatsWithLongTimeAndShortDate(string formatLabel, string expectedFormat)
|
||||
{
|
||||
// Setup
|
||||
var helperResults = AvailableResultsList.GetList(true, true, false, GetDateTimeForTest());
|
||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
var helperResults = AvailableResultsList.GetList(true, true, false, GetDateTimeForTest(true));
|
||||
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
|
||||
// Act
|
||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
||||
@@ -241,8 +249,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void UtcFormatsWithLongTimeAndLongDate(string formatLabel, string expectedFormat)
|
||||
{
|
||||
// Setup
|
||||
var helperResults = AvailableResultsList.GetList(true, true, true, GetDateTimeForTest());
|
||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
var helperResults = AvailableResultsList.GetList(true, true, true, GetDateTimeForTest(true));
|
||||
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||
|
||||
// Act
|
||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Reference in New Issue
Block a user