mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Migrate blow plugin's from UT to cmdpal: 1. TimeDate 2. WindowWalker 3. System 4. Registry This PR is mostly helped by Copilot. Please feel free to change cases in the future. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #40461 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng <yuleng@microsoft.com>
76 lines
3.0 KiB
C#
76 lines
3.0 KiB
C#
// 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.Collections;
|
|
using System.Linq;
|
|
|
|
using Microsoft.CmdPal.Ext.Registry.Helpers;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace Microsoft.CmdPal.Ext.Registry.UnitTests;
|
|
|
|
[TestClass]
|
|
public class RegistryHelperTest
|
|
{
|
|
[TestMethod]
|
|
[DataRow(@"HKCC\System\CurrentControlSet\Control", "HKEY_CURRENT_CONFIG")]
|
|
[DataRow(@"HKCR\*\OpenWithList", "HKEY_CLASSES_ROOT")]
|
|
[DataRow(@"HKCU\Control Panel\Accessibility", "HKEY_CURRENT_USER")]
|
|
[DataRow(@"HKLM\HARDWARE\UEFI", "HKEY_LOCAL_MACHINE")]
|
|
[DataRow(@"HKPD\???", "HKEY_PERFORMANCE_DATA")]
|
|
[DataRow(@"HKU\.DEFAULT\Environment", "HKEY_USERS")]
|
|
public void GetRegistryBaseKeyTestOnlyOneBaseKey(string query, string expectedBaseKey)
|
|
{
|
|
var (baseKeyList, _) = RegistryHelper.GetRegistryBaseKey(query);
|
|
Assert.IsNotNull(baseKeyList);
|
|
Assert.IsTrue(baseKeyList.Count() == 1);
|
|
Assert.AreEqual(expectedBaseKey, baseKeyList.First().Name);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetRegistryBaseKeyTestMoreThanOneBaseKey()
|
|
{
|
|
var (baseKeyList, _) = RegistryHelper.GetRegistryBaseKey("HKC\\Control Panel\\Accessibility"); /* #no-spell-check-line */
|
|
|
|
Assert.IsNotNull(baseKeyList);
|
|
Assert.IsTrue(baseKeyList.Count() > 1);
|
|
|
|
var list = baseKeyList.Select(found => found.Name);
|
|
Assert.IsTrue(list.Contains("HKEY_CLASSES_ROOT"));
|
|
Assert.IsTrue(list.Contains("HKEY_CURRENT_CONFIG"));
|
|
Assert.IsTrue(list.Contains("HKEY_CURRENT_USER"));
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(@"HKCR\*\OpenWithList", @"*\OpenWithList")]
|
|
[DataRow(@"HKCU\Control Panel\Accessibility", @"Control Panel\Accessibility")]
|
|
[DataRow(@"HKLM\HARDWARE\UEFI", @"HARDWARE\UEFI")]
|
|
[DataRow(@"HKU\.DEFAULT\Environment", @".DEFAULT\Environment")]
|
|
[DataRow(@"HKCC\System\CurrentControlSet\Control", @"System\CurrentControlSet\Control")]
|
|
[DataRow(@"HKPD\???", @"???")]
|
|
public void GetRegistryBaseKeyTestSubKey(string query, string expectedSubKey)
|
|
{
|
|
var (_, subKey) = RegistryHelper.GetRegistryBaseKey(query);
|
|
Assert.AreEqual(expectedSubKey, subKey);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetAllBaseKeysTest()
|
|
{
|
|
var list = RegistryHelper.GetAllBaseKeys();
|
|
|
|
CollectionAssert.AllItemsAreNotNull((ICollection)list);
|
|
CollectionAssert.AllItemsAreUnique((ICollection)list);
|
|
|
|
var keys = list.Select(found => found.Key).ToList() as ICollection;
|
|
|
|
CollectionAssert.Contains(keys, Win32.Registry.ClassesRoot);
|
|
CollectionAssert.Contains(keys, Win32.Registry.CurrentConfig);
|
|
CollectionAssert.Contains(keys, Win32.Registry.CurrentUser);
|
|
CollectionAssert.Contains(keys, Win32.Registry.LocalMachine);
|
|
CollectionAssert.Contains(keys, Win32.Registry.PerformanceData);
|
|
CollectionAssert.Contains(keys, Win32.Registry.Users);
|
|
}
|
|
}
|