diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs index 36ec7b6ffa..a8e04cbae5 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs @@ -1,11 +1,15 @@ -using Microsoft.PowerToys.Settings.UI.Library; -using Microsoft.PowerToys.Settings.UI.Library.Interfaces; -using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; -using Moq; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System; using System.Globalization; using System.IO.Abstractions; using System.Linq.Expressions; +using Microsoft.PowerToys.Settings.UI.Library; +using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; +using Moq; namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility { @@ -16,14 +20,17 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility // Using Ordinal since this is used internally for a path private static readonly Expression> SettingsFilterExpression = s => s == null || s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal); - internal class MockSettingsRepository : ISettingsRepository where T : ISettingsConfig, new() + internal class MockSettingsRepository : ISettingsRepository + where T : ISettingsConfig, new() { - T _settingsConfig; - readonly ISettingsUtils _settingsUtils; - public MockSettingsRepository( ISettingsUtils settingsUtils) + private readonly ISettingsUtils _settingsUtils; + private T _settingsConfig; + + public MockSettingsRepository(ISettingsUtils settingsUtils) { _settingsUtils = settingsUtils; } + public T SettingsConfig { get @@ -43,10 +50,8 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility } } - - public static MockGetModuleIOProvider(string version, string module, string fileName) + public static Mock GetModuleIOProvider(string version, string module, string fileName) { - var stubSettingsPath = StubSettingsPath(version, module, fileName); Expression> filterExpression = ModuleFilterExpression(module); return IIOProviderMocks.GetMockIOReadWithStubFile(stubSettingsPath, filterExpression); @@ -62,9 +67,9 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility return string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, module, fileName); } - public static void VerifyModuleIOProviderWasRead(Mock provider, string module, int expectedCallCount) + public static void VerifyModuleIOProviderWasRead(Mock provider, string module, int expectedCallCount) { - if(provider == null) + if (provider == null) { throw new ArgumentNullException(nameof(provider)); } @@ -95,6 +100,5 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility IIOProviderMocks.VerifyIOReadWithStubFile(provider, SettingsFilterExpression, expectedCallCount); } - } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj index 501187832b..a9b57204f2 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Microsoft.PowerToys.Settings.UI.UnitTests.csproj @@ -15,6 +15,14 @@ ..\..\..\x64\Release\SettingsTest\ + + + GlobalSuppressions.cs + + + StyleCop.json + + @@ -29,6 +37,10 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/IIOProviderMocks.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/IIOProviderMocks.cs index 226e243b08..e3aabfba86 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/IIOProviderMocks.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/IIOProviderMocks.cs @@ -1,19 +1,21 @@ -using Microsoft.PowerToys.Settings.UI.Library.Utilities; -using Moq; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System; using System.IO.Abstractions; -using System.IO.Abstractions.TestingHelpers; using System.Linq.Expressions; +using Microsoft.PowerToys.Settings.UI.Library.Utilities; +using Moq; namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks { internal static class IIOProviderMocks { - /// /// This method mocks an IO provider to validate tests wich required saving to a file, and then reading the contents of that file, or verifying it exists /// - /// + /// Mocked IO Provider internal static Mock GetMockIOProviderForSaveLoadExists() { string savePath = string.Empty; @@ -25,12 +27,15 @@ 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(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(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(x => !x.Equals(savePath, StringComparison.Ordinal)))) .Returns(false); @@ -38,27 +43,24 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks return mockIOProvider; } - - private static readonly IFileSystem FileSystem = new FileSystem(); private static readonly IFile File = FileSystem.File; + /// - /// This method mocks an IO provider so that it will always return data at the savePath location. + /// This method mocks an IO provider so that it will always return data at the savePath location. /// This mock is specific to a given module, and is verifiable that the stub file was read. /// /// The path to the stub settings file - /// The substring in the path that identifies the module eg. Microsoft\\PowerToys\\ColorPicker - /// + /// The substring in the path that identifies the module eg. Microsoft\\PowerToys\\ColorPicker + /// Mocked IFile internal static Mock GetMockIOReadWithStubFile(string savePath, Expression> filterExpression) { string saveContent = File.ReadAllText(savePath); var fileMock = new Mock(); - fileMock.Setup(x => x.ReadAllText(It.Is(filterExpression))) .Returns(() => saveContent).Verifiable(); - fileMock.Setup(x => x.Exists(It.Is(filterExpression))) .Returns(true); diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/ISettingsUtilsMocks.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/ISettingsUtilsMocks.cs index d497dd4da4..6866a3ed90 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/ISettingsUtilsMocks.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/Mocks/ISettingsUtilsMocks.cs @@ -1,13 +1,16 @@ -using Microsoft.PowerToys.Settings.UI.Library; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Moq; -using System; namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks { internal static class ISettingsUtilsMocks { - //Stubs out empty values for imageresizersettings and general settings as needed by the imageresizer viewmodel + // Stubs out empty values for imageresizersettings and general settings as needed by the imageresizer viewmodel internal static Mock GetStubSettingsUtils() where T : ISettingsConfig, new() { diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/BasePTModuleSettingsTest.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/BasePTModuleSettingsTest.cs index 67daf9a363..babdbf6d96 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/BasePTModuleSettingsTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/BasePTModuleSettingsTest.cs @@ -3,10 +3,8 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.PowerToys.Settings.UI.Library; -using Microsoft.PowerToys.Settings.UI.Library.Utilities; -using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; using System.IO.Abstractions.TestingHelpers; +using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UnitTest; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; @@ -24,7 +22,7 @@ namespace CommonLibTest [ObsoleteAttribute("This test method is obsolete.", true)] public void ToJsonStringShouldReturnValidJSONOfModelWhenSuccessful() { - //Mock Disk access + // Mock Disk access var mockFileSystem = new MockFileSystem(); var settingsUtils = new SettingsUtils(mockFileSystem); diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsRepositoryTest.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsRepositoryTest.cs index ced10464d9..a7e4c150da 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsRepositoryTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsRepositoryTest.cs @@ -5,8 +5,8 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.PowerToys.Settings.UI.Library; -using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace CommonLibTest { @@ -15,14 +15,12 @@ namespace CommonLibTest { private static Task> GetSettingsRepository(ISettingsUtils settingsUtils) { - return Task.Run(() => { return SettingsRepository.GetInstance(settingsUtils); }); } - [TestMethod] public void SettingsRepositoryInstanceWhenCalledMustReturnSameObject() { @@ -47,7 +45,7 @@ namespace CommonLibTest List>> settingsRepoTasks = new List>>(); int numberOfTasks = 100; - for(int i = 0; i < numberOfTasks; i++) + for (int i = 0; i < numberOfTasks; i++) { settingsRepoTasks.Add(GetSettingsRepository(mockSettingsUtils.Object)); } @@ -56,11 +54,10 @@ namespace CommonLibTest Task.WaitAll(settingsRepoTasks.ToArray()); // Assert - for(int i=0; i< numberOfTasks-1; i++) + for (int i = 0; i < numberOfTasks - 1; i++) { Assert.IsTrue(object.ReferenceEquals(settingsRepoTasks[i].Result, settingsRepoTasks[i + 1].Result)); } - } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs index 9c60f9b8b3..65eeb4f40c 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs @@ -3,25 +3,19 @@ // See the LICENSE file in the project root for more information. using System; -using System.IO.Abstractions; using System.IO.Abstractions.TestingHelpers; using System.Linq; using System.Text.Json; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; -using Microsoft.PowerToys.Settings.UI.Library.Utilities; -using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility; -using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; using Microsoft.PowerToys.Settings.UnitTest; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; namespace CommonLibTest { [TestClass] public class SettingsUtilsTests { - [TestMethod] public void SaveSettingsSaveSettingsToFileWhenFilePathExists() { @@ -106,9 +100,10 @@ namespace CommonLibTest .Select(s => s[random.Next(s.Length)]).ToArray()); } - partial class TestClass : ISettingsConfig + private partial class TestClass : ISettingsConfig { public int TestInt { get; set; } = 100; + public string TestString { get; set; } = "test"; public string GetModuleName() diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ColorPicker.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ColorPicker.cs index 01efdd2370..e84929ab39 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ColorPicker.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ColorPicker.cs @@ -19,12 +19,12 @@ namespace ViewModelTests /// Test if the original settings files were modified. /// [TestMethod] - [DataRow("v0.20.1", "settings.json")] //Color picker was introduced in .20 + [DataRow("v0.20.1", "settings.json")] // Color picker was introduced in .20 [DataRow("v0.21.1", "settings.json")] [DataRow("v0.22.0", "settings.json")] public void OriginalFilesModificationTest(string version, string fileName) { - //Arrange + // Arrange var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, ColorPickerSettings.ModuleName, fileName); var settingPathMock = new Mock(); @@ -37,18 +37,18 @@ namespace ViewModelTests GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings(); var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository(mockGeneralSettingsUtils); - //Act + // Act // Initialise View Model with test Config files ColorPickerViewModel viewModel = new ColorPickerViewModel(mockSettingsUtils, generalSettingsRepository, ColorPickerIsEnabledByDefaultIPC); - //Assert + // Assert // Verify that the old settings persisted Assert.AreEqual(originalGeneralSettings.Enabled.ColorPicker, viewModel.IsEnabled); Assert.AreEqual(originalSettings.Properties.ActivationShortcut.ToString(), viewModel.ActivationShortcut.ToString()); Assert.AreEqual(originalSettings.Properties.ChangeCursor, viewModel.ChangeCursor); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, ColorPickerSettings.ModuleName, expectedCallCount); BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount); } @@ -68,6 +68,5 @@ namespace ViewModelTests Assert.IsTrue(snd.GeneralSettings.Enabled.ColorPicker); return 0; } - } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/FancyZones.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/FancyZones.cs index d40f1d9e94..d39c0e25e0 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/FancyZones.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/FancyZones.cs @@ -4,7 +4,6 @@ using System; using System.Text.Json; -using CommonLibTest; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.ViewModels; using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility; @@ -69,8 +68,8 @@ namespace ViewModelTests Assert.AreEqual(originalSettings.Properties.FancyzonesZoneSetChangeMoveWindows.Value, viewModel.ZoneSetChangeMoveWindows); Assert.AreEqual(originalSettings.Properties.UseCursorposEditorStartupscreen.Value, viewModel.UseCursorPosEditorStartupScreen); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, FancyZonesSettings.ModuleName, expectedCallCount); BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount); } @@ -96,7 +95,7 @@ namespace ViewModelTests [TestMethod] public void IsEnabledShouldDisableModuleWhenSuccessful() { - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.IsFalse(snd.GeneralSettings.Enabled.FancyZones); @@ -104,7 +103,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsTrue(viewModel.IsEnabled); // check if the module is enabled. // act @@ -115,7 +114,7 @@ namespace ViewModelTests public void ShiftDragShouldSetValue2FalseWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsFalse(snd.Powertoys.FancyZones.Properties.FancyzonesShiftDrag.Value); @@ -123,7 +122,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsTrue(viewModel.ShiftDrag); // check if value was initialized to false. // act @@ -134,7 +133,7 @@ namespace ViewModelTests public void OverrideSnapHotkeysShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOverrideSnapHotkeys.Value); @@ -142,7 +141,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.OverrideSnapHotkeys); // check if value was initialized to false. // act @@ -153,7 +152,7 @@ namespace ViewModelTests public void MoveWindowsBasedOnPositionShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMoveWindowsBasedOnPosition.Value); @@ -161,7 +160,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.MoveWindowsBasedOnPosition); // check if value was initialized to false. // act @@ -172,7 +171,7 @@ namespace ViewModelTests public void ZoneSetChangeFlashZonesShouldSetValue2FalseWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMakeDraggedWindowTransparent.Value); @@ -180,7 +179,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.MakeDraggedWindowsTransparent); // check if value was initialized to false. // act @@ -191,7 +190,7 @@ namespace ViewModelTests public void MouseSwitchShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMouseSwitch.Value); @@ -199,7 +198,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.MouseSwitch); // check if value was initialized to false. // act @@ -210,7 +209,7 @@ namespace ViewModelTests public void DisplayChangeMoveWindowsShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesDisplayChangeMoveWindows.Value); @@ -218,7 +217,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.DisplayChangeMoveWindows); // check if value was initialized to false. // act @@ -229,7 +228,7 @@ namespace ViewModelTests public void ZoneSetChangeMoveWindowsShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesZoneSetChangeMoveWindows.Value); @@ -237,7 +236,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.ZoneSetChangeMoveWindows); // check if value was initialized to false. // act @@ -248,7 +247,7 @@ namespace ViewModelTests public void AppLastZoneMoveWindowsShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesAppLastZoneMoveWindows.Value); @@ -256,7 +255,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.AppLastZoneMoveWindows); // check if value was initialized to false. // act @@ -266,7 +265,7 @@ namespace ViewModelTests public void OpenWindowOnActiveMonitorShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOpenWindowOnActiveMonitor.Value); @@ -274,7 +273,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.OpenWindowOnActiveMonitor); // check if value was initialized to false. // act @@ -285,7 +284,7 @@ namespace ViewModelTests public void RestoreSizeShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesRestoreSize.Value); @@ -293,7 +292,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.RestoreSize); // check if value was initialized to false. // act @@ -304,7 +303,7 @@ namespace ViewModelTests public void UseCursorPosEditorStartupScreenShouldSetValue2FalseWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.UseCursorposEditorStartupscreen.Value); @@ -312,7 +311,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsTrue(viewModel.UseCursorPosEditorStartupScreen); // check if value was initialized to false. // act @@ -323,7 +322,7 @@ namespace ViewModelTests public void ShowOnAllMonitorsShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesShowOnAllMonitors.Value); @@ -331,7 +330,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.IsFalse(viewModel.ShowOnAllMonitors); // check if value was initialized to false. // act @@ -342,7 +341,7 @@ namespace ViewModelTests public void ZoneHighlightColorShouldSetColorValue2WhiteWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesZoneHighlightColor.Value); @@ -350,7 +349,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.AreEqual(ConfigDefaults.DefaultFancyZonesZoneHighlightColor, viewModel.ZoneHighlightColor); // act @@ -361,7 +360,7 @@ namespace ViewModelTests public void ZoneBorderColorShouldSetColorValue2WhiteWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesBorderColor.Value); @@ -369,7 +368,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.AreEqual(ConfigDefaults.DefaultFancyzonesBorderColor, viewModel.ZoneBorderColor); // act @@ -380,7 +379,7 @@ namespace ViewModelTests public void ZoneInActiveColorShouldSetColorValue2WhiteWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesInActiveColor.Value); @@ -388,7 +387,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.AreEqual(ConfigDefaults.DefaultFancyZonesInActiveColor, viewModel.ZoneInActiveColor); // act @@ -399,7 +398,7 @@ namespace ViewModelTests public void ExcludedAppsShouldSetColorValue2WhiteWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual("Sample", snd.Powertoys.FancyZones.Properties.FancyzonesExcludedApps.Value); @@ -407,7 +406,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.AreEqual(string.Empty, viewModel.ExcludedApps); // act @@ -418,7 +417,7 @@ namespace ViewModelTests public void HighlightOpacityShouldSetOpacityValueTo60WhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual(60, snd.Powertoys.FancyZones.Properties.FancyzonesHighlightOpacity.Value); @@ -426,7 +425,7 @@ namespace ViewModelTests }; // arrange - FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName); + FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName); Assert.AreEqual(50, viewModel.HighlightOpacity); // act diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/General.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/General.cs index 98a5a19bd4..88c86ec81f 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/General.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/General.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Globalization; -using System.Text.Json; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.ViewModels; using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility; @@ -18,19 +16,16 @@ namespace ViewModelTests [TestClass] public class General { - public const string generalSettingsFileName = "Test\\GenealSettings"; + public const string GeneralSettingsFileName = "Test\\GenealSettings"; private Mock mockGeneralSettingsUtils; - - [TestInitialize] public void SetUpStubSettingUtils() { mockGeneralSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils(); } - - /// + [TestMethod] [DataRow("v0.18.2")] [DataRow("v0.19.2")] @@ -47,12 +42,11 @@ namespace ViewModelTests var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository(mockGeneralSettingsUtils); - // Initialise View Model with test Config files // Arrange - Func SendMockIPCConfigMSG = msg => 0; - Func SendRestartAdminIPCMessage = msg => 0; - Func SendCheckForUpdatesIPCMessage = msg => 0; + Func sendMockIPCConfigMSG = msg => 0; + Func sendRestartAdminIPCMessage = msg => 0; + Func sendCheckForUpdatesIPCMessage = msg => 0; var viewModel = new GeneralViewModel( settingsRepository: generalSettingsRepository, runAsAdminText: "GeneralSettings_RunningAsAdminText", @@ -60,9 +54,9 @@ namespace ViewModelTests isElevated: false, isAdmin: false, updateTheme: UpdateUIThemeMethod, - ipcMSGCallBackFunc: SendMockIPCConfigMSG, - ipcMSGRestartAsAdminMSGCallBackFunc: SendRestartAdminIPCMessage, - ipcMSGCheckForUpdatesCallBackFunc: SendCheckForUpdatesIPCMessage, + ipcMSGCallBackFunc: sendMockIPCConfigMSG, + ipcMSGRestartAsAdminMSGCallBackFunc: sendRestartAdminIPCMessage, + ipcMSGCheckForUpdatesCallBackFunc: sendCheckForUpdatesIPCMessage, configFileSubfolder: string.Empty); // Verify that the old settings persisted @@ -72,8 +66,8 @@ namespace ViewModelTests Assert.AreEqual(originalGeneralSettings.RunElevated, viewModel.RunElevated); Assert.AreEqual(originalGeneralSettings.Startup, viewModel.Startup); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(fileMock, expectedCallCount); } @@ -81,9 +75,9 @@ namespace ViewModelTests public void IsElevatedShouldUpdateRunasAdminStatusAttrsWhenSuccessful() { // Arrange - Func SendMockIPCConfigMSG = msg => { return 0; }; - Func SendRestartAdminIPCMessage = msg => { return 0; }; - Func SendCheckForUpdatesIPCMessage = msg => { return 0; }; + Func sendMockIPCConfigMSG = msg => { return 0; }; + Func sendRestartAdminIPCMessage = msg => { return 0; }; + Func sendCheckForUpdatesIPCMessage = msg => { return 0; }; GeneralViewModel viewModel = new GeneralViewModel( settingsRepository: SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), "GeneralSettings_RunningAsAdminText", @@ -91,10 +85,10 @@ namespace ViewModelTests false, false, UpdateUIThemeMethod, - SendMockIPCConfigMSG, - SendRestartAdminIPCMessage, - SendCheckForUpdatesIPCMessage, - generalSettingsFileName); + sendMockIPCConfigMSG, + sendRestartAdminIPCMessage, + sendCheckForUpdatesIPCMessage, + GeneralSettingsFileName); Assert.AreEqual(viewModel.RunningAsUserDefaultText, viewModel.RunningAsText); Assert.IsFalse(viewModel.IsElevated); @@ -111,7 +105,7 @@ namespace ViewModelTests public void StartupShouldEnableRunOnStartUpWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.GeneralSettings.Startup); @@ -119,8 +113,8 @@ namespace ViewModelTests }; // Arrange - Func SendRestartAdminIPCMessage = msg => { return 0; }; - Func SendCheckForUpdatesIPCMessage = msg => { return 0; }; + Func sendRestartAdminIPCMessage = msg => { return 0; }; + Func sendCheckForUpdatesIPCMessage = msg => { return 0; }; GeneralViewModel viewModel = new GeneralViewModel( settingsRepository: SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), "GeneralSettings_RunningAsAdminText", @@ -128,10 +122,10 @@ namespace ViewModelTests false, false, UpdateUIThemeMethod, - SendMockIPCConfigMSG, - SendRestartAdminIPCMessage, - SendCheckForUpdatesIPCMessage, - generalSettingsFileName); + sendMockIPCConfigMSG, + sendRestartAdminIPCMessage, + sendCheckForUpdatesIPCMessage, + GeneralSettingsFileName); Assert.IsFalse(viewModel.Startup); // act @@ -142,15 +136,15 @@ namespace ViewModelTests public void RunElevatedShouldEnableAlwaysRunElevatedWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.GeneralSettings.RunElevated); return 0; }; - Func SendRestartAdminIPCMessage = msg => { return 0; }; - Func SendCheckForUpdatesIPCMessage = msg => { return 0; }; + Func sendRestartAdminIPCMessage = msg => { return 0; }; + Func sendCheckForUpdatesIPCMessage = msg => { return 0; }; // Arrange GeneralViewModel viewModel = new GeneralViewModel( @@ -160,10 +154,10 @@ namespace ViewModelTests false, false, UpdateUIThemeMethod, - SendMockIPCConfigMSG, - SendRestartAdminIPCMessage, - SendCheckForUpdatesIPCMessage, - generalSettingsFileName); + sendMockIPCConfigMSG, + sendRestartAdminIPCMessage, + sendCheckForUpdatesIPCMessage, + GeneralSettingsFileName); Assert.IsFalse(viewModel.RunElevated); @@ -176,16 +170,17 @@ namespace ViewModelTests { // Arrange GeneralViewModel viewModel = null; + // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.AreEqual("light", snd.GeneralSettings.Theme); return 0; }; - Func SendRestartAdminIPCMessage = msg => { return 0; }; - Func SendCheckForUpdatesIPCMessage = msg => { return 0; }; + Func sendRestartAdminIPCMessage = msg => { return 0; }; + Func sendCheckForUpdatesIPCMessage = msg => { return 0; }; viewModel = new GeneralViewModel( settingsRepository: SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), "GeneralSettings_RunningAsAdminText", @@ -193,10 +188,10 @@ namespace ViewModelTests false, false, UpdateUIThemeMethod, - SendMockIPCConfigMSG, - SendRestartAdminIPCMessage, - SendCheckForUpdatesIPCMessage, - generalSettingsFileName); + sendMockIPCConfigMSG, + sendRestartAdminIPCMessage, + sendCheckForUpdatesIPCMessage, + GeneralSettingsFileName); Assert.IsFalse(viewModel.IsLightThemeRadioButtonChecked); // act @@ -208,15 +203,15 @@ namespace ViewModelTests { // Arrange // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.AreEqual("dark", snd.GeneralSettings.Theme); return 0; }; - Func SendRestartAdminIPCMessage = msg => { return 0; }; - Func SendCheckForUpdatesIPCMessage = msg => { return 0; }; + Func sendRestartAdminIPCMessage = msg => { return 0; }; + Func sendCheckForUpdatesIPCMessage = msg => { return 0; }; GeneralViewModel viewModel = new GeneralViewModel( settingsRepository: SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), "GeneralSettings_RunningAsAdminText", @@ -224,14 +219,12 @@ namespace ViewModelTests false, false, UpdateUIThemeMethod, - SendMockIPCConfigMSG, - SendRestartAdminIPCMessage, - SendCheckForUpdatesIPCMessage, - generalSettingsFileName); + sendMockIPCConfigMSG, + sendRestartAdminIPCMessage, + sendCheckForUpdatesIPCMessage, + GeneralSettingsFileName); Assert.IsFalse(viewModel.IsDarkThemeRadioButtonChecked); - - // act viewModel.IsDarkThemeRadioButtonChecked = true; } @@ -239,11 +232,10 @@ namespace ViewModelTests [TestMethod] public void AllModulesAreEnabledByDefault() { - //arrange + // arrange EnabledModules modules = new EnabledModules(); - - //Assert + // Assert Assert.IsTrue(modules.FancyZones); Assert.IsTrue(modules.ImageResizer); Assert.IsTrue(modules.FileExplorerPreview); diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ImageResizer.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ImageResizer.cs index 452b54a8d9..1e306eadaf 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ImageResizer.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ImageResizer.cs @@ -3,12 +3,10 @@ // See the LICENSE file in the project root for more information. using System; -using System.IO.Abstractions; using System.IO.Abstractions.TestingHelpers; using System.Linq; using System.Text.Json; using Microsoft.PowerToys.Settings.UI.Library; -using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels; using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility; using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; @@ -31,7 +29,6 @@ namespace ViewModelTests _mockImgResizerSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils(); } - /// /// Test if the original settings files were modified. /// @@ -57,8 +54,8 @@ namespace ViewModelTests var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository(mockGeneralSettingsUtils); // Initialise View Model with test Config files - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG); // Verify that the old settings persisted Assert.AreEqual(originalGeneralSettings.Enabled.ImageResizer, viewModel.IsEnabled); @@ -70,8 +67,8 @@ namespace ViewModelTests Assert.AreEqual(originalSettings.Properties.ImageresizerSizes.Value.Count, viewModel.Sizes.Count); Assert.AreEqual(originalSettings.Properties.ImageresizerTiffCompressOption.Value, viewModel.TiffCompressOption); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, ImageResizerSettings.ModuleName, expectedCallCount); BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralFileMock, expectedCallCount); } @@ -80,7 +77,7 @@ namespace ViewModelTests public void IsEnabledShouldEnableModuleWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.GeneralSettings.Enabled.ImageResizer); @@ -88,7 +85,7 @@ namespace ViewModelTests }; // arrange - ImageResizerViewModel viewModel = new ImageResizerViewModel(_mockImgResizerSettingsUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + ImageResizerViewModel viewModel = new ImageResizerViewModel(_mockImgResizerSettingsUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); // act viewModel.IsEnabled = true; @@ -100,14 +97,14 @@ namespace ViewModelTests // arrange var fileSystemMock = new MockFileSystem(); var mockSettingsUtils = new SettingsUtils(fileSystemMock); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); // act viewModel.JPEGQualityLevel = 10; // Assert - viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); Assert.AreEqual(10, viewModel.JPEGQualityLevel); } @@ -117,14 +114,14 @@ namespace ViewModelTests // arrange var fileSystemMock = new MockFileSystem(); var mockSettingsUtils = new SettingsUtils(fileSystemMock); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); // act viewModel.PngInterlaceOption = 10; // Assert - viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); Assert.AreEqual(10, viewModel.PngInterlaceOption); } @@ -134,14 +131,14 @@ namespace ViewModelTests // arrange var fileSystemMock = new MockFileSystem(); var mockSettingsUtils = new SettingsUtils(fileSystemMock); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); // act viewModel.TiffCompressOption = 10; // Assert - viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); Assert.AreEqual(10, viewModel.TiffCompressOption); } @@ -151,15 +148,15 @@ namespace ViewModelTests // arrange var fileSystemMock = new MockFileSystem(); var mockSettingsUtils = new SettingsUtils(fileSystemMock); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); string expectedValue = "%1 (%3)"; // act viewModel.FileName = expectedValue; // Assert - viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); Assert.AreEqual(expectedValue, viewModel.FileName); } @@ -170,6 +167,7 @@ namespace ViewModelTests var settingUtils = ISettingsUtilsMocks.GetStubSettingsUtils(); 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(content => content.Equals(expectedSettingsString, StringComparison.Ordinal)), @@ -177,8 +175,8 @@ namespace ViewModelTests It.IsAny())) .Verifiable(); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); // act viewModel.KeepDateModified = true; @@ -193,14 +191,14 @@ namespace ViewModelTests // arrange var fileSystemMock = new MockFileSystem(); var mockSettingsUtils = new SettingsUtils(fileSystemMock); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); // act viewModel.Encoder = 3; // Assert - viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); Assert.AreEqual("163bcc30-e2e9-4f0b-961d-a3e9fdb788a3", viewModel.EncoderGuid); Assert.AreEqual(3, viewModel.Encoder); } @@ -210,8 +208,8 @@ namespace ViewModelTests { // arrange var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils(); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); int sizeOfOriginalArray = viewModel.Sizes.Count; // act @@ -226,8 +224,8 @@ namespace ViewModelTests { // arrange var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils(); - Func SendMockIPCConfigMSG = msg => { return 0; }; - ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG); int sizeOfOriginalArray = viewModel.Sizes.Count; ImageSize deleteCandidate = viewModel.Sizes.Where(x => x.Id == 0).First(); diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs index 3662d18094..267d60a95b 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs @@ -2,15 +2,12 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.ViewModels; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Moq; -using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility; -using System.Globalization; -using System.IO.Abstractions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; namespace ViewModelTests { @@ -23,6 +20,7 @@ namespace ViewModelTests // PowerLauncherSettings is unused, but required according to SendCallback's signature. // Naming parameter with discard symbol to suppress FxCop warnings. + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "We actually don't validate setting, just calculate it was sent")] public void OnSend(PowerLauncherSettings _) { TimesSent++; @@ -32,6 +30,7 @@ namespace ViewModelTests private PowerLauncherViewModel viewModel; private PowerLauncherSettings mockSettings; private SendCallbackMock sendCallbackMock; + [TestInitialize] public void Initialize() { @@ -66,8 +65,8 @@ namespace ViewModelTests var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository(mockGeneralSettingsUtils); // Initialise View Model with test Config files - Func SendMockIPCConfigMSG = msg => { return 0; }; - PowerLauncherViewModel viewModel = new PowerLauncherViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG, 32); + Func sendMockIPCConfigMSG = msg => { return 0; }; + PowerLauncherViewModel viewModel = new PowerLauncherViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG, 32); // Verify that the old settings persisted Assert.AreEqual(originalGeneralSettings.Enabled.PowerLauncher, viewModel.EnablePowerLauncher); @@ -82,8 +81,8 @@ namespace ViewModelTests Assert.AreEqual(originalSettings.Properties.SearchResultPreference, viewModel.SearchResultPreference); Assert.AreEqual(originalSettings.Properties.SearchTypePreference, viewModel.SearchTypePreference); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerLauncherSettings.ModuleName, expectedCallCount); BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount); } @@ -108,7 +107,8 @@ namespace ViewModelTests Assert.AreEqual(alt, setting.Alt); Assert.AreEqual(shift, setting.Shift); Assert.AreEqual(code, setting.Code); - } else + } + else { Assert.Fail("setting parameter is null"); } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerPreview.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerPreview.cs index c68c973eae..4e9e4606e2 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerPreview.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerPreview.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.IO.Abstractions; using System.Text.Json; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.ViewModels; @@ -17,7 +16,6 @@ namespace ViewModelTests [TestClass] public class PowerPreview { - private Mock mockPowerPreviewSettingsUtils; private Mock mockGeneralSettingsUtils; @@ -53,8 +51,8 @@ namespace ViewModelTests var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository(mockGeneralSettingsUtils); // Initialise View Model with test Config files - Func SendMockIPCConfigMSG = msg => { return 0; }; - PowerPreviewViewModel viewModel = new PowerPreviewViewModel(repository, generalSettingsRepository, SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + PowerPreviewViewModel viewModel = new PowerPreviewViewModel(repository, generalSettingsRepository, sendMockIPCConfigMSG); // Verify that the old settings persisted Assert.AreEqual(originalGeneralSettings.IsElevated, viewModel.IsElevated); @@ -62,17 +60,16 @@ namespace ViewModelTests Assert.AreEqual(originalSettings.Properties.EnableSvgPreview, viewModel.SVGRenderIsEnabled); Assert.AreEqual(originalSettings.Properties.EnableSvgThumbnail, viewModel.SVGThumbnailIsEnabled); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, PowerPreviewSettings.ModuleName, expectedCallCount); } - [TestMethod] public void SVGRenderIsEnabledShouldPrevHandlerWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { SndModuleSettings snd = JsonSerializer.Deserialize>(msg); Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableSvgPreview); @@ -80,7 +77,7 @@ namespace ViewModelTests }; // arrange - PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, PowerPreviewSettings.ModuleName); + PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName); // act viewModel.SVGRenderIsEnabled = true; @@ -90,7 +87,7 @@ namespace ViewModelTests public void SVGThumbnailIsEnabledShouldPrevHandlerWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { SndModuleSettings snd = JsonSerializer.Deserialize>(msg); Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableSvgThumbnail); @@ -98,7 +95,7 @@ namespace ViewModelTests }; // arrange - PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, PowerPreviewSettings.ModuleName); + PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName); // act viewModel.SVGThumbnailIsEnabled = true; @@ -108,7 +105,7 @@ namespace ViewModelTests public void MDRenderIsEnabledShouldPrevHandlerWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { SndModuleSettings snd = JsonSerializer.Deserialize>(msg); Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableMdPreview); @@ -116,7 +113,7 @@ namespace ViewModelTests }; // arrange - PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, PowerPreviewSettings.ModuleName); ; + PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName); // act viewModel.MDRenderIsEnabled = true; diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerRename.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerRename.cs index 571d061734..7c0eb10f31 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerRename.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/PowerRename.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.IO.Abstractions; using System.Text.Json; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.ViewModels; @@ -17,7 +16,7 @@ namespace ViewModelTests [TestClass] public class PowerRename { - public const string generalSettingsFileName = "Test\\PowerRename"; + public const string GeneralSettingsFileName = "Test\\PowerRename"; private Mock mockGeneralSettingsUtils; @@ -42,11 +41,10 @@ namespace ViewModelTests { var settingPathMock = new Mock(); var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerRenameSettings.ModuleName, fileName); - + var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object); PowerRenameLocalProperties originalSettings = mockSettingsUtils.GetSettings(PowerRenameSettings.ModuleName); - var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version); var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object); @@ -54,8 +52,8 @@ namespace ViewModelTests var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository(mockGeneralSettingsUtils); // Initialise View Model with test Config files - Func SendMockIPCConfigMSG = msg => { return 0; }; - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG); // Verify that the old settings persisted Assert.AreEqual(originalGeneralSettings.Enabled.PowerRename, viewModel.IsEnabled); @@ -63,8 +61,8 @@ namespace ViewModelTests Assert.AreEqual(originalSettings.MRUEnabled, viewModel.MRUEnabled); Assert.AreEqual(originalSettings.ShowIcon, viewModel.EnabledOnContextMenu); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerRenameSettings.ModuleName, expectedCallCount); BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount); } @@ -73,7 +71,7 @@ namespace ViewModelTests public void IsEnabledShouldEnableModuleWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.GeneralSettings.Enabled.PowerRename); @@ -81,7 +79,7 @@ namespace ViewModelTests }; // arrange - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); // act viewModel.IsEnabled = true; @@ -91,7 +89,7 @@ namespace ViewModelTests public void MRUEnabledShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.PowerRename.Properties.MRUEnabled.Value); @@ -99,7 +97,7 @@ namespace ViewModelTests }; // arrange - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); // act viewModel.MRUEnabled = true; @@ -108,8 +106,8 @@ namespace ViewModelTests [TestMethod] public void WhenIsEnabledIsOffAndMRUEnabledIsOffGlobalAndMruShouldBeOff() { - Func SendMockIPCConfigMSG = msg => { return 0; }; - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + Func sendMockIPCConfigMSG = msg => { return 0; }; + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); viewModel.IsEnabled = false; viewModel.MRUEnabled = false; @@ -120,8 +118,8 @@ namespace ViewModelTests [TestMethod] public void WhenIsEnabledIsOffAndMRUEnabledIsOnGlobalAndMruShouldBeOff() { - Func SendMockIPCConfigMSG = msg => { return 0; }; - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + Func sendMockIPCConfigMSG = msg => { return 0; }; + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); viewModel.IsEnabled = false; viewModel.MRUEnabled = true; @@ -132,8 +130,8 @@ namespace ViewModelTests [TestMethod] public void WhenIsEnabledIsOnAndMRUEnabledIsOffGlobalAndMruShouldBeOff() { - Func SendMockIPCConfigMSG = msg => { return 0; }; - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + Func sendMockIPCConfigMSG = msg => { return 0; }; + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); viewModel.IsEnabled = true; viewModel.MRUEnabled = false; @@ -144,8 +142,8 @@ namespace ViewModelTests [TestMethod] public void WhenIsEnabledIsOnAndMRUEnabledIsOnGlobalAndMruShouldBeOn() { - Func SendMockIPCConfigMSG = msg => { return 0; }; - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + Func sendMockIPCConfigMSG = msg => { return 0; }; + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); viewModel.IsEnabled = true; viewModel.MRUEnabled = true; @@ -157,7 +155,7 @@ namespace ViewModelTests public void EnabledOnContextMenuShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.PowerRename.Properties.ShowIcon.Value); @@ -165,7 +163,7 @@ namespace ViewModelTests }; // arrange - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); // act viewModel.EnabledOnContextMenu = true; @@ -175,7 +173,7 @@ namespace ViewModelTests public void EnabledOnContextExtendedMenuShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.PowerRename.Properties.ShowIcon.Value); @@ -183,7 +181,7 @@ namespace ViewModelTests }; // arrange - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); // act viewModel.EnabledOnContextMenu = true; @@ -193,7 +191,7 @@ namespace ViewModelTests public void RestoreFlagsOnLaunchShouldSetValue2TrueWhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.Powertoys.PowerRename.Properties.PersistState.Value); @@ -201,7 +199,7 @@ namespace ViewModelTests }; // arrange - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); // act viewModel.RestoreFlagsOnLaunch = true; @@ -211,7 +209,7 @@ namespace ViewModelTests public void MaxDispListNumShouldSetMaxSuggListTo20WhenSuccessful() { // Assert - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual(20, snd.Powertoys.PowerRename.Properties.MaxMRUSize.Value); @@ -219,7 +217,7 @@ namespace ViewModelTests }; // arrange - PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName); + PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName); // act viewModel.MaxDispListNum = 20; diff --git a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ShortcutGuide.cs b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ShortcutGuide.cs index 53f7a11f06..8d5655f52c 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ShortcutGuide.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/ShortcutGuide.cs @@ -41,16 +41,16 @@ namespace ViewModelTests var shortcutSettingsRepository = new BackCompatTestProperties.MockSettingsRepository(mockSettingsUtils); // Initialise View Model with test Config files - Func SendMockIPCConfigMSG = msg => { return 0; }; - ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(generalSettingsRepository, shortcutSettingsRepository, SendMockIPCConfigMSG); + Func sendMockIPCConfigMSG = msg => { return 0; }; + ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(generalSettingsRepository, shortcutSettingsRepository, sendMockIPCConfigMSG); // Verify that the old settings persisted Assert.AreEqual(originalGeneralSettings.Enabled.ShortcutGuide, viewModel.IsEnabled); Assert.AreEqual(originalSettings.Properties.OverlayOpacity.Value, viewModel.OverlayOpacity); Assert.AreEqual(originalSettings.Properties.PressTime.Value, viewModel.PressTime); - //Verify that the stub file was used - var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings) + // Verify that the stub file was used + var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings) BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, ShortcutGuideSettings.ModuleName, expectedCallCount); BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount); } @@ -71,7 +71,7 @@ namespace ViewModelTests { // Assert // Initialize mock function of sending IPC message. - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg); Assert.IsTrue(snd.GeneralSettings.Enabled.ShortcutGuide); @@ -79,7 +79,7 @@ namespace ViewModelTests }; // Arrange - ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName); + ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName); // Act viewModel.IsEnabled = true; @@ -90,7 +90,7 @@ namespace ViewModelTests { // Assert // Initialize mock function of sending IPC message. - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual("dark", snd.Powertoys.ShortcutGuide.Properties.Theme.Value); @@ -98,7 +98,8 @@ namespace ViewModelTests }; // Arrange - ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName); + ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName); + // Initialize shortcut guide settings theme to 'system' to be in sync with shortcut_guide.h. Assert.AreEqual(2, viewModel.ThemeIndex); @@ -111,7 +112,7 @@ namespace ViewModelTests { // Assert // Initialize mock function of sending IPC message. - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); Assert.AreEqual(100, snd.Powertoys.ShortcutGuide.Properties.PressTime.Value); @@ -119,7 +120,7 @@ namespace ViewModelTests }; // Arrange - ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName); + ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName); Assert.AreEqual(900, viewModel.PressTime); // Act @@ -131,7 +132,7 @@ namespace ViewModelTests { // Assert // Initialize mock function of sending IPC message. - Func SendMockIPCConfigMSG = msg => + Func sendMockIPCConfigMSG = msg => { ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); @@ -141,7 +142,7 @@ namespace ViewModelTests }; // Arrange - ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName); + ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName); Assert.AreEqual(90, viewModel.OverlayOpacity); // Act