mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
[Settings] Adding Tests to Verify Backward Compatibility (#6161)
* compare config files * create settings files * updated path check * reverted color picker changes * added test files * removed settings uralted files * Modifying directory structure and adding properties for backcompat test. * Updating Unit test to use mock repositories. 1) BackCompatTestProperties exposes mock repository implementation because SettingsRepository is a singleton, and settings utils isn't typed. 2) BackCompatTestProperties, encapsulates logic to verify that the correct file was read from. 3) Validating each file is read twice. Once by the original file, and once via the view model. * Adding 18.2 settings files. * Fix compiler errors from latest merge * Adding v0.19.2 test files. * Adding in 0.20.1 settings. Removing 0.20.2 (as this was a dev build number) * Adding settings tests for 22.1 * General Settings should update version when they don't match * Adding v0.22.0 files * Removing not settings related files from TestData for PT Run 21.1 * Referencing module name as *Settings.ModuleName in tests. Except for ImageResizer * Using ImageResizerSettings to use Settings for the module name. * Setting AllPlugins to empty list in case PluginManager.Save/Load/ReloadData is called before plugins are loaded * Fixing fxcop errors * using named parameters as per review feedback Co-authored-by: ryanbodrug-microsoft <56318517+ryanbodrug-microsoft@users.noreply.github.com>
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
@@ -21,11 +23,56 @@ namespace ViewModelTests
|
||||
|
||||
private Mock<ISettingsUtils> mockGeneralSettingsUtils;
|
||||
|
||||
|
||||
|
||||
[TestInitialize]
|
||||
public void SetUpStubSettingUtils()
|
||||
{
|
||||
mockGeneralSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>();
|
||||
}
|
||||
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[DataRow("v0.18.2")]
|
||||
[DataRow("v0.19.2")]
|
||||
[DataRow("v0.20.1")]
|
||||
[DataRow("v0.21.1")]
|
||||
[DataRow("v0.22.0")]
|
||||
public void OriginalFilesModificationTest(string version)
|
||||
{
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
// Arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
|
||||
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
|
||||
var viewModel = new GeneralViewModel(
|
||||
settingsRepository: generalSettingsRepository,
|
||||
runAsAdminText: "GeneralSettings_RunningAsAdminText",
|
||||
runAsUserText: "GeneralSettings_RunningAsUserText",
|
||||
isElevated: false,
|
||||
isAdmin: false,
|
||||
updateTheme: UpdateUIThemeMethod,
|
||||
ipcMSGCallBackFunc: SendMockIPCConfigMSG,
|
||||
ipcMSGRestartAsAdminMSGCallBackFunc: SendRestartAdminIPCMessage,
|
||||
ipcMSGCheckForUpdatesCallBackFunc: SendCheckForUpdatesIPCMessage,
|
||||
configFileSubfolder: string.Empty);
|
||||
|
||||
// Verifiy that the old settings persisted
|
||||
Assert.AreEqual(originalGeneralSettings.AutoDownloadUpdates, viewModel.AutoDownloadUpdates);
|
||||
Assert.AreEqual(originalGeneralSettings.Packaged, viewModel.Packaged);
|
||||
Assert.AreEqual(originalGeneralSettings.PowertoysVersion, viewModel.PowerToysVersion);
|
||||
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<T>)
|
||||
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsElevatedShouldUpdateRunasAdminStatusAttrsWhenSuccessful()
|
||||
|
||||
Reference in New Issue
Block a user