/ src / settings-ui / Settings.UI.UnitTests / Cmd / SetSettingCommandTests.cs
SetSettingCommandTests.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System;
 6  using System.IO.Abstractions.TestingHelpers;
 7  
 8  using Microsoft.PowerToys.Settings.UI.Library;
 9  using Microsoft.VisualStudio.TestTools.UnitTesting;
10  
11  using static Microsoft.PowerToys.Settings.UI.Library.SetSettingCommandLineCommand;
12  
13  namespace Settings.UI.UnitTests.Cmd;
14  
15  [TestClass]
16  public class SetSettingCommandTests
17  {
18      private SettingsUtils settingsUtils;
19  
20      [TestInitialize]
21      public void Setup()
22      {
23          settingsUtils = new SettingsUtils(new MockFileSystem());
24      }
25  
26      private void SetSetting(Type moduleSettingsType, string settingName, string newValueStr)
27      {
28          var settings = CommandLineUtils.GetSettingsConfigFor(moduleSettingsType, settingsUtils);
29          var defaultValue = CommandLineUtils.GetPropertyValue(settingName, settings);
30          var qualifiedName = moduleSettingsType.Name.Replace("Settings", string.Empty) + "." + settingName;
31          var type = CommandLineUtils.GetSettingPropertyInfo(settingName, settings).PropertyType;
32          var newValue = ICmdLineRepresentable.ParseFor(type, newValueStr);
33  
34          Execute(qualifiedName, newValueStr, settingsUtils);
35  
36          Assert.AreNotEqual(defaultValue, newValue);
37          Assert.AreEqual(newValue, CommandLineUtils.GetPropertyValue(settingName, settings));
38      }
39  
40      // Each setting has a different type.
41      [TestMethod]
42      [DataRow(typeof(PowerRenameSettings), nameof(PowerRenameProperties.MaxMRUSize), "123")]
43      [DataRow(typeof(FancyZonesSettings), nameof(FZConfigProperties.FancyzonesBorderColor), "#00FF00")]
44      [DataRow(typeof(MeasureToolSettings), nameof(MeasureToolProperties.ActivationShortcut), "Ctrl+Alt+Delete")]
45      [DataRow(typeof(AlwaysOnTopSettings), nameof(AlwaysOnTopProperties.SoundEnabled), "False")]
46      [DataRow(typeof(PowerAccentSettings), nameof(PowerAccentProperties.ShowUnicodeDescription), "true")]
47      [DataRow(typeof(AwakeSettings), nameof(AwakeProperties.Mode), "EXPIRABLE")]
48      [DataRow(typeof(AwakeSettings), nameof(AwakeProperties.ExpirationDateTime), "March 31, 2020 15:00 +00:00")]
49      [DataRow(typeof(PowerLauncherSettings), nameof(PowerLauncherProperties.MaximumNumberOfResults), "322")]
50  
51      [DataRow(typeof(ColorPickerSettings), nameof(ColorPickerProperties.CopiedColorRepresentation), "RGB")]
52      public void SetModuleSetting(Type moduleSettingsType, string settingName, string newValueStr)
53      {
54          SetSetting(moduleSettingsType, settingName, newValueStr);
55      }
56  
57      [DataRow(typeof(GeneralSettings), "Enabled.MouseWithoutBorders", "true")]
58      [DataRow(typeof(GeneralSettings), nameof(GeneralSettings.AutoDownloadUpdates), "true")]
59      [TestMethod]
60      public void SetGeneralSetting(Type moduleSettingsType, string settingName, string newValueStr)
61      {
62          SetSetting(moduleSettingsType, settingName, newValueStr);
63      }
64  }