QueryHelperTest.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 Microsoft.CmdPal.Ext.Registry.Helpers;
 6  using Microsoft.VisualStudio.TestTools.UnitTesting;
 7  
 8  namespace Microsoft.CmdPal.Ext.Registry.UnitTests;
 9  
10  [TestClass]
11  public class QueryHelperTest
12  {
13      [TestMethod]
14      [DataRow(@"HKLM", false, @"HKLM", "")]
15      [DataRow(@"HKLM\", false, @"HKLM\", "")]
16      [DataRow(@"HKLM\\", true, @"HKLM", "")]
17      [DataRow(@"HKLM\\Test", true, @"HKLM", "Test")]
18      [DataRow(@"HKLM\Test\\TestTest", true, @"HKLM\Test", "TestTest")]
19      [DataRow(@"HKLM\Test\\\TestTest", true, @"HKLM\Test", @"\TestTest")]
20      [DataRow("HKLM/\"Software\"/", false, @"HKLM\Software\", "")]
21      [DataRow("HKLM/\"Software\"//test", true, @"HKLM\Software", "test")]
22      [DataRow("HKLM/\"Software\"//test/123", true, @"HKLM\Software", "test/123")]
23      [DataRow("HKLM/\"Software\"//test\\123", true, @"HKLM\Software", @"test\123")]
24      [DataRow("HKLM/\"Software\"/test", false, @"HKLM\Software\test", "")]
25      [DataRow("HKLM\\Software\\\"test\"", false, @"HKLM\Software\test", "")]
26      [DataRow("HKLM\\\"Software\"\\\"test\"", false, @"HKLM\Software\test", "")]
27      [DataRow("HKLM\\\"Software\"\\\"test/software\"", false, @"HKLM\Software\test/software", "")]
28      [DataRow("HKLM\\\"Software\"/\"test\"\\hello", false, @"HKLM\Software\test\hello", "")]
29      [DataRow("HKLM\\\"Software\"\\\"test\"\\hello\\\\\"some/value\"", true, @"HKLM\Software\test\hello", "some/value")]
30      [DataRow("HKLM\\\"Software\"\\\"test\"/hello\\\\\"some/value\"", true, @"HKLM\Software\test\hello", "some/value")]
31      [DataRow("HKLM\\\"Software\"\\\"test\"\\hello\\\\some\\value", true, @"HKLM\Software\test\hello", @"some\value")]
32      public void GetQueryPartsTest(string query, bool expectedHasValueName, string expectedQueryKey, string expectedQueryValueName)
33      {
34          var hasValueName = QueryHelper.GetQueryParts(query, out var queryKey, out var queryValueName);
35  
36          Assert.AreEqual(expectedHasValueName, hasValueName);
37          Assert.AreEqual(expectedQueryKey, queryKey);
38          Assert.AreEqual(expectedQueryValueName, queryValueName);
39      }
40  
41      [TestMethod]
42      [DataRow(@"HKCR\*\OpenWithList", @"HKEY_CLASSES_ROOT\*\OpenWithList")]
43      [DataRow(@"HKCU\Control Panel\Accessibility", @"HKEY_CURRENT_USER\Control Panel\Accessibility")]
44      [DataRow(@"HKLM\HARDWARE\UEFI", @"HKEY_LOCAL_MACHINE\HARDWARE\UEFI")]
45      [DataRow(@"HKU\.DEFAULT\Environment", @"HKEY_USERS\.DEFAULT\Environment")]
46      [DataRow(@"HKCC\System\CurrentControlSet\Control", @"HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control")]
47      [DataRow(@"HKPD\???", @"HKEY_PERFORMANCE_DATA\???")]
48      public void GetShortBaseKeyTest(string registryKeyShort, string registryKeyFull)
49      {
50          Assert.AreEqual(registryKeyShort, QueryHelper.GetKeyWithShortBaseKey(registryKeyFull));
51      }
52  }