Audit culture bugs (#7707)

* Added comments and fixed CultureInfo /  StringComparison where appropriate

* Addressed comments

* Fixed comment
This commit is contained in:
Avneet Kaur
2020-10-30 16:43:09 -07:00
committed by GitHub
parent bd34127cd4
commit 2c5b9b4d52
54 changed files with 160 additions and 28 deletions

View File

@@ -20,6 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
Directory.CreateDirectory(ApplicationLogPath);
}
// Using InvariantCulture since this is used for a log file name
var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));

View File

@@ -45,7 +45,7 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
public static Mock<IIOProvider>GetModuleIOProvider(string version, string module, string fileName)
{
// Using StringComparison.Ordinal / CultureInfo.InvariantCulture since this is used internally
var stubSettingsPath = string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, module, fileName);
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains(module, StringComparison.Ordinal);
var mockIOProvider = IIOProviderMocks.GetMockIOReadWithStubFile(stubSettingsPath, filterExpression);
@@ -59,6 +59,7 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
throw new ArgumentNullException(nameof(provider));
}
// Using Ordinal since this is used internally
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains(module, StringComparison.Ordinal);
IIOProviderMocks.VerifyIOReadWithStubFile(provider, filterExpression, expectedCallCount);
@@ -66,6 +67,7 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
public static Mock<IIOProvider> GetGeneralSettingsIOProvider(string version)
{
// Using StringComparison.Ordinal / CultureInfo.InvariantCulture since this is used internally for a path
var stubGeneralSettingsPath = string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, string.Empty, "settings.json");
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
var mockGeneralIOProvider = IIOProviderMocks.GetMockIOReadWithStubFile(stubGeneralSettingsPath, filterExpression);
@@ -78,7 +80,7 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
{
throw new ArgumentNullException(nameof(provider));
}
// Using Ordinal since this is used internally for a path
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
IIOProviderMocks.VerifyIOReadWithStubFile(provider, filterExpression, expectedCallCount);
}

View File

@@ -26,11 +26,13 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
savePath = path;
saveContent = content;
});
// Using Ordinal since this is used internally for a path
mockIOProvider.Setup(x => x.ReadAllText(It.Is<string>(x => x.Equals(savePath, StringComparison.Ordinal))))
.Returns(() => saveContent);
// Using Ordinal since this is used internally for a path
mockIOProvider.Setup(x => x.FileExists(It.Is<string>(x => x.Equals(savePath, StringComparison.Ordinal))))
.Returns(true);
// Using Ordinal since this is used internally for a path
mockIOProvider.Setup(x => x.FileExists(It.Is<string>(x => !x.Equals(savePath, StringComparison.Ordinal))))
.Returns(false);

View File

@@ -167,6 +167,7 @@ namespace ViewModelTests
var settingUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
var expectedSettingsString = new ImageResizerSettings() { Properties = new ImageResizerProperties() { ImageresizerKeepDateModified = new BoolProperty() { Value = true } } }.ToJsonString();
// Using Ordinal since this is used internally
settingUtils.Setup(x => x.SaveSettings(
It.Is<string>(content => content.Equals(expectedSettingsString, StringComparison.Ordinal)),
It.Is<string>(module => module.Equals(ImageResizerSettings.ModuleName, StringComparison.Ordinal)),