mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +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:
@@ -239,7 +239,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
|
|
||||||
// Act
|
// Act
|
||||||
// Using en-us culture to have a fixed number style
|
// Using en-us culture to have a fixed number style
|
||||||
var result = engine.Interpret(input, new CultureInfo("en-us"), out _);
|
var result = engine.Interpret(input, new CultureInfo("en-us", false), out _);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
public void Translate_ThrowError_WhenCalledNull(string input)
|
public void Translate_ThrowError_WhenCalledNull(string input)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var translator = NumberTranslator.Create(new CultureInfo("de-DE"), new CultureInfo("en-US"));
|
var translator = NumberTranslator.Create(new CultureInfo("de-DE", false), new CultureInfo("en-US", false));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => translator.Translate(input));
|
Assert.ThrowsException<ArgumentNullException>(() => translator.Translate(input));
|
||||||
@@ -58,7 +58,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
public void Translate_WhenCalledEmpty(string input)
|
public void Translate_WhenCalledEmpty(string input)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var translator = NumberTranslator.Create(new CultureInfo("de-DE"), new CultureInfo("en-US"));
|
var translator = NumberTranslator.Create(new CultureInfo("de-DE", false), new CultureInfo("en-US", false));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = translator.Translate(input);
|
var result = translator.Translate(input);
|
||||||
@@ -76,7 +76,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
public void Translate_NoErrors_WhenCalled(string input, string expectedResult)
|
public void Translate_NoErrors_WhenCalled(string input, string expectedResult)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var translator = NumberTranslator.Create(new CultureInfo("de-DE"), new CultureInfo("en-US"));
|
var translator = NumberTranslator.Create(new CultureInfo("de-DE", false), new CultureInfo("en-US", false));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = translator.Translate(input);
|
var result = translator.Translate(input);
|
||||||
@@ -95,7 +95,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
public void TranslateBack_NoErrors_WhenCalled(string input, string expectedResult)
|
public void TranslateBack_NoErrors_WhenCalled(string input, string expectedResult)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var translator = NumberTranslator.Create(new CultureInfo("de-DE"), new CultureInfo("en-US"));
|
var translator = NumberTranslator.Create(new CultureInfo("de-DE", false), new CultureInfo("en-US", false));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = translator.TranslateBack(input);
|
var result = translator.TranslateBack(input);
|
||||||
@@ -113,7 +113,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
public void Translate_RemoveNumberGroupSeparator_WhenCalled(string decimalSeparator, string groupSeparator, string input, string expectedResult)
|
public void Translate_RemoveNumberGroupSeparator_WhenCalled(string decimalSeparator, string groupSeparator, string input, string expectedResult)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var sourceCulture = new CultureInfo("en-US")
|
var sourceCulture = new CultureInfo("en-US", false)
|
||||||
{
|
{
|
||||||
NumberFormat =
|
NumberFormat =
|
||||||
{
|
{
|
||||||
@@ -121,7 +121,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
NumberGroupSeparator = groupSeparator,
|
NumberGroupSeparator = groupSeparator,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
var translator = NumberTranslator.Create(sourceCulture, new CultureInfo("en-US"));
|
var translator = NumberTranslator.Create(sourceCulture, new CultureInfo("en-US", false));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = translator.Translate(input);
|
var result = translator.Translate(input);
|
||||||
@@ -137,7 +137,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||||||
public void Translate_NoRemovalOfLeadingZeroesOnEdgeCases(string input, string expectedResult)
|
public void Translate_NoRemovalOfLeadingZeroesOnEdgeCases(string input, string expectedResult)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var translator = NumberTranslator.Create(new CultureInfo("de-de"), new CultureInfo("en-US"));
|
var translator = NumberTranslator.Create(new CultureInfo("de-de", false), new CultureInfo("en-US", false));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = translator.Translate(input);
|
var result = translator.Translate(input);
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
|||||||
|
|
||||||
// Set culture to 'en-us'
|
// Set culture to 'en-us'
|
||||||
originalCulture = CultureInfo.CurrentCulture;
|
originalCulture = CultureInfo.CurrentCulture;
|
||||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
|||||||
|
|
||||||
// Set culture to 'en-us'
|
// Set culture to 'en-us'
|
||||||
originalCulture = CultureInfo.CurrentCulture;
|
originalCulture = CultureInfo.CurrentCulture;
|
||||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
|||||||
{
|
{
|
||||||
// Set culture to 'en-us'
|
// Set culture to 'en-us'
|
||||||
originalCulture = CultureInfo.CurrentCulture;
|
originalCulture = CultureInfo.CurrentCulture;
|
||||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
|
|||||||
@@ -21,14 +21,22 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
|||||||
{
|
{
|
||||||
// Set culture to 'en-us'
|
// Set culture to 'en-us'
|
||||||
originalCulture = CultureInfo.CurrentCulture;
|
originalCulture = CultureInfo.CurrentCulture;
|
||||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
|
||||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
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]
|
[DataTestMethod]
|
||||||
@@ -181,8 +189,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
|||||||
public void UtcFormatsWithShortTimeAndShortDate(string formatLabel, string expectedFormat)
|
public void UtcFormatsWithShortTimeAndShortDate(string formatLabel, string expectedFormat)
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var helperResults = AvailableResultsList.GetList(true, false, false, GetDateTimeForTest());
|
var helperResults = AvailableResultsList.GetList(true, false, false, GetDateTimeForTest(true));
|
||||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
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)
|
public void UtcFormatsWithShortTimeAndLongDate(string formatLabel, string expectedFormat)
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest());
|
var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest(true));
|
||||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
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)
|
public void UtcFormatsWithLongTimeAndShortDate(string formatLabel, string expectedFormat)
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var helperResults = AvailableResultsList.GetList(true, true, false, GetDateTimeForTest());
|
var helperResults = AvailableResultsList.GetList(true, true, false, GetDateTimeForTest(true));
|
||||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
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)
|
public void UtcFormatsWithLongTimeAndLongDate(string formatLabel, string expectedFormat)
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var helperResults = AvailableResultsList.GetList(true, true, true, GetDateTimeForTest());
|
var helperResults = AvailableResultsList.GetList(true, true, true, GetDateTimeForTest(true));
|
||||||
var expectedResult = GetDateTimeForTest().ToUniversalTime().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|||||||
Reference in New Issue
Block a user