Compare commits

..

30 Commits

Author SHA1 Message Date
Leilei Zhang
1074f9f812 test 2025-07-18 12:42:27 +08:00
Leilei Zhang
f478533db9 update reg 2025-07-18 11:40:39 +08:00
Leilei Zhang
1e0b6d5e38 fix merge error 2025-07-18 11:22:39 +08:00
Leilei Zhang
3bee31bfd7 Merge branch 'main' of https://github.com/microsoft/PowerToys into leilzh/peekuitests 2025-07-18 10:33:01 +08:00
Leilei Zhang
a89d8476f8 use compare 2025-07-18 09:53:42 +08:00
Leilei Zhang
19ada53ce3 get image for testing 2025-07-17 15:58:16 +08:00
Leilei Zhang
0654edb18a update default program tests 2025-07-17 15:49:56 +08:00
Leilei Zhang
7d02867b60 add enter 2025-07-17 13:41:16 +08:00
Leilei Zhang
b05cf8bf9f update common function 2025-07-17 12:23:03 +08:00
Leilei Zhang
522f12a0b2 clean windows 2025-07-17 11:21:30 +08:00
Leilei Zhang
d12bbf0cbf close settings page before testing 2025-07-17 10:18:37 +08:00
Leilei Zhang
f067a925f6 add more tests 2025-07-16 20:41:35 +08:00
Leilei Zhang
37c690b216 update screenshot name 2025-07-16 17:49:08 +08:00
Leilei Zhang
f6ff5064a3 use all 2025-07-16 17:05:20 +08:00
Leilei Zhang
78884bb587 use wrong flag 2025-07-16 15:52:16 +08:00
Leilei Zhang
d2b81450e3 add retry 2025-07-16 14:59:18 +08:00
Leilei Zhang
425883508f update image pipeline 2025-07-16 14:09:25 +08:00
Leilei Zhang
41ff1f8cf7 add more image and add long time 2025-07-16 13:57:53 +08:00
Leilei Zhang
2ee40a99d5 exit command paletter 2025-07-16 12:52:30 +08:00
Leilei Zhang
943d79bb83 clean code 2025-07-16 10:58:43 +08:00
Leilei Zhang
e42a1b8753 add test run title 2025-07-16 10:22:53 +08:00
Leilei Zhang
ed424faea5 add png 2025-07-16 10:11:56 +08:00
Leilei Zhang
85db62e946 add more time 2025-07-16 00:09:18 +08:00
Leilei Zhang
96de5d7a87 add png 2025-07-15 23:00:54 +08:00
Leilei Zhang
8a1aff68c1 add pin and unpin 2025-07-15 21:17:22 +08:00
Leilei Zhang
f19c2e1a78 create image 2025-07-15 09:34:33 +08:00
Leilei Zhang
1dab45c87c check file 2025-07-14 21:44:43 +08:00
Leilei Zhang
0040112855 add delay 2025-07-14 19:48:00 +08:00
Leilei Zhang
6205e25eb5 add delay 2025-07-14 18:54:44 +08:00
Leilei Zhang
dbe3ac6077 add peek ui tests 2025-07-14 17:50:41 +08:00
87 changed files with 174 additions and 3205 deletions

View File

@@ -190,18 +190,11 @@ jobs:
displayName: Verify ARM64 configurations
- ${{ if eq(parameters.enablePackageCaching, true) }}:
- pwsh: |-
$dotnetVersion = dotnet --version
Write-Host "Current .NET SDK Version: $dotnetVersion"
Write-Host "##vso[task.setvariable variable=DotNetSdkVersion]$dotnetVersion"
displayName: Get .NET SDK Version for Cache Key
- task: Cache@2
displayName: 'Cache nuget packages (PackageReference)'
inputs:
key: '"PackageReference" | "$(Agent.OS)" | Directory.Packages.props | "$(DotNetSdkVersion)"'
key: '"PackageReference" | "$(Agent.OS)" | Directory.Packages.props'
restoreKeys: |
"PackageReference" | "$(Agent.OS)" | Directory.Packages.props
"PackageReference" | "$(Agent.OS)"
"PackageReference"
path: $(NUGET_PACKAGES)

View File

@@ -113,6 +113,23 @@ jobs:
& '$(build.sourcesdirectory)\.pipelines\InstallWinAppDriver.ps1'
displayName: Download and install WinAppDriver
- pwsh: |-
# Set Windows Error Reporting to not show UI to prevent test hangs
reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v DontShowUI /t REG_DWORD /d 1 /f
Write-Host "Windows Error Reporting DontShowUI set to prevent dialog popups during UI tests"
displayName: Configure Windows Error Reporting for UI Tests
- pwsh: |-
# Verify the setting was actually applied
$result = reg query "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v DontShowUI 2>$null
if ($result -match "DontShowUI.*REG_DWORD.*0x1") {
Write-Host "✓ Verification successful: DontShowUI is set to 1"
} else {
Write-Host "✗ Verification failed: DontShowUI setting not found or incorrect"
Write-Host "Registry query result: $result"
}
displayName: Verify Windows Error Reporting Configuration
- ${{ if eq(parameters.useLatestOfficialBuild, true) }}:
- task: DownloadPipelineArtifact@2
inputs:

View File

@@ -60,6 +60,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRenameLib", "src\modules\powerrename\lib\PowerRenameLib.vcxproj", "{51920F1F-C28C-4ADF-8660-4238766796C2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRenameTest", "src\modules\powerrename\testapp\PowerRenameTest.vcxproj", "{A3935CF4-46C5-4A88-84D3-6B12E16E6BA2}"
ProjectSection(ProjectDependencies) = postProject
{51920F1F-C28C-4ADF-8660-4238766796C2} = {51920F1F-C28C-4ADF-8660-4238766796C2}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRenameUnitTests", "src\modules\powerrename\unittests\PowerRenameLibUnitTests.vcxproj", "{2151F984-E006-4A9F-92EF-C6DDE3DC8413}"
ProjectSection(ProjectDependencies) = postProject
@@ -739,18 +742,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{02EA681E-C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Core.ViewModels", "src\modules\cmdpal\Microsoft.CmdPal.Core.ViewModels\Microsoft.CmdPal.Core.ViewModels.csproj", "{24133F7F-C1D1-DE04-EFA8-F5D5467FE027}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.UITests", "src\modules\cmdpal\Microsoft.CmdPal.UITests\Microsoft.CmdPal.UITests.csproj", "{840455DF-5634-51BB-D937-9D7D32F0B0C2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{15EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.Registry.UnitTests", "src\modules\cmdpal\Tests\Microsoft.CmdPal.Ext.Registry.UnitTests\Microsoft.CmdPal.Ext.Registry.UnitTests.csproj", "{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.System.UnitTests", "src\modules\cmdpal\Tests\Microsoft.CmdPal.Ext.System.UnitTests\Microsoft.CmdPal.Ext.System.UnitTests.csproj", "{790247CB-2B95-E139-E933-09D10137EEAF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.TimeDate.UnitTests", "src\modules\cmdpal\Tests\Microsoft.CmdPal.Ext.TimeDate.UnitTests\Microsoft.CmdPal.Ext.TimeDate.UnitTests.csproj", "{18525614-CDB2-8BBE-B1B4-3812CD990C22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.WindowWalker.UnitTests", "src\modules\cmdpal\Tests\Microsoft.CmdPal.Ext.WindowWalker.UnitTests\Microsoft.CmdPal.Ext.WindowWalker.UnitTests.csproj", "{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
@@ -2757,46 +2748,6 @@ Global
{BCDC7246-F4F8-4EED-8DE6-037AA2E7C6D1}.Release|ARM64.Build.0 = Release|ARM64
{BCDC7246-F4F8-4EED-8DE6-037AA2E7C6D1}.Release|x64.ActiveCfg = Release|x64
{BCDC7246-F4F8-4EED-8DE6-037AA2E7C6D1}.Release|x64.Build.0 = Release|x64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|ARM64.ActiveCfg = Debug|ARM64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|ARM64.Build.0 = Debug|ARM64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|x64.ActiveCfg = Debug|x64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|x64.Build.0 = Debug|x64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|ARM64.ActiveCfg = Release|ARM64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|ARM64.Build.0 = Release|ARM64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|x64.ActiveCfg = Release|x64
{840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|x64.Build.0 = Release|x64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Debug|ARM64.ActiveCfg = Debug|ARM64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Debug|ARM64.Build.0 = Debug|ARM64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Debug|x64.ActiveCfg = Debug|x64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Debug|x64.Build.0 = Debug|x64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Release|ARM64.ActiveCfg = Release|ARM64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Release|ARM64.Build.0 = Release|ARM64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Release|x64.ActiveCfg = Release|x64
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7}.Release|x64.Build.0 = Release|x64
{790247CB-2B95-E139-E933-09D10137EEAF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{790247CB-2B95-E139-E933-09D10137EEAF}.Debug|ARM64.Build.0 = Debug|ARM64
{790247CB-2B95-E139-E933-09D10137EEAF}.Debug|x64.ActiveCfg = Debug|x64
{790247CB-2B95-E139-E933-09D10137EEAF}.Debug|x64.Build.0 = Debug|x64
{790247CB-2B95-E139-E933-09D10137EEAF}.Release|ARM64.ActiveCfg = Release|ARM64
{790247CB-2B95-E139-E933-09D10137EEAF}.Release|ARM64.Build.0 = Release|ARM64
{790247CB-2B95-E139-E933-09D10137EEAF}.Release|x64.ActiveCfg = Release|x64
{790247CB-2B95-E139-E933-09D10137EEAF}.Release|x64.Build.0 = Release|x64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Debug|ARM64.ActiveCfg = Debug|ARM64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Debug|ARM64.Build.0 = Debug|ARM64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Debug|x64.ActiveCfg = Debug|x64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Debug|x64.Build.0 = Debug|x64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Release|ARM64.ActiveCfg = Release|ARM64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Release|ARM64.Build.0 = Release|ARM64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Release|x64.ActiveCfg = Release|x64
{18525614-CDB2-8BBE-B1B4-3812CD990C22}.Release|x64.Build.0 = Release|x64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Debug|ARM64.ActiveCfg = Debug|ARM64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Debug|ARM64.Build.0 = Debug|ARM64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Debug|x64.ActiveCfg = Debug|x64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Debug|x64.Build.0 = Debug|x64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Release|ARM64.ActiveCfg = Release|ARM64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Release|ARM64.Build.0 = Release|ARM64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Release|x64.ActiveCfg = Release|x64
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -3085,12 +3036,6 @@ Global
{24133F7F-C1D1-DE04-EFA8-F5D5467FE027} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{9D3F3793-EFE3-4525-8782-238015DABA62} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
{BCDC7246-F4F8-4EED-8DE6-037AA2E7C6D1} = {17B4FA70-001E-4D33-BBBB-0D142DBC2E20}
{840455DF-5634-51BB-D937-9D7D32F0B0C2} = {7520A2FE-00A2-49B8-83ED-DB216E874C04}
{15EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {3846508C-77EB-4034-A702-F8BB263C4F79}
{2CF0567E-1E00-4E3F-1561-BF85F5CE5FE7} = {15EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{790247CB-2B95-E139-E933-09D10137EEAF} = {15EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{18525614-CDB2-8BBE-B1B4-3812CD990C22} = {15EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{B0FE6EF3-5FB3-B8DC-7507-008BBB392FD8} = {15EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}

View File

@@ -32,7 +32,6 @@ namespace Microsoft.PowerToys.UITest
Runner,
Workspaces,
PowerRename,
CommandPalette,
}
/// <summary>
@@ -105,7 +104,6 @@ namespace Microsoft.PowerToys.UITest
[PowerToysModule.Runner] = new ModuleInfo("PowerToys.exe", "PowerToys"),
[PowerToysModule.Workspaces] = new ModuleInfo("PowerToys.WorkspacesEditor.exe", "Workspaces Editor"),
[PowerToysModule.PowerRename] = new ModuleInfo("PowerToys.PowerRename.exe", "PowerRename", "WinUI3Apps"),
[PowerToysModule.CommandPalette] = new ModuleInfo("Microsoft.CmdPal.UI.exe", "PowerToys Command Palette", "WinUI3Apps\\CmdPal"),
};
}

View File

@@ -176,9 +176,6 @@ namespace Microsoft.PowerToys.UITest
runner = Process.Start(runnerProcessInfo);
Thread.Sleep(5000);
// Exit CmdPal UI before launching new process if use installer for test
ExitExeByName("Microsoft.CmdPal.UI");
if (root != null)
{
const int maxRetries = 5;
@@ -207,6 +204,9 @@ namespace Microsoft.PowerToys.UITest
}
}
}
// Exit CmdPal UI before launching new process if use installer for test
ExitExeByName("Microsoft.CmdPal.UI");
}
/// <summary>

View File

@@ -411,7 +411,7 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<value>Back</value>
</data>
<data name="BackButton.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Back (Alt + Left arrow)</value>
<value>Back</value>
</data>
<data name="MoreCommandsButton.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>More</value>

View File

@@ -1,130 +0,0 @@
// 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.Threading.Tasks;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.UITests;
[TestClass]
public class BasicTests : CommandPaletteTestBase
{
public BasicTests()
{
}
[TestMethod]
public void BasicFileSearchTest()
{
SetSearchBox("files");
var searchFileItem = this.Find<NavigationViewItem>("Search files");
Assert.AreEqual(searchFileItem.Name, "Search files");
searchFileItem.DoubleClick();
SetFilesExtensionSearchBox("AppData");
Assert.IsNotNull(this.Find<NavigationViewItem>("AppData"));
}
[TestMethod]
public void BasicCalculatorTest()
{
SetSearchBox("calculator");
var searchFileItem = this.Find<NavigationViewItem>("Calculator");
Assert.AreEqual(searchFileItem.Name, "Calculator");
searchFileItem.DoubleClick();
SetCalculatorExtensionSearchBox("1+2");
Assert.IsNotNull(this.Find<NavigationViewItem>("3"));
}
[TestMethod]
public void BasicTimeAndDateTest()
{
SetSearchBox("time and date");
var searchFileItem = this.Find<NavigationViewItem>("Time and Date");
Assert.AreEqual(searchFileItem.Name, "Time and Date");
searchFileItem.DoubleClick();
SetTimeAndDaterExtensionSearchBox("year");
Assert.IsNotNull(this.Find<NavigationViewItem>("2025"));
}
[TestMethod]
public void BasicWindowsTerminalTest()
{
SetSearchBox("Windows Terminal");
var searchFileItem = this.Find<NavigationViewItem>("Open Windows Terminal Profiles");
Assert.AreEqual(searchFileItem.Name, "Open Windows Terminal Profiles");
searchFileItem.DoubleClick();
SetSearchBox("PowerShell");
Assert.IsNotNull(this.Find<NavigationViewItem>("PowerShell"));
}
[TestMethod]
public void BasicWindowsSettingsTest()
{
SetSearchBox("Windows Settings");
var searchFileItem = this.Find<NavigationViewItem>("Windows Settings");
Assert.AreEqual(searchFileItem.Name, "Windows Settings");
searchFileItem.DoubleClick();
SetSearchBox("power");
Assert.IsNotNull(this.Find<NavigationViewItem>("Power and sleep"));
}
[TestMethod]
public void BasicRegistryTest()
{
SetSearchBox("Registry");
var searchFileItem = this.Find<NavigationViewItem>("Registry");
Assert.AreEqual(searchFileItem.Name, "Registry");
searchFileItem.DoubleClick();
SetSearchBox("HKEY_LOCAL_MACHINE");
Assert.IsNotNull(this.Find<NavigationViewItem>("HKEY_LOCAL_MACHINE\\SECURITY"));
}
[TestMethod]
public void BasicWindowsServicesTest()
{
SetSearchBox("Windows Services");
var searchFileItem = this.Find<NavigationViewItem>("Windows Services");
Assert.AreEqual(searchFileItem.Name, "Windows Services");
searchFileItem.DoubleClick();
SetSearchBox("hyper-v");
Assert.IsNotNull(this.Find<NavigationViewItem>("Hyper-V Heartbeat Service"));
}
[TestMethod]
public void BasicWindowsSystemCommandsTest()
{
SetSearchBox("Windows System Commands");
var searchFileItem = this.Find<NavigationViewItem>("Windows System Commands");
Assert.AreEqual(searchFileItem.Name, "Windows System Commands");
searchFileItem.DoubleClick();
SetSearchBox("Sleep");
Assert.IsNotNull(this.Find<NavigationViewItem>("Sleep"));
}
}

View File

@@ -1,48 +0,0 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.UITests;
public class CommandPaletteTestBase : UITestBase
{
public CommandPaletteTestBase()
: base(PowerToysModule.CommandPalette)
{
}
protected void SetSearchBox(string text)
{
Assert.AreEqual(this.Find<TextBox>("Type here to search...").SetText(text, true).Text, text);
}
protected void SetFilesExtensionSearchBox(string text)
{
Assert.AreEqual(this.Find<TextBox>("Search for files and folders...").SetText(text, true).Text, text);
}
protected void SetCalculatorExtensionSearchBox(string text)
{
Assert.AreEqual(this.Find<TextBox>("Type an equation...").SetText(text, true).Text, text);
}
protected void SetTimeAndDaterExtensionSearchBox(string text)
{
Assert.AreEqual(this.Find<TextBox>("Search values or type a custom time stamp...").SetText(text, true).Text, text);
}
protected void OpenContextMenu()
{
var contextMenuButton = this.Find<Button>("More");
Assert.IsNotNull(contextMenuButton, "Context menu button not found.");
contextMenuButton.Click();
}
}

View File

@@ -1,226 +0,0 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.UITests;
[TestClass]
public class IndexerTests : CommandPaletteTestBase
{
private const string TestFileContent = "This is Indexer UI test sample";
private const string TestFileName = "indexer_test_item.txt";
private const string TestFolderName = "Downloads";
public IndexerTests()
: base()
{
// create a empty file in Downloads folder
// to ensure that the indexer has something to search for
var downloadsPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads";
var emptyFilePath = System.IO.Path.Combine(downloadsPath, TestFileName);
if (!System.IO.File.Exists(emptyFilePath))
{
using (var fileStream = System.IO.File.Create(emptyFilePath))
{
var content = TestFileContent;
var contentBytes = Encoding.UTF8.GetBytes(content);
fileStream.Write(contentBytes, 0, contentBytes.Length);
}
}
}
public void EnterIndexerExtension()
{
SetSearchBox("files");
var searchFileItem = this.Find<NavigationViewItem>("Search files");
Assert.AreEqual(searchFileItem.Name, "Search files");
searchFileItem.DoubleClick();
}
[TestMethod]
public void BasicIndexerSearchTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox("Downloads");
Assert.IsNotNull(this.Find<NavigationViewItem>("Downloads"));
}
[TestMethod]
public void IndexerOpenFileTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFileName);
var searchItem = this.Find<NavigationViewItem>(TestFileName);
Assert.IsNotNull(searchItem);
searchItem.Click();
var openButton = this.Find<Button>("Open");
Assert.IsNotNull(openButton);
openButton.Click();
var notepadWindow = this.Find<Window>($"{TestFileName} - Notepad", global: true);
Assert.IsNotNull(notepadWindow);
}
[TestMethod]
public void IndexerDoubleClickOpenFileTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFileName);
var searchItem = this.Find<NavigationViewItem>(TestFileName);
Assert.IsNotNull(searchItem);
searchItem.DoubleClick();
var notepadWindow = this.Find<Window>($"{TestFileName} - Notepad", global: true);
Assert.IsNotNull(notepadWindow);
}
[TestMethod]
public void IndexerOpenFolderTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFolderName);
var searchItem = this.Find<NavigationViewItem>(TestFolderName);
Assert.IsNotNull(searchItem);
searchItem.Click();
var openButton = this.Find<Button>("Open");
Assert.IsNotNull(openButton);
openButton.Click();
var notepadWindow = this.Find<Window>($"{TestFolderName} - File Explorer", global: true);
Assert.IsNotNull(notepadWindow);
}
[TestMethod]
public void IndexerDoubleClickOpenFolderTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFolderName);
var searchItem = this.Find<NavigationViewItem>(TestFolderName);
Assert.IsNotNull(searchItem);
searchItem.DoubleClick();
var fileExplorer = this.Find<Window>($"{TestFolderName} - File Explorer", global: true);
Assert.IsNotNull(fileExplorer);
}
[TestMethod]
public void IndexerBrowseFolderTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFolderName);
var searchItem = this.Find<NavigationViewItem>(TestFolderName);
Assert.IsNotNull(searchItem);
searchItem.Click();
var openButton = this.Find<Button>("Browse");
Assert.IsNotNull(openButton);
openButton.Click();
var testItem = this.Find<NavigationViewItem>(TestFileName);
Assert.IsNotNull(testItem);
}
[STATestMethod]
[TestMethod]
public void IndexerCopyPathTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFileName);
var searchItem = this.Find<NavigationViewItem>(TestFileName);
Assert.IsNotNull(searchItem);
searchItem.Click();
OpenContextMenu();
var copyPathButton = this.Find<NavigationViewItem>("Copy path");
Assert.IsNotNull(copyPathButton);
copyPathButton.Click();
var clipboardContent = System.Windows.Forms.Clipboard.GetText();
Assert.IsTrue(clipboardContent.Contains(TestFileName), $"Clipboard content does not contain the expected file name. clipboard: {clipboardContent}");
}
[TestMethod]
public void IndexerShowInFolderTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFileName);
var searchItem = this.Find<NavigationViewItem>(TestFileName);
Assert.IsNotNull(searchItem);
searchItem.Click();
OpenContextMenu();
var showInFolderButton = this.Find<NavigationViewItem>("Show in folder");
Assert.IsNotNull(showInFolderButton);
showInFolderButton.Click();
var fileExplorer = this.Find<Window>($"{TestFolderName} - File Explorer", global: true, timeoutMS: 20000);
Assert.IsNotNull(fileExplorer);
}
[TestMethod]
public void IndexerOpenPathInConsoleTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFileName);
var searchItem = this.Find<NavigationViewItem>(TestFileName);
Assert.IsNotNull(searchItem);
searchItem.Click();
OpenContextMenu();
var copyPathButton = this.Find<NavigationViewItem>("Open path in console");
Assert.IsNotNull(copyPathButton);
copyPathButton.Click();
var textItem = this.Find<Window>("C:\\Windows\\system32\\cmd.exe", global: true);
Assert.IsNotNull(textItem, "The console did not open with the expected path.");
}
[TestMethod]
public void IndexerOpenPropertiesTest()
{
EnterIndexerExtension();
SetFilesExtensionSearchBox(TestFileName);
var searchItem = this.Find<NavigationViewItem>(TestFileName);
Assert.IsNotNull(searchItem);
searchItem.Click();
OpenContextMenu();
var copyPathButton = this.Find<NavigationViewItem>("Properties");
Assert.IsNotNull(copyPathButton);
copyPathButton.Click();
var propertiesWindow = this.Find<Window>($"{TestFileName} Properties", global: true);
Assert.IsNotNull(propertiesWindow, "The properties window did not open for the selected file.");
}
}

View File

@@ -1,26 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />
<PropertyGroup>
<RootNamespace>Microsoft.CmdPal.UITests</RootNamespace>
<AssemblyName>Microsoft.CmdPal.UITests</AssemblyName>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<!-- This is a UI test, so don't run as part of MSBuild -->
<RunVSTest>false</RunVSTest>
</PropertyGroup>
<PropertyGroup>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\tests\Microsoft.CmdPal.UITests\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" />
<PackageReference Include="System.Net.Http" />
<PackageReference Include="System.Private.Uri" />
<PackageReference Include="System.Text.RegularExpressions" />
<ProjectReference Include="..\..\..\common\UITestAutomation\UITestAutomation.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,18 +0,0 @@
// 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.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.Registry.UnitTests;
[TestClass]
public class BasicStructureTest
{
[TestMethod]
public void CanCreateTestClass()
{
// This is a basic test to verify the test project structure is correct
Assert.IsTrue(true);
}
}

View File

@@ -1,26 +0,0 @@
// 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.CmdPal.Ext.Registry.Constants;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.Registry.UnitTests;
[TestClass]
public class KeyNameTest
{
[TestMethod]
[DataRow("HKEY", KeyName.FirstPart)]
[DataRow("HKEY_", KeyName.FirstPartUnderscore)]
[DataRow("HKCR", KeyName.ClassRootShort)]
[DataRow("HKCC", KeyName.CurrentConfigShort)]
[DataRow("HKCU", KeyName.CurrentUserShort)]
[DataRow("HKLM", KeyName.LocalMachineShort)]
[DataRow("HKPD", KeyName.PerformanceDataShort)]
[DataRow("HKU", KeyName.UsersShort)]
public void TestConstants(string shortName, string baseName)
{
Assert.AreEqual(shortName, baseName);
}
}

View File

@@ -1,22 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Look at Directory.Build.props in root for common stuff as well -->
<Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Microsoft.CmdPal.Ext.Registry.UnitTests</RootNamespace>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal\tests\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="MSTest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ext\Microsoft.CmdPal.Ext.Registry\Microsoft.CmdPal.Ext.Registry.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,52 +0,0 @@
// 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.CmdPal.Ext.Registry.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.Registry.UnitTests;
[TestClass]
public class QueryHelperTest
{
[TestMethod]
[DataRow(@"HKLM", false, @"HKLM", "")]
[DataRow(@"HKLM\", false, @"HKLM\", "")]
[DataRow(@"HKLM\\", true, @"HKLM", "")]
[DataRow(@"HKLM\\Test", true, @"HKLM", "Test")]
[DataRow(@"HKLM\Test\\TestTest", true, @"HKLM\Test", "TestTest")]
[DataRow(@"HKLM\Test\\\TestTest", true, @"HKLM\Test", @"\TestTest")]
[DataRow("HKLM/\"Software\"/", false, @"HKLM\Software\", "")]
[DataRow("HKLM/\"Software\"//test", true, @"HKLM\Software", "test")]
[DataRow("HKLM/\"Software\"//test/123", true, @"HKLM\Software", "test/123")]
[DataRow("HKLM/\"Software\"//test\\123", true, @"HKLM\Software", @"test\123")]
[DataRow("HKLM/\"Software\"/test", false, @"HKLM\Software\test", "")]
[DataRow("HKLM\\Software\\\"test\"", false, @"HKLM\Software\test", "")]
[DataRow("HKLM\\\"Software\"\\\"test\"", false, @"HKLM\Software\test", "")]
[DataRow("HKLM\\\"Software\"\\\"test/software\"", false, @"HKLM\Software\test/software", "")]
[DataRow("HKLM\\\"Software\"/\"test\"\\hello", false, @"HKLM\Software\test\hello", "")]
[DataRow("HKLM\\\"Software\"\\\"test\"\\hello\\\\\"some/value\"", true, @"HKLM\Software\test\hello", "some/value")]
[DataRow("HKLM\\\"Software\"\\\"test\"/hello\\\\\"some/value\"", true, @"HKLM\Software\test\hello", "some/value")]
[DataRow("HKLM\\\"Software\"\\\"test\"\\hello\\\\some\\value", true, @"HKLM\Software\test\hello", @"some\value")]
public void GetQueryPartsTest(string query, bool expectedHasValueName, string expectedQueryKey, string expectedQueryValueName)
{
var hasValueName = QueryHelper.GetQueryParts(query, out var queryKey, out var queryValueName);
Assert.AreEqual(expectedHasValueName, hasValueName);
Assert.AreEqual(expectedQueryKey, queryKey);
Assert.AreEqual(expectedQueryValueName, queryValueName);
}
[TestMethod]
[DataRow(@"HKCR\*\OpenWithList", @"HKEY_CLASSES_ROOT\*\OpenWithList")]
[DataRow(@"HKCU\Control Panel\Accessibility", @"HKEY_CURRENT_USER\Control Panel\Accessibility")]
[DataRow(@"HKLM\HARDWARE\UEFI", @"HKEY_LOCAL_MACHINE\HARDWARE\UEFI")]
[DataRow(@"HKU\.DEFAULT\Environment", @"HKEY_USERS\.DEFAULT\Environment")]
[DataRow(@"HKCC\System\CurrentControlSet\Control", @"HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control")]
[DataRow(@"HKPD\???", @"HKEY_PERFORMANCE_DATA\???")]
public void GetShortBaseKeyTest(string registryKeyShort, string registryKeyFull)
{
Assert.AreEqual(registryKeyShort, QueryHelper.GetKeyWithShortBaseKey(registryKeyFull));
}
}

View File

@@ -1,75 +0,0 @@
// 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);
}
}

View File

@@ -1,32 +0,0 @@
// 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.Collections.Generic;
using System.Linq;
using Microsoft.CmdPal.Ext.Registry.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.Registry.UnitTests;
[TestClass]
public class ResultHelperTest
{
[TestMethod]
[DataRow(@"HKEY_CLASSES_ROOT\*\OpenWithList", @"HKEY_CLASSES_ROOT\*\OpenWithList")]
[DataRow(@"HKEY_CURRENT_USER\Control Panel\Accessibility", @"HKEY_CURRENT_USER\Control Panel\Accessibility")]
[DataRow(@"HKEY_LOCAL_MACHINE\HARDWARE\UEFI", @"HKEY_LOCAL_MACHINE\HARDWARE\UEFI")]
[DataRow(@"HKEY_USERS\.DEFAULT\Environment", @"HKEY_USERS\.DEFAULT\Environment")]
[DataRow(@"HKCC\System\CurrentControlSet\Control", @"HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control")]
[DataRow(@"HKEY_PERFORMANCE_DATA\???", @"HKEY_PERFORMANCE_DATA\???")]
[DataRow(@"HKCR\*\shell\Open with VS Code\command", @"HKEY_CLASSES_ROOT\*\shell\Open with VS Code\command")]
[DataRow(@"...ndows\CurrentVersion\Explorer\StartupApproved", @"HKEY_CURRENT_USER\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved")]
[DataRow(@"...p\Upgrade\NetworkDriverBackup\Control\Network", @"HKEY_LOCAL_MACHINE\SYSTEM\Setup\Upgrade\NetworkDriverBackup\Control\Network")]
[DataRow(@"...anel\International\User Profile System Backup", @"HKEY_USERS\.DEFAULT\Control Panel\International\User Profile System Backup")]
[DataRow(@"...stem\CurrentControlSet\Control\Print\Printers", @"HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers")]
public void GetTruncatedTextTest_StandardCases(string registryKeyShort, string registryKeyFull)
{
Assert.AreEqual(registryKeyShort, ResultHelper.GetTruncatedText(registryKeyFull, 45));
}
}

View File

@@ -1,84 +0,0 @@
// 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 Microsoft.CmdPal.Ext.System.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.System.UnitTests;
[TestClass]
public class BasicTests
{
[TestMethod]
public void CommandsHelperTest()
{
// Setup & Act
var commands = Commands.GetSystemCommands(false, false, false, false);
// Assert
Assert.IsNotNull(commands);
Assert.IsTrue(commands.Count > 0);
}
[TestMethod]
public void IconsHelperTest()
{
// Assert
Assert.IsNotNull(Icons.FirmwareSettingsIcon);
Assert.IsNotNull(Icons.LockIcon);
Assert.IsNotNull(Icons.LogoffIcon);
Assert.IsNotNull(Icons.NetworkAdapterIcon);
Assert.IsNotNull(Icons.RecycleBinIcon);
Assert.IsNotNull(Icons.RestartIcon);
Assert.IsNotNull(Icons.RestartShellIcon);
Assert.IsNotNull(Icons.ShutdownIcon);
Assert.IsNotNull(Icons.SleepIcon);
}
[TestMethod]
public void Win32HelpersTest()
{
// Setup & Act
// These methods should not throw exceptions
var firmwareType = Win32Helpers.GetSystemFirmwareType();
// Assert
// Just testing that they don't throw exceptions
Assert.IsTrue(Enum.IsDefined(typeof(FirmwareType), firmwareType));
}
[TestMethod]
public void NetworkConnectionPropertiesTest()
{
// Test that network connection properties can be accessed without throwing exceptions
try
{
var networkPropertiesList = NetworkConnectionProperties.GetList();
// If we have network connections, test accessing their properties
if (networkPropertiesList.Count > 0)
{
var networkProperties = networkPropertiesList[0];
// Access properties (these used to be methods)
var ipv4 = networkProperties.IPv4;
var ipv6 = networkProperties.IPv6Primary;
var macAddress = networkProperties.PhysicalAddress;
// Test passes if no exceptions are thrown
Assert.IsTrue(true);
}
else
{
// If no network connections, test still passes
Assert.IsTrue(true);
}
}
catch
{
Assert.Fail("Network properties should not throw exceptions");
}
}
}

View File

@@ -1,72 +0,0 @@
// 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.Linq;
using System.Reflection;
using Microsoft.CmdPal.Ext.System.Helpers;
using Microsoft.CmdPal.Ext.System.Pages;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.System.UnitTests;
[TestClass]
public class ImageTests
{
[DataTestMethod]
[DataRow("shutdown", "ShutdownIcon")]
[DataRow("restart", "RestartIcon")]
[DataRow("sign out", "LogoffIcon")]
[DataRow("lock", "LockIcon")]
[DataRow("sleep", "SleepIcon")]
[DataRow("hibernate", "SleepIcon")]
[DataRow("recycle bin", "RecycleBinIcon")]
[DataRow("uefi firmware settings", "FirmwareSettingsIcon")]
[DataRow("IPv4 addr", "NetworkAdapterIcon")]
[DataRow("IPV6 addr", "NetworkAdapterIcon")]
[DataRow("MAC addr", "NetworkAdapterIcon")]
public void IconThemeDarkTest(string typedString, string expectedIconPropertyName)
{
var systemPage = new SystemCommandPage(new SettingsManager());
foreach (var item in systemPage.GetItems())
{
if (item.Title.Contains(typedString, StringComparison.OrdinalIgnoreCase) || item.Subtitle.Contains(typedString, StringComparison.OrdinalIgnoreCase))
{
var icon = item.Icon;
Assert.IsNotNull(icon, $"Icon for '{typedString}' should not be null.");
Assert.IsNotEmpty(icon.Dark.Icon, $"Icon for '{typedString}' should not be empty.");
}
}
}
[DataTestMethod]
[DataRow("shutdown", "ShutdownIcon")]
[DataRow("restart", "RestartIcon")]
[DataRow("sign out", "LogoffIcon")]
[DataRow("lock", "LockIcon")]
[DataRow("sleep", "SleepIcon")]
[DataRow("hibernate", "SleepIcon")]
[DataRow("recycle bin", "RecycleBinIcon")]
[DataRow("uefi firmware settings", "FirmwareSettingsIcon")]
[DataRow("IPv4 addr", "NetworkAdapterIcon")]
[DataRow("IPV6 addr", "NetworkAdapterIcon")]
[DataRow("MAC addr", "NetworkAdapterIcon")]
public void IconThemeLightTest(string typedString, string expectedIconPropertyName)
{
var systemPage = new SystemCommandPage(new SettingsManager());
foreach (var item in systemPage.GetItems())
{
if (item.Title.Contains(typedString, StringComparison.OrdinalIgnoreCase) || item.Subtitle.Contains(typedString, StringComparison.OrdinalIgnoreCase))
{
var icon = item.Icon;
Assert.IsNotNull(icon, $"Icon for '{typedString}' should not be null.");
Assert.IsNotEmpty(icon.Light.Icon, $"Icon for '{typedString}' should not be empty.");
}
}
}
}

View File

@@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Look at Directory.Build.props in root for common stuff as well -->
<Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Microsoft.CmdPal.Ext.System.UnitTests</RootNamespace>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal\tests\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="MSTest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\ext\Microsoft.CmdPal.Ext.System\Microsoft.CmdPal.Ext.System.csproj" />
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,105 +0,0 @@
// 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.Linq;
using Microsoft.CmdPal.Ext.System.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.System.UnitTests;
[TestClass]
public class QueryTests
{
[DataTestMethod]
[DataRow("shutdown", "Shutdown")]
[DataRow("restart", "Restart")]
[DataRow("sign out", "Sign out")]
[DataRow("lock", "Lock")]
[DataRow("sleep", "Sleep")]
[DataRow("hibernate", "Hibernate")]
public void SystemCommandsTest(string typedString, string expectedCommand)
{
// Setup
var commands = Commands.GetSystemCommands(false, false, false, false);
// Act
var result = commands.Where(c => c.Title.Contains(expectedCommand, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
// Assert
Assert.IsNotNull(result);
Assert.IsTrue(result.Title.Contains(expectedCommand, StringComparison.OrdinalIgnoreCase));
}
[TestMethod]
public void RecycleBinCommandTest()
{
// Setup
var commands = Commands.GetSystemCommands(false, false, false, false);
// Act
var result = commands.Where(c => c.Title.Contains("Recycle", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
// Assert
Assert.IsNotNull(result);
}
[TestMethod]
public void NetworkCommandsTest()
{
// Test that network commands can be retrieved
try
{
var networkPropertiesList = NetworkConnectionProperties.GetList();
Assert.IsTrue(networkPropertiesList.Count >= 0); // Should not throw exceptions
}
catch (Exception ex)
{
Assert.Fail($"Network commands should not throw exceptions: {ex.Message}");
}
}
[TestMethod]
public void UefiCommandIsAvailableTest()
{
// Setup
var firmwareType = Win32Helpers.GetSystemFirmwareType();
var isUefiMode = firmwareType == FirmwareType.Uefi;
// Act
var commands = Commands.GetSystemCommands(isUefiMode, false, false, false);
var uefiCommand = commands.Where(c => c.Title.Contains("UEFI", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
// Assert
if (isUefiMode)
{
Assert.IsNotNull(uefiCommand);
}
else
{
// UEFI command may still exist but be disabled on non-UEFI systems
Assert.IsTrue(true); // Test environment independent
}
}
[TestMethod]
public void FirmwareTypeTest()
{
// Test that GetSystemFirmwareType returns a valid enum value
var firmwareType = Win32Helpers.GetSystemFirmwareType();
Assert.IsTrue(Enum.IsDefined(typeof(FirmwareType), firmwareType));
}
[TestMethod]
public void EmptyRecycleBinCommandTest()
{
// Test that empty recycle bin command exists
var commands = Commands.GetSystemCommands(false, false, false, false);
var result = commands.Where(c => c.Title.Contains("Empty", StringComparison.OrdinalIgnoreCase) &&
c.Title.Contains("Recycle", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
// Empty recycle bin command should exist
Assert.IsNotNull(result);
}
}

View File

@@ -1,494 +0,0 @@
// 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.Linq;
using Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class AvailableResultsListTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void CleanUp()
{
// Set culture to original value
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
private DateTime GetDateTimeForTest(bool embedUtc = false)
{
var dateTime = new DateTime(2022, 03, 02, 22, 30, 45);
if (embedUtc)
{
return DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
}
else
{
return dateTime;
}
}
[DataTestMethod]
[DataRow("time", "10:30 PM")]
[DataRow("date", "3/2/2022")]
[DataRow("date and time", "3/2/2022 10:30 PM")]
[DataRow("hour", "22")]
[DataRow("minute", "30")]
[DataRow("second", "45")]
[DataRow("millisecond", "0")]
[DataRow("day (week day)", "Wednesday")]
[DataRow("day of the week (week day)", "4")]
[DataRow("day of the month", "2")]
[DataRow("day of the year", "61")]
[DataRow("week of the month", "1")]
[DataRow("week of the year (calendar week, week number)", "10")]
[DataRow("month", "March")]
[DataRow("month of the year", "3")]
[DataRow("month and day", "March 2")]
[DataRow("year", "2022")]
[DataRow("month and year", "March 2022")]
[DataRow("ISO 8601", "2022-03-02T22:30:45")]
[DataRow("ISO 8601 with time zone", "2022-03-02T22:30:45")]
[DataRow("RFC1123", "Wed, 02 Mar 2022 22:30:45 GMT")]
[DataRow("Date and time in filename-compatible format", "2022-03-02_22-30-45")]
public void LocalFormatsWithShortTimeAndShortDate(string formatLabel, string expectedResult)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, false, false, GetDateTimeForTest());
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value, $"Culture {CultureInfo.CurrentCulture.Name}, Culture UI: {CultureInfo.CurrentUICulture.Name}, Calendar: {CultureInfo.CurrentCulture.Calendar}, Region: {RegionInfo.CurrentRegion.Name}");
}
[TestMethod]
public void GetList_WithKeywordSearch_ReturnsResults()
{
// Setup
var settings = new SettingsManager();
// Act
var results = AvailableResultsList.GetList(true, settings);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, "Should return at least some results for keyword search");
}
[TestMethod]
public void GetList_WithoutKeywordSearch_ReturnsResults()
{
// Setup
var settings = new SettingsManager();
// Act
var results = AvailableResultsList.GetList(false, settings);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, "Should return at least some results for non-keyword search");
}
[TestMethod]
public void GetList_WithSpecificDateTime_ReturnsFormattedResults()
{
// Setup
var settings = new SettingsManager();
var specificDateTime = GetDateTimeForTest();
// Act
var results = AvailableResultsList.GetList(true, settings, null, null, specificDateTime);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, "Should return results for specific datetime");
// Verify that all results have values
foreach (var result in results)
{
Assert.IsNotNull(result.Label, "Result label should not be null");
Assert.IsNotNull(result.Value, "Result value should not be null");
}
}
[TestMethod]
public void GetList_ResultsHaveRequiredProperties()
{
// Setup
var settings = new SettingsManager();
// Act
var results = AvailableResultsList.GetList(true, settings);
// Assert
Assert.IsTrue(results.Count > 0, "Should have results");
foreach (var result in results)
{
Assert.IsNotNull(result.Label, "Each result should have a label");
Assert.IsNotNull(result.Value, "Each result should have a value");
Assert.IsFalse(string.IsNullOrWhiteSpace(result.Label), "Label should not be empty");
Assert.IsFalse(string.IsNullOrWhiteSpace(result.Value), "Value should not be empty");
}
}
[TestMethod]
public void GetList_WithDifferentCalendarSettings_ReturnsResults()
{
// Setup
var settings = new SettingsManager();
// Act & Assert - Test with different settings
var results1 = AvailableResultsList.GetList(true, settings);
Assert.IsNotNull(results1);
Assert.IsTrue(results1.Count > 0);
// Test that the method can handle different calendar settings
var results2 = AvailableResultsList.GetList(false, settings);
Assert.IsNotNull(results2);
Assert.IsTrue(results2.Count > 0);
}
[DataTestMethod]
[DataRow("time", "10:30 PM")]
[DataRow("date", "Wednesday, March 2, 2022")]
[DataRow("date and time", "Wednesday, March 2, 2022 10:30 PM")]
[DataRow("hour", "22")]
[DataRow("minute", "30")]
[DataRow("second", "45")]
[DataRow("millisecond", "0")]
[DataRow("day (week day)", "Wednesday")]
[DataRow("day of the week (week day)", "4")]
[DataRow("day of the month", "2")]
[DataRow("day of the year", "61")]
[DataRow("week of the month", "1")]
[DataRow("week of the year (calendar week, week number)", "10")]
[DataRow("month", "March")]
[DataRow("month of the year", "3")]
[DataRow("month and day", "March 2")]
[DataRow("year", "2022")]
[DataRow("month and year", "March 2022")]
[DataRow("ISO 8601", "2022-03-02T22:30:45")]
[DataRow("ISO 8601 with time zone", "2022-03-02T22:30:45")]
[DataRow("RFC1123", "Wed, 02 Mar 2022 22:30:45 GMT")]
[DataRow("Date and time in filename-compatible format", "2022-03-02_22-30-45")]
public void LocalFormatsWithShortTimeAndLongDate(string formatLabel, string expectedResult)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, false, true, GetDateTimeForTest());
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[DataTestMethod]
[DataRow("time", "10:30:45 PM")]
[DataRow("date", "3/2/2022")]
[DataRow("date and time", "3/2/2022 10:30:45 PM")]
[DataRow("hour", "22")]
[DataRow("minute", "30")]
[DataRow("second", "45")]
[DataRow("millisecond", "0")]
[DataRow("day (week day)", "Wednesday")]
[DataRow("day of the week (week day)", "4")]
[DataRow("day of the month", "2")]
[DataRow("day of the year", "61")]
[DataRow("week of the month", "1")]
[DataRow("week of the year (calendar week, week number)", "10")]
[DataRow("month", "March")]
[DataRow("month of the year", "3")]
[DataRow("month and day", "March 2")]
[DataRow("year", "2022")]
[DataRow("month and year", "March 2022")]
[DataRow("ISO 8601", "2022-03-02T22:30:45")]
[DataRow("ISO 8601 with time zone", "2022-03-02T22:30:45")]
[DataRow("RFC1123", "Wed, 02 Mar 2022 22:30:45 GMT")]
[DataRow("Date and time in filename-compatible format", "2022-03-02_22-30-45")]
public void LocalFormatsWithLongTimeAndShortDate(string formatLabel, string expectedResult)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, true, false, GetDateTimeForTest());
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[DataTestMethod]
[DataRow("time", "10:30:45 PM")]
[DataRow("date", "Wednesday, March 2, 2022")]
[DataRow("date and time", "Wednesday, March 2, 2022 10:30:45 PM")]
[DataRow("hour", "22")]
[DataRow("minute", "30")]
[DataRow("second", "45")]
[DataRow("millisecond", "0")]
[DataRow("day (week day)", "Wednesday")]
[DataRow("day of the week (week day)", "4")]
[DataRow("day of the month", "2")]
[DataRow("day of the year", "61")]
[DataRow("week of the month", "1")]
[DataRow("week of the year (calendar week, week number)", "10")]
[DataRow("month", "March")]
[DataRow("month of the year", "3")]
[DataRow("month and day", "March 2")]
[DataRow("year", "2022")]
[DataRow("month and year", "March 2022")]
[DataRow("ISO 8601", "2022-03-02T22:30:45")]
[DataRow("ISO 8601 with time zone", "2022-03-02T22:30:45")]
[DataRow("RFC1123", "Wed, 02 Mar 2022 22:30:45 GMT")]
[DataRow("Date and time in filename-compatible format", "2022-03-02_22-30-45")]
public void LocalFormatsWithLongTimeAndLongDate(string formatLabel, string expectedResult)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, true, true, GetDateTimeForTest());
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[DataTestMethod]
[DataRow("time utc", "t")]
[DataRow("date and time utc", "g")]
[DataRow("ISO 8601 UTC", "yyyy-MM-ddTHH:mm:ss")]
[DataRow("ISO 8601 UTC with time zone", "yyyy-MM-ddTHH:mm:ss'Z'")]
[DataRow("Universal time format: YYYY-MM-DD hh:mm:ss", "u")]
[DataRow("Date and time in filename-compatible format", "yyyy-MM-dd_HH-mm-ss")]
public void UtcFormatsWithShortTimeAndShortDate(string formatLabel, string expectedFormat)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, false, false, GetDateTimeForTest(true));
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[DataTestMethod]
[DataRow("time utc", "t")]
[DataRow("date and time utc", "f")]
[DataRow("ISO 8601 UTC", "yyyy-MM-ddTHH:mm:ss")]
[DataRow("ISO 8601 UTC with time zone", "yyyy-MM-ddTHH:mm:ss'Z'")]
[DataRow("Universal time format: YYYY-MM-DD hh:mm:ss", "u")]
[DataRow("Date and time in filename-compatible format", "yyyy-MM-dd_HH-mm-ss")]
public void UtcFormatsWithShortTimeAndLongDate(string formatLabel, string expectedFormat)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, false, true, GetDateTimeForTest(true));
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[DataTestMethod]
[DataRow("time utc", "T")]
[DataRow("date and time utc", "G")]
[DataRow("ISO 8601 UTC", "yyyy-MM-ddTHH:mm:ss")]
[DataRow("ISO 8601 UTC with time zone", "yyyy-MM-ddTHH:mm:ss'Z'")]
[DataRow("Universal time format: YYYY-MM-DD hh:mm:ss", "u")]
[DataRow("Date and time in filename-compatible format", "yyyy-MM-dd_HH-mm-ss")]
public void UtcFormatsWithLongTimeAndShortDate(string formatLabel, string expectedFormat)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, true, false, GetDateTimeForTest(true));
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[DataTestMethod]
[DataRow("time utc", "T")]
[DataRow("date and time utc", "F")]
[DataRow("ISO 8601 UTC", "yyyy-MM-ddTHH:mm:ss")]
[DataRow("ISO 8601 UTC with time zone", "yyyy-MM-ddTHH:mm:ss'Z'")]
[DataRow("Universal time format: YYYY-MM-DD hh:mm:ss", "u")]
[DataRow("Date and time in filename-compatible format", "yyyy-MM-dd_HH-mm-ss")]
public void UtcFormatsWithLongTimeAndLongDate(string formatLabel, string expectedFormat)
{
// Setup
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, true, true, GetDateTimeForTest(true));
var expectedResult = GetDateTimeForTest().ToString(expectedFormat, CultureInfo.CurrentCulture);
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[TestMethod]
public void UnixTimestampSecondsFormat()
{
// Setup
string formatLabel = "Unix epoch time";
DateTime timeValue = DateTime.Now.ToUniversalTime();
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, null, null, timeValue);
var expectedResult = (long)timeValue.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult.ToString(CultureInfo.CurrentCulture), result?.Value);
}
[TestMethod]
public void UnixTimestampMillisecondsFormat()
{
// Setup
string formatLabel = "Unix epoch time in milliseconds";
DateTime timeValue = DateTime.Now.ToUniversalTime();
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, null, null, timeValue);
var expectedResult = (long)timeValue.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult.ToString(CultureInfo.CurrentCulture), result?.Value);
}
[TestMethod]
public void WindowsFileTimeFormat()
{
// Setup
string formatLabel = "Windows file time (Int64 number)";
DateTime timeValue = DateTime.Now;
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, null, null, timeValue);
var expectedResult = timeValue.ToFileTime().ToString(CultureInfo.CurrentCulture);
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[TestMethod]
public void ValidateEraResult()
{
// Setup
string formatLabel = "Era";
DateTime timeValue = DateTime.Now;
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, null, null, timeValue);
var expectedResult = DateTimeFormatInfo.CurrentInfo.GetEraName(CultureInfo.CurrentCulture.Calendar.GetEra(timeValue));
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[TestMethod]
public void ValidateEraAbbreviationResult()
{
// Setup
string formatLabel = "Era abbreviation";
DateTime timeValue = DateTime.Now;
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, null, null, timeValue);
var expectedResult = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedEraName(CultureInfo.CurrentCulture.Calendar.GetEra(timeValue));
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult, result?.Value);
}
[DataTestMethod]
[DataRow(CalendarWeekRule.FirstDay, "3")]
[DataRow(CalendarWeekRule.FirstFourDayWeek, "2")]
[DataRow(CalendarWeekRule.FirstFullWeek, "2")]
public void DifferentFirstWeekSettingConfigurations(CalendarWeekRule weekRule, string expectedWeekOfYear)
{
// Setup
DateTime timeValue = new DateTime(2021, 1, 12);
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, null, null, timeValue, weekRule, DayOfWeek.Sunday);
// Act
var resultWeekOfYear = helperResults.FirstOrDefault(x => x.Label.Equals("week of the year (calendar week, week number)", StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedWeekOfYear, resultWeekOfYear?.Value);
}
[DataTestMethod]
[DataRow(DayOfWeek.Monday, "2", "2", "5")]
[DataRow(DayOfWeek.Tuesday, "3", "3", "4")]
[DataRow(DayOfWeek.Wednesday, "3", "3", "3")]
[DataRow(DayOfWeek.Thursday, "3", "3", "2")]
[DataRow(DayOfWeek.Friday, "3", "3", "1")]
[DataRow(DayOfWeek.Saturday, "2", "2", "7")]
[DataRow(DayOfWeek.Sunday, "2", "2", "6")]
public void DifferentFirstDayOfWeekSettingConfigurations(DayOfWeek dayOfWeek, string expectedWeekOfYear, string expectedWeekOfMonth, string expectedDayInWeek)
{
// Setup
DateTime timeValue = new DateTime(2024, 1, 12); // Friday
var settings = new SettingsManager();
var helperResults = AvailableResultsList.GetList(true, settings, null, null, timeValue, CalendarWeekRule.FirstDay, dayOfWeek);
// Act
var resultWeekOfYear = helperResults.FirstOrDefault(x => x.Label.Equals("week of the year (calendar week, week number)", StringComparison.OrdinalIgnoreCase));
var resultWeekOfMonth = helperResults.FirstOrDefault(x => x.Label.Equals("week of the month", StringComparison.OrdinalIgnoreCase));
var resultDayInWeek = helperResults.FirstOrDefault(x => x.Label.Equals("day of the week (week day)", StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedWeekOfYear, resultWeekOfYear?.Value);
Assert.AreEqual(expectedWeekOfMonth, resultWeekOfMonth?.Value);
Assert.AreEqual(expectedDayInWeek, resultDayInWeek?.Value);
}
}

View File

@@ -1,28 +0,0 @@
// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class BasicTests
{
[TestMethod]
public void BasicTest()
{
// This is a basic test to verify the test project can run
Assert.IsTrue(true);
}
[TestMethod]
public void DateTimeTest()
{
// Test basic DateTime functionality
var now = DateTime.Now;
Assert.IsNotNull(now);
Assert.IsTrue(now > DateTime.MinValue);
}
}

View File

@@ -1,86 +0,0 @@
// 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 Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class FallbackTimeDateItemTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void Cleanup()
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[DataTestMethod]
[DataRow("time", "12:00 PM")]
[DataRow("date", "7/1/2025")]
[DataRow("week", "27")]
public void FallbackQueryTests(string query, string expectedTitle)
{
// Setup
var settingsManager = new SettingsManager();
DateTime now = new DateTime(2025, 7, 1, 12, 0, 0); // Fixed date for testing
var fallbackItem = new FallbackTimeDateItem(settingsManager, now);
// Act & Assert - Test that UpdateQuery doesn't throw exceptions
try
{
fallbackItem.UpdateQuery(query);
Assert.IsTrue(
fallbackItem.Title.Contains(expectedTitle, StringComparison.OrdinalIgnoreCase),
$"Expected title to contain '{expectedTitle}', but got '{fallbackItem.Title}'");
Assert.IsNotNull(fallbackItem.Subtitle, "Subtitle should not be null");
Assert.IsNotNull(fallbackItem.Icon, "Icon should not be null");
}
catch (Exception ex)
{
Assert.Fail($"UpdateQuery should not throw exceptions: {ex.Message}");
}
}
[DataTestMethod]
[DataRow(null)]
[DataRow("invalid input")]
public void InvalidQueryTests(string query)
{
// Setup
var settingsManager = new SettingsManager();
DateTime now = new DateTime(2025, 7, 1, 12, 0, 0); // Fixed date for testing
var fallbackItem = new FallbackTimeDateItem(settingsManager, now);
// Act & Assert - Test that UpdateQuery doesn't throw exceptions
try
{
fallbackItem.UpdateQuery(query);
Assert.AreEqual(string.Empty, fallbackItem.Title, "Title should be empty for invalid queries");
Assert.AreEqual(string.Empty, fallbackItem.Subtitle, "Subtitle should be empty for invalid queries");
}
catch (Exception ex)
{
Assert.Fail($"UpdateQuery should not throw exceptions: {ex.Message}");
}
}
}

View File

@@ -1,127 +0,0 @@
// 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 Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class IconTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void CleanUp()
{
// Set culture to original value
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[TestMethod]
public void TimeDateCommandsProvider_HasIcon()
{
// Setup
var provider = new TimeDateCommandsProvider();
// Act
var icon = provider.Icon;
// Assert
Assert.IsNotNull(icon, "Provider should have an icon");
}
[TestMethod]
public void TimeDateCommandsProvider_TopLevelCommands_HaveIcons()
{
// Setup
var provider = new TimeDateCommandsProvider();
// Act
var commands = provider.TopLevelCommands();
// Assert
Assert.IsNotNull(commands);
Assert.IsTrue(commands.Length > 0, "Should have at least one top-level command");
foreach (var command in commands)
{
Assert.IsNotNull(command.Icon, "Each command should have an icon");
}
}
[TestMethod]
public void AvailableResults_HaveIcons()
{
// Setup
var settings = new SettingsManager();
// Act
var results = AvailableResultsList.GetList(true, settings);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, "Should have results");
foreach (var result in results)
{
Assert.IsNotNull(result.GetIconInfo(), $"Result '{result.Label}' should have an icon");
}
}
[DataTestMethod]
[DataRow(ResultIconType.Time, "\uE823")]
[DataRow(ResultIconType.Date, "\uE787")]
[DataRow(ResultIconType.DateTime, "\uEC92")]
public void ResultHelper_CreateListItem_PreservesIcon(ResultIconType resultIconType, string expectedIcon)
{
// Setup
var availableResult = new AvailableResult
{
Label = "Test Label",
Value = "Test Value",
IconType = resultIconType,
};
// Act
var listItem = availableResult.ToListItem();
var icon = listItem.Icon;
// Assert
Assert.IsNotNull(listItem);
Assert.IsNotNull(listItem.Icon, "ListItem should preserve the icon from AvailableResult");
Assert.AreEqual(expectedIcon, icon.Dark.Icon, $"Icon for {resultIconType} should match expected value");
}
[TestMethod]
public void Icons_AreNotEmpty()
{
// Setup
var settings = new SettingsManager();
var results = AvailableResultsList.GetList(true, settings);
// Act & Assert
foreach (var result in results)
{
Assert.IsNotNull(result.GetIconInfo(), $"Result '{result.Label}' should have an icon");
Assert.IsFalse(string.IsNullOrWhiteSpace(result.GetIconInfo().ToString()), $"Icon for '{result.Label}' should not be empty");
}
}
}

View File

@@ -1,23 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Look at Directory.Build.props in root for common stuff as well -->
<Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Microsoft.CmdPal.Ext.TimeDate.UnitTests</RootNamespace>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal\tests\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="MSTest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\ext\Microsoft.CmdPal.Ext.TimeDate\Microsoft.CmdPal.Ext.TimeDate.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,350 +0,0 @@
// 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.Linq;
using Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class QueryTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void CleanUp()
{
// Set culture to original value
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[DataTestMethod]
[DataRow("time", 1)] // Common time queries should return results
[DataRow("date", 1)] // Common date queries should return results
[DataRow("now", 1)] // Now should return multiple results
[DataRow("current", 1)] // Current should return multiple results
[DataRow("year", 1)] // Year-related queries should return results
[DataRow("time::10:10:10", 1)] // Specific time format should return results
[DataRow("date::10/10/10", 1)] // Specific date format should return results
public void CountBasicQueries(string query, int expectedMinResultCount)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsTrue(
results.Count >= expectedMinResultCount,
$"Expected at least {expectedMinResultCount} results for query '{query}', but got {results.Count}");
}
[DataTestMethod]
[DataRow("time")]
[DataRow("date")]
[DataRow("year")]
[DataRow("now")]
[DataRow("current")]
[DataRow("")]
[DataRow("now::10:10:10")] // Windows file time
public void AllQueriesReturnResults(string query)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, $"Query '{query}' should return at least one result");
}
[DataTestMethod]
[DataRow("time", "Time")]
[DataRow("date", "Date")]
[DataRow("now", "Now")]
[DataRow("unix", "Unix epoch time")]
[DataRow("unix epoch time in milli", "Unix epoch time in milliseconds")]
[DataRow("file", "Windows file time (Int64 number)")]
[DataRow("hour", "Hour")]
[DataRow("minute", "Minute")]
[DataRow("second", "Second")]
[DataRow("millisecond", "Millisecond")]
[DataRow("day", "Day (Week day)")]
[DataRow("day of week", "Day of the week (Week day)")]
[DataRow("day of month", "Day of the month")]
[DataRow("day of year", "Day of the year")]
[DataRow("week of month", "Week of the month")]
[DataRow("week of year", "Week of the year (Calendar week, Week number)")]
[DataRow("month", "Month")]
[DataRow("month of year", "Month of the year")]
[DataRow("month and d", "Month and day")]
[DataRow("month and y", "Month and year")]
[DataRow("year", "Year")]
[DataRow("era", "Era")]
[DataRow("era a", "Era abbreviation")]
[DataRow("universal", "Universal time format: YYYY-MM-DD hh:mm:ss")]
[DataRow("iso", "ISO 8601")]
[DataRow("rfc", "RFC1123")]
[DataRow("time::12:30", "Time")]
[DataRow("date::10.10.2022", "Date")]
[DataRow("time::u1646408119", "Time")]
[DataRow("time::ft637820085517321977", "Time")]
[DataRow("week day", "Day (Week day)")]
[DataRow("cal week", "Week of the year (Calendar week, Week number)")]
[DataRow("week num", "Week of the year (Calendar week, Week number)")]
[DataRow("days in mo", "Days in month")]
[DataRow("Leap y", "Leap year")]
public void CanFindFormatResult(string query, string expectedSubtitle)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
var matchingResult = results.FirstOrDefault(x => x.Subtitle?.StartsWith(expectedSubtitle, StringComparison.CurrentCulture) == true);
Assert.IsNotNull(matchingResult, $"Could not find result with subtitle starting with '{expectedSubtitle}' for query '{query}'");
}
[DataTestMethod]
[DataRow("12:30", "Time")]
[DataRow("10.10.2022", "Date")]
[DataRow("u1646408119", "Date and time")]
[DataRow("u+1646408119", "Date and time")]
[DataRow("u-1646408119", "Date and time")]
[DataRow("ums1646408119", "Date and time")]
[DataRow("ums+1646408119", "Date and time")]
[DataRow("ums-1646408119", "Date and time")]
[DataRow("ft637820085517321977", "Date and time")]
public void DateTimeNumberOnlyInput(string query, string expectedSubtitle)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
var matchingResult = results.FirstOrDefault(x => x.Subtitle?.StartsWith(expectedSubtitle, StringComparison.CurrentCulture) == true);
Assert.IsNotNull(matchingResult, $"Could not find result with subtitle starting with '{expectedSubtitle}' for query '{query}'");
}
[DataTestMethod]
[DataRow("abcdefg")]
[DataRow("timmmmeeee")]
[DataRow("timtaaaetetaae::u1646408119")]
[DataRow("time:eeee")]
[DataRow("time::eeee")]
[DataRow("time//eeee")]
public void InvalidInputShowsErrorResults(string query)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results, $"Results should not be null for query '{query}'");
Assert.IsTrue(results.Count > 0, $"Query '{query}' should return at least one result");
// For invalid input, cmdpal returns an error result
var hasErrorResult = results.Any(r => r.Title?.StartsWith("Error: Invalid input", StringComparison.CurrentCulture) == true);
Assert.IsTrue(hasErrorResult, $"Query '{query}' should return an error result for invalid input");
}
[DataTestMethod]
[DataRow("ug1646408119")] // Invalid prefix
[DataRow("u9999999999999")] // Unix number + prefix is longer than 12 characters
[DataRow("ums999999999999999")] // Unix number in milliseconds + prefix is longer than 17 characters
[DataRow("-u99999999999")] // Unix number with wrong placement of - sign
[DataRow("+ums9999999999")] // Unix number in milliseconds with wrong placement of + sign
[DataRow("0123456")] // Missing prefix
[DataRow("ft63782008ab55173dasdas21977")] // Number contains letters
[DataRow("ft63782008ab55173dasdas")] // Number contains letters at the end
[DataRow("ft12..548")] // Number contains wrong punctuation
[DataRow("ft12..54//8")] // Number contains wrong punctuation and other characters
[DataRow("time::ft12..54//8")] // Number contains wrong punctuation and other characters
[DataRow("ut2ed.5555")] // Number contains letters
[DataRow("12..54//8")] // Number contains punctuation and other characters, but no special prefix
[DataRow("ft::1288gg8888")] // Number contains delimiter and letters, but no special prefix
[DataRow("date::12::55")]
[DataRow("date::12:aa:55")]
[DataRow("10.aa.22")]
[DataRow("12::55")]
[DataRow("12:aa:55")]
public void InvalidNumberInputShowsErrorMessage(string query)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results, $"Results should not be null for query '{query}'");
Assert.IsTrue(results.Count > 0, $"Should return at least one result (error message) for invalid query '{query}'");
// Check if we get an error result
var errorResult = results.FirstOrDefault(r => r.Title?.StartsWith("Error: Invalid input", StringComparison.CurrentCulture) == true);
Assert.IsNotNull(errorResult, $"Should return an error result for invalid query '{query}'");
}
[DataTestMethod]
[DataRow("10.10aa")] // Input contains <Number>.<Number> (Can be part of a date.)
[DataRow("10:10aa")] // Input contains <Number>:<Number> (Can be part of a time.)
[DataRow("10/10aa")] // Input contains <Number>/<Number> (Can be part of a date.)
public void InvalidInputNotShowsErrorMessage(string query)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results, $"Results should not be null for query '{query}'");
// These queries are ambiguous and cmdpal returns an error for them
// This test might need to be adjusted based on actual cmdpal behavior
if (results.Count > 0)
{
var hasErrorResult = results.Any(r => r.Title?.StartsWith("Error: Invalid input", StringComparison.CurrentCulture) == true);
// For these ambiguous inputs, cmdpal may return error results, which is acceptable
// We just verify that the system handles them gracefully (doesn't crash)
Assert.IsTrue(true, $"Query '{query}' handled gracefully");
}
}
[DataTestMethod]
[DataRow("time", "time", true)] // Full word match should work
[DataRow("date", "date", true)] // Full word match should work
[DataRow("now", "now", true)] // Full word match should work
[DataRow("year", "year", true)] // Full word match should work
[DataRow("abcdefg", "", false)] // Invalid query should return error
public void ValidateBehaviorOnSearchQueries(string query, string expectedMatchTerm, bool shouldHaveValidResults)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results, $"Results should not be null for query '{query}'");
Assert.IsTrue(results.Count > 0, $"Query '{query}' should return at least one result");
if (shouldHaveValidResults)
{
// Should have non-error results
var hasValidResult = results.Any(r => !r.Title?.StartsWith("Error: Invalid input", StringComparison.CurrentCulture) == true);
Assert.IsTrue(hasValidResult, $"Query '{query}' should return valid (non-error) results");
if (!string.IsNullOrEmpty(expectedMatchTerm))
{
var hasMatchingResult = results.Any(r =>
r.Title?.Contains(expectedMatchTerm, StringComparison.CurrentCultureIgnoreCase) == true ||
r.Subtitle?.Contains(expectedMatchTerm, StringComparison.CurrentCultureIgnoreCase) == true);
Assert.IsTrue(hasMatchingResult, $"Query '{query}' should return results containing '{expectedMatchTerm}'");
}
}
else
{
// Should have error results
var hasErrorResult = results.Any(r => r.Title?.StartsWith("Error: Invalid input", StringComparison.CurrentCulture) == true);
Assert.IsTrue(hasErrorResult, $"Query '{query}' should return error results for invalid input");
}
}
[TestMethod]
public void EmptyQueryReturnsAllResults()
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, string.Empty);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, "Empty query should return all available results");
}
[TestMethod]
public void NullQueryReturnsAllResults()
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, null);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, "Null query should return all available results");
}
[DataTestMethod]
[DataRow("time u", "Time UTC")]
[DataRow("now u", "Now UTC")]
[DataRow("iso utc", "ISO 8601 UTC")]
[DataRow("iso zone", "ISO 8601 with time zone")]
[DataRow("iso utc zone", "ISO 8601 UTC with time zone")]
public void UTCRelatedQueries(string query, string expectedSubtitle)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count > 0, $"Query '{query}' should return results");
var matchingResult = results.FirstOrDefault(x => x.Subtitle?.StartsWith(expectedSubtitle, StringComparison.CurrentCulture) == true);
Assert.IsNotNull(matchingResult, $"Could not find result with subtitle starting with '{expectedSubtitle}' for query '{query}'");
}
[DataTestMethod]
[DataRow("time::12:30:45")]
[DataRow("date::2023-12-25")]
[DataRow("now::u1646408119")]
[DataRow("current::ft637820085517321977")]
public void DelimiterQueriesReturnResults(string query)
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results);
// Delimiter queries should return results even if parsing fails (error results)
Assert.IsTrue(results.Count > 0, $"Delimiter query '{query}' should return at least one result");
}
}

View File

@@ -1,143 +0,0 @@
// 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 Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class ResultHelperTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void CleanUp()
{
// Set culture to original value
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[TestMethod]
public void ResultHelper_CreateListItem_ReturnsValidItem()
{
// Setup
var availableResult = new AvailableResult
{
Label = "Test Label",
Value = "Test Value",
};
// Act
var listItem = availableResult.ToListItem();
// Assert
Assert.IsNotNull(listItem);
Assert.AreEqual("Test Value", listItem.Title);
Assert.AreEqual("Test Label", listItem.Subtitle);
}
[TestMethod]
public void ResultHelper_CreateListItem_HandlesNullInput()
{
AvailableResult availableResult = null;
// Act & Assert
Assert.ThrowsException<System.NullReferenceException>(() => availableResult.ToListItem());
}
[TestMethod]
public void ResultHelper_CreateListItem_HandlesEmptyValues()
{
// Setup
var availableResult = new AvailableResult
{
Label = string.Empty,
Value = string.Empty,
};
// Act
var listItem = availableResult.ToListItem();
// Assert
Assert.IsNotNull(listItem);
Assert.AreEqual("Copy", listItem.Title);
Assert.AreEqual(string.Empty, listItem.Subtitle);
}
[TestMethod]
public void ResultHelper_CreateListItem_WithIcon()
{
// Setup
var availableResult = new AvailableResult
{
Label = "Test Label",
Value = "Test Value",
IconType = ResultIconType.Date,
};
// Act
var listItem = availableResult.ToListItem();
// Assert
Assert.IsNotNull(listItem);
Assert.AreEqual("Test Value", listItem.Title);
Assert.AreEqual("Test Label", listItem.Subtitle);
Assert.IsNotNull(listItem.Icon);
}
[TestMethod]
public void ResultHelper_CreateListItem_WithLongText()
{
// Setup
var longText = new string('A', 1000);
var availableResult = new AvailableResult
{
Label = longText,
Value = longText,
};
// Act
var listItem = availableResult.ToListItem();
// Assert
Assert.IsNotNull(listItem);
Assert.AreEqual(longText, listItem.Title);
Assert.AreEqual(longText, listItem.Subtitle);
}
[TestMethod]
public void ResultHelper_CreateListItem_WithSpecialCharacters()
{
// Setup
var specialText = "Test & < > \" ' \n \t";
var availableResult = new AvailableResult
{
Label = specialText,
Value = specialText,
};
// Act
var listItem = availableResult.ToListItem();
// Assert
Assert.IsNotNull(listItem);
Assert.AreEqual(specialText, listItem.Title);
Assert.AreEqual(specialText, listItem.Subtitle);
}
}

View File

@@ -1,85 +0,0 @@
// 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 Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class SettingsManagerTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void Cleanup()
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[TestMethod]
public void SettingsManagerInitializationTest()
{
// Act
var settingsManager = new SettingsManager();
// Assert
Assert.IsNotNull(settingsManager);
Assert.IsNotNull(settingsManager.Settings);
}
[TestMethod]
public void DefaultSettingsValidation()
{
// Act
var settingsManager = new SettingsManager();
// Assert - Check that properties are accessible
var enableFallback = settingsManager.EnableFallbackItems;
var timeWithSecond = settingsManager.TimeWithSecond;
var dateWithWeekday = settingsManager.DateWithWeekday;
var firstWeekOfYear = settingsManager.FirstWeekOfYear;
var firstDayOfWeek = settingsManager.FirstDayOfWeek;
var customFormats = settingsManager.CustomFormats;
Assert.IsNotNull(customFormats);
}
[TestMethod]
public void SettingsPropertiesAccessibilityTest()
{
// Setup
var settingsManager = new SettingsManager();
// Act & Assert - Verify all properties are accessible without exception
try
{
_ = settingsManager.EnableFallbackItems;
_ = settingsManager.TimeWithSecond;
_ = settingsManager.DateWithWeekday;
_ = settingsManager.FirstWeekOfYear;
_ = settingsManager.FirstDayOfWeek;
_ = settingsManager.CustomFormats;
}
catch (Exception ex)
{
Assert.Fail($"Settings properties should be accessible: {ex.Message}");
}
}
}

View File

@@ -1,135 +0,0 @@
// 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 Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class StringParserTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[DataTestMethod]
[DataRow("10/29/2022 17:05:10", true, "G", "10/29/2022 5:05:10 PM")]
[DataRow("Saturday, October 29, 2022 5:05:10 PM", true, "G", "10/29/2022 5:05:10 PM")]
[DataRow("10/29/2022", true, "d", "10/29/2022")]
[DataRow("Saturday, October 29, 2022", true, "d", "10/29/2022")]
[DataRow("17:05:10", true, "T", "5:05:10 PM")]
[DataRow("5:05:10 PM", true, "T", "5:05:10 PM")]
[DataRow("10456", false, "", "")]
[DataRow("u10456", true, "", "")] // Value is UTC and can be different based on system
[DataRow("u-10456", true, "", "")] // Value is UTC and can be different based on system
[DataRow("u+10456", true, "", "")] // Value is UTC and can be different based on system
[DataRow("ums10456", true, "", "")] // Value is UTC and can be different based on system
[DataRow("ums-10456", true, "", "")] // Value is UTC and can be different based on system
[DataRow("ums+10456", true, "", "")] // Value is UTC and can be different based on system
[DataRow("ft10456", true, "", "")] // Value is UTC and can be different based on system
[DataRow("oa-657434.99999999", true, "G", "1/1/0100 11:59:59 PM")]
[DataRow("oa2958465.99999999", true, "G", "12/31/9999 11:59:59 PM")]
[DataRow("oa-657435", false, "", "")] // Value to low
[DataRow("oa2958466", false, "", "")] // Value to large
[DataRow("exc1.99998843", true, "G", "1/1/1900 11:59:59 PM")]
[DataRow("exc59.99998843", true, "G", "2/28/1900 11:59:59 PM")]
[DataRow("exc61", true, "G", "3/1/1900 12:00:00 AM")]
[DataRow("exc62.99998843", true, "G", "3/2/1900 11:59:59 PM")]
[DataRow("exc2958465.99998843", true, "G", "12/31/9999 11:59:59 PM")]
[DataRow("exc0", false, "", "")] // Day 0 means in Excel 0/1/1900 and this is a fake date.
[DataRow("exc0.99998843", false, "", "")] // Day 0 means in Excel 0/1/1900 and this is a fake date.
[DataRow("exc60.99998843", false, "", "")] // Day 60 means in Excel 2/29/1900 and this is a fake date in Excel which we cannot support.
[DataRow("exc60", false, "", "")] // Day 60 means in Excel 2/29/1900 and this is a fake date in Excel which we cannot support.
[DataRow("exc-1", false, "", "")] // Value to low
[DataRow("exc2958466", false, "", "")] // Value to large
[DataRow("exf0.99998843", true, "G", "1/1/1904 11:59:59 PM")]
[DataRow("exf2957003.99998843", true, "G", "12/31/9999 11:59:59 PM")]
[DataRow("exf-0.5", false, "", "")] // Value to low
[DataRow("exf2957004", false, "", "")] // Value to large
public void ConvertStringToDateTime(string typedString, bool expectedBool, string stringType, string expectedString)
{
// Act
var boolResult = TimeAndDateHelper.ParseStringAsDateTime(in typedString, out DateTime result, out _);
// Assert
Assert.AreEqual(expectedBool, boolResult);
if (!string.IsNullOrEmpty(expectedString))
{
Assert.AreEqual(expectedString, result.ToString(stringType, CultureInfo.CurrentCulture));
}
}
[TestMethod]
public void ParseStringAsDateTime_BasicTest()
{
// Test basic string parsing functionality
var testCases = new[]
{
("2023-12-25", true),
("12/25/2023", true),
("invalid date", false),
(string.Empty, false),
};
foreach (var (input, expectedSuccess) in testCases)
{
// Act
var result = TimeAndDateHelper.ParseStringAsDateTime(in input, out DateTime dateTime, out var errorMessage);
// Assert
Assert.AreEqual(expectedSuccess, result, $"Failed for input: {input}");
if (!expectedSuccess)
{
Assert.IsFalse(string.IsNullOrEmpty(errorMessage), $"Error message should not be empty for invalid input: {input}");
}
}
}
[TestMethod]
public void ParseStringAsDateTime_UnixTimestampTest()
{
// Test Unix timestamp parsing
var unixTimestamp = "u1640995200"; // 2022-01-01 00:00:00 UTC
// Act
var result = TimeAndDateHelper.ParseStringAsDateTime(in unixTimestamp, out DateTime dateTime, out var errorMessage);
// Assert
Assert.IsTrue(result, "Unix timestamp parsing should succeed");
Assert.IsTrue(string.IsNullOrEmpty(errorMessage), "Error message should be empty for valid Unix timestamp");
}
[TestMethod]
public void ParseStringAsDateTime_FileTimeTest()
{
// Test Windows file time parsing
var fileTime = "ft132857664000000000"; // Some valid file time
// Act
var result = TimeAndDateHelper.ParseStringAsDateTime(in fileTime, out DateTime dateTime, out var errorMessage);
// Assert
Assert.IsTrue(result, "File time parsing should succeed");
}
[TestCleanup]
public void CleanUp()
{
// Set culture to original value
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
}

View File

@@ -1,132 +0,0 @@
// 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 Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class TimeAndDateHelperTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void Cleanup()
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[DataTestMethod]
[DataRow(-1, null)] // default setting
[DataRow(0, CalendarWeekRule.FirstDay)]
[DataRow(1, CalendarWeekRule.FirstFullWeek)]
[DataRow(2, CalendarWeekRule.FirstFourDayWeek)]
[DataRow(30, null)] // wrong setting
public void GetCalendarWeekRuleBasedOnPluginSetting(int setting, CalendarWeekRule? valueExpected)
{
// Act
var result = TimeAndDateHelper.GetCalendarWeekRule(setting);
// Assert
if (valueExpected == null)
{
// falls back to system setting.
Assert.AreEqual(DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, result);
}
else
{
Assert.AreEqual(valueExpected, result);
}
}
[DataTestMethod]
[DataRow(-1, null)] // default setting
[DataRow(0, DayOfWeek.Sunday)]
[DataRow(1, DayOfWeek.Monday)]
[DataRow(2, DayOfWeek.Tuesday)]
[DataRow(3, DayOfWeek.Wednesday)]
[DataRow(4, DayOfWeek.Thursday)]
[DataRow(5, DayOfWeek.Friday)]
[DataRow(6, DayOfWeek.Saturday)]
[DataRow(30, null)] // wrong setting
public void GetFirstDayOfWeekBasedOnPluginSetting(int setting, DayOfWeek? valueExpected)
{
// Act
var result = TimeAndDateHelper.GetFirstDayOfWeek(setting);
// Assert
if (valueExpected == null)
{
// falls back to system setting.
Assert.AreEqual(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek, result);
}
else
{
Assert.AreEqual(valueExpected, result);
}
}
[DataTestMethod]
[DataRow("yyyy-MM-dd", "2023-12-25")]
[DataRow("MM/dd/yyyy", "12/25/2023")]
[DataRow("dd.MM.yyyy", "25.12.2023")]
public void GetDateTimeFormatTest(string format, string expectedPattern)
{
// Setup
var testDate = new DateTime(2023, 12, 25);
// Act
var result = testDate.ToString(format, CultureInfo.CurrentCulture);
// Assert
Assert.AreEqual(expectedPattern, result);
}
[TestMethod]
public void GetCurrentTimeFormatTest()
{
// Setup
var testDateTime = new DateTime(2023, 12, 25, 14, 30, 45);
// Act
var timeResult = testDateTime.ToString("T", CultureInfo.CurrentCulture);
var dateResult = testDateTime.ToString("d", CultureInfo.CurrentCulture);
// Assert
Assert.AreEqual("2:30:45 PM", timeResult);
Assert.AreEqual("12/25/2023", dateResult);
}
[DataTestMethod]
[DataRow("yyyy-MM-dd HH:mm:ss", "2023-12-25 14:30:45")]
[DataRow("dddd, MMMM dd, yyyy", "Monday, December 25, 2023")]
[DataRow("HH:mm:ss tt", "14:30:45 PM")]
public void ValidateCustomDateTimeFormats(string format, string expectedResult)
{
// Setup
var testDate = new DateTime(2023, 12, 25, 14, 30, 45);
// Act
var result = testDate.ToString(format, CultureInfo.CurrentCulture);
// Assert
Assert.AreEqual(expectedResult, result);
}
}

View File

@@ -1,124 +0,0 @@
// 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.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests;
[TestClass]
public class TimeDateCalculatorTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void Cleanup()
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[TestMethod]
public void CountAllResults()
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, string.Empty);
// Assert
Assert.IsTrue(results.Count > 0);
}
[TestMethod]
public void ValidateEmptyQuery()
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, string.Empty);
// Assert
Assert.IsNotNull(results);
}
[TestMethod]
public void ValidateNullQuery()
{
// Setup
var settings = new SettingsManager();
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, null);
// Assert
Assert.IsNotNull(results);
}
[TestMethod]
public void ValidateTimeParsing()
{
// Setup
var settings = new SettingsManager();
var query = "time::10:30:45";
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count >= 0); // May have 0 results due to invalid format, but shouldn't crash
}
[TestMethod]
public void ValidateDateParsing()
{
// Setup
var settings = new SettingsManager();
var query = "date::12/25/2023";
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results);
Assert.IsTrue(results.Count >= 0); // May have 0 results due to invalid format, but shouldn't crash
}
[TestMethod]
public void ValidateCommonQueries()
{
// Setup
var settings = new SettingsManager();
var queries = new[] { "time", "date", "now", "current" };
foreach (var query in queries)
{
// Act
var results = TimeDateCalculator.ExecuteSearch(settings, query);
// Assert
Assert.IsNotNull(results, $"Results should not be null for query: {query}");
}
}
}

View File

@@ -1,109 +0,0 @@
// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.TimeDate.UnitTests
{
[TestClass]
public class TimeDateCommandsProviderTests
{
private CultureInfo originalCulture;
private CultureInfo originalUiCulture;
[TestInitialize]
public void Setup()
{
// Set culture to 'en-us'
originalCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-us", false);
originalUiCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo("en-us", false);
}
[TestCleanup]
public void Cleanup()
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUiCulture;
}
[TestMethod]
public void TimeDateCommandsProviderInitializationTest()
{
// Act
var provider = new TimeDateCommandsProvider();
// Assert
Assert.IsNotNull(provider);
Assert.IsNotNull(provider.DisplayName);
Assert.AreEqual("DateTime", provider.Id);
Assert.IsNotNull(provider.Icon);
Assert.IsNotNull(provider.Settings);
}
[TestMethod]
public void TopLevelCommandsTest()
{
// Setup
var provider = new TimeDateCommandsProvider();
// Act
var commands = provider.TopLevelCommands();
// Assert
Assert.IsNotNull(commands);
Assert.AreEqual(1, commands.Length);
Assert.IsNotNull(commands[0]);
Assert.IsNotNull(commands[0].Title);
Assert.IsNotNull(commands[0].Icon);
}
[TestMethod]
public void FallbackCommandsTest()
{
// Setup
var provider = new TimeDateCommandsProvider();
// Act
var fallbackCommands = provider.FallbackCommands();
// Assert
Assert.IsNotNull(fallbackCommands);
Assert.AreEqual(1, fallbackCommands.Length);
Assert.IsNotNull(fallbackCommands[0]);
}
[TestMethod]
public void DisplayNameTest()
{
// Setup
var provider = new TimeDateCommandsProvider();
// Act
var displayName = provider.DisplayName;
// Assert
Assert.IsFalse(string.IsNullOrEmpty(displayName));
}
[TestMethod]
public void GetTranslatedPluginDescriptionTest()
{
// Setup
var provider = new TimeDateCommandsProvider();
// Act
var commands = provider.TopLevelCommands();
var subtitle = commands[0].Subtitle;
// Assert
Assert.IsFalse(string.IsNullOrEmpty(subtitle));
Assert.IsTrue(subtitle.Contains("Provides time and date values in different formats"));
}
}
}

View File

@@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Look at Directory.Build.props in root for common stuff as well -->
<Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Microsoft.CmdPal.Ext.WindowWalker.UnitTests</RootNamespace>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal\tests\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="MSTest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\ext\Microsoft.CmdPal.Ext.WindowWalker\Microsoft.CmdPal.Ext.WindowWalker.csproj" />
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,60 +0,0 @@
// 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.Reflection;
using Microsoft.CmdPal.Ext.WindowWalker.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.CmdPal.Ext.WindowWalker.UnitTests;
[TestClass]
public class PluginSettingsTests
{
[DataTestMethod]
[DataRow("ResultsFromVisibleDesktopOnly")]
[DataRow("SubtitleShowPid")]
[DataRow("SubtitleShowDesktopName")]
[DataRow("ConfirmKillProcess")]
[DataRow("KillProcessTree")]
[DataRow("OpenAfterKillAndClose")]
[DataRow("HideKillProcessOnElevatedProcesses")]
[DataRow("HideExplorerSettingInfo")]
[DataRow("InMruOrder")]
public void DoesSettingExist(string name)
{
// Setup
Type settings = SettingsManager.Instance?.GetType();
// Act
var result = settings?.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
// Assert
Assert.IsNotNull(result);
}
[DataTestMethod]
[DataRow("ResultsFromVisibleDesktopOnly", false)]
[DataRow("SubtitleShowPid", false)]
[DataRow("SubtitleShowDesktopName", true)]
[DataRow("ConfirmKillProcess", true)]
[DataRow("KillProcessTree", false)]
[DataRow("OpenAfterKillAndClose", false)]
[DataRow("HideKillProcessOnElevatedProcesses", false)]
[DataRow("HideExplorerSettingInfo", true)]
[DataRow("InMruOrder", true)]
public void DefaultValues(string name, bool valueExpected)
{
// Setup
SettingsManager setting = SettingsManager.Instance;
// Act
PropertyInfo propertyInfo = setting?.GetType()?.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
var result = propertyInfo?.GetValue(setting);
// Assert
Assert.AreEqual(valueExpected, result);
}
}

View File

@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CmdPal.Ext.Apps.Programs;
@@ -47,19 +46,7 @@ public sealed partial class AppCache : IDisposable
UpdateUWPIconPath(ThemeHelper.GetCurrentTheme());
});
try
{
Task.WaitAll(a, b);
}
catch (AggregateException ex)
{
ManagedCommon.Logger.LogError("One or more errors occurred while indexing apps");
foreach (var inner in ex.InnerExceptions)
{
ManagedCommon.Logger.LogError(inner.Message, inner);
}
}
Task.WaitAll(a, b);
AllAppsSettings.Instance.LastIndexTime = DateTime.Today;
}
@@ -70,14 +57,7 @@ public sealed partial class AppCache : IDisposable
{
foreach (UWPApplication app in _packageRepository)
{
try
{
app.UpdateLogoPath(theme);
}
catch (Exception ex)
{
ManagedCommon.Logger.LogError($"Failed to update icon path for app {app.Name}", ex);
}
app.UpdateLogoPath(theme);
}
}
}

View File

@@ -128,6 +128,14 @@ public partial class UWP
public static UWPApplication[] All()
{
var windows10 = new Version(10, 0);
var support = Environment.OSVersion.Version.Major >= windows10.Major;
if (!support)
{
return Array.Empty<UWPApplication>();
}
var appsBag = new ConcurrentBag<UWPApplication>();
Parallel.ForEach(CurrentUserPackages(), p =>

View File

@@ -115,7 +115,11 @@ internal sealed partial class PackageRepository : ListRepository<UWPApplication>
public void IndexPrograms()
{
var applications = UWP.All();
var windows10 = new Version(10, 0);
var support = Environment.OSVersion.Version.Major >= windows10.Major;
var applications = support ? Programs.UWP.All() : Array.Empty<UWPApplication>();
SetList(applications);
}
}

View File

@@ -267,7 +267,8 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
public void IndexPrograms()
{
var applications = Win32Program.All(_settings);
var applications = Programs.Win32Program.All(_settings);
SetList(applications);
}
}

View File

@@ -10,13 +10,6 @@
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
<ProjectPriFileName>Microsoft.CmdPal.Ext.Registry.pri</ProjectPriFileName>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.CmdPal.Ext.Registry.UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.ServiceProcess.ServiceController" />
</ItemGroup>

View File

@@ -33,9 +33,4 @@
<CustomToolNamespace>Microsoft.CmdPal.Ext.System</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.CmdPal.Ext.System.UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>

View File

@@ -17,16 +17,13 @@ internal sealed partial class FallbackTimeDateItem : FallbackCommandItem
{
private readonly HashSet<string> _validOptions;
private SettingsManager _settingsManager;
private DateTime? _timestamp;
public FallbackTimeDateItem(SettingsManager settings, DateTime? timestamp = null)
public FallbackTimeDateItem(SettingsManager settings)
: base(new NoOpCommand(), Resources.Microsoft_plugin_timedate_fallback_display_title)
{
Title = string.Empty;
Subtitle = string.Empty;
_settingsManager = settings;
_timestamp = timestamp;
_validOptions = new(StringComparer.OrdinalIgnoreCase)
{
Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagDate", CultureInfo.CurrentCulture),
@@ -52,7 +49,7 @@ internal sealed partial class FallbackTimeDateItem : FallbackCommandItem
return;
}
var availableResults = AvailableResultsList.GetList(false, _settingsManager, timestamp: _timestamp);
var availableResults = AvailableResultsList.GetList(false, _settingsManager);
ListItem result = null;
var maxScore = 0;

View File

@@ -298,7 +298,6 @@ internal static class TimeAndDateHelper
}
else
{
inputParsingErrorMsg = Resources.Microsoft_plugin_timedate_InvalidInput_ErrorMessageTitle;
timestamp = new DateTime(1, 1, 1, 1, 1, 1);
Logger.LogWarning($"Failed to parse input: '{input}'. Format not recognized.");
return false;

View File

@@ -11,12 +11,6 @@
<ProjectPriFileName>Microsoft.CmdPal.Ext.TimeDate.pri</ProjectPriFileName>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.CmdPal.Ext.TimeDate.UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@@ -46,9 +46,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.CmdPal.Ext.WindowWalker.UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -17,24 +17,27 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_2_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_4_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_5_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_6_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_7_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_8_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_2_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_4_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_5_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_6_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_7_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_8_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_2_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_4_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_5_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_6_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_7_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestSingleFilePreview_8_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_2_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_3_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_4_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_5_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_6_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_7_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_8_arm64.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_2_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_3_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_4_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_5_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_6_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_7_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_8_x64Win11.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_2_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_3_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_4_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_5_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_6_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_7_x64Win10.png" />
<EmbeddedResource Include="Baseline\PeekFilePreviewTests_TestFilePreviewWithVisualComparison_8_x64Win10.png" />
</ItemGroup>
<ItemGroup>
<Content Include="TestAssets\**\*">

View File

@@ -3,13 +3,10 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -39,7 +36,25 @@ public class PeekFilePreviewTests : UITestBase
public void TestInitialize()
{
Session.CloseMainWindow();
SendKeys(Key.Win, Key.M);
SendKeys(Key.Win, Key.D);
}
[TestCleanup]
public void PeekTestCleanup()
{
try
{
// Ensure all test resources are cleaned up
ClosePeekAndExplorer();
// Force garbage collection to help with resource cleanup
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch (Exception ex)
{
Debug.WriteLine($"TestCleanup failed: {ex.Message}");
}
}
[TestMethod("Peek.FilePreview.Folder")]
@@ -58,81 +73,28 @@ public class PeekFilePreviewTests : UITestBase
}
/// <summary>
/// Test JPEG image preview
/// Comprehensive test for all files in TestAssets with visual comparison
/// Tests all supported file types and validates preview rendering with image comparison
/// </summary>
[TestMethod("Peek.FilePreview.JPEGImage")]
[TestMethod("Peek.FilePreview.AllTestAssets")]
[TestCategory("Preview files")]
public void PeekJPEGImagePreview()
public void PeekAllTestAssets()
{
string imagePath = Path.GetFullPath(@".\TestAssets\2.jpg");
TestSingleFilePreview(imagePath, "2");
}
// Get all test asset files
var testFiles = GetTestAssetFiles();
/// <summary>
/// Test PDF document preview
/// ToDo: need to open settings to enable PDF preview in Peek
/// </summary>
// [TestMethod("Peek.FilePreview.PDFDocument")]
// [TestCategory("Preview files")]
// public void PeekPDFDocumentPreview()
// {
// string pdfPath = Path.GetFullPath(@".\TestAssets\3.pdf");
// TestSingleFilePreview(pdfPath, "3", 10000);
// }
Assert.IsTrue(testFiles.Count > 0, "Should have test files in TestAssets folder");
/// <summary>
/// Test QOI image preview
/// </summary>
[TestMethod("Peek.FilePreview.QOIImage")]
[TestCategory("Preview files")]
public void PeekQOIImagePreview()
{
string qoiPath = Path.GetFullPath(@".\TestAssets\4.qoi");
TestSingleFilePreview(qoiPath, "4");
}
// Test each file individually with visual comparison
foreach (var testFile in testFiles)
{
string fileName = Path.GetFileName(testFile);
string fileExtension = Path.GetExtension(testFile).ToLowerInvariant();
/// <summary>
/// Test C++ source code preview
/// </summary>
[TestMethod("Peek.FilePreview.CPPSourceCode")]
[TestCategory("Preview files")]
public void PeekCPPSourceCodePreview()
{
string cppPath = Path.GetFullPath(@".\TestAssets\5.cpp");
TestSingleFilePreview(cppPath, "5");
}
TestFilePreviewWithVisualComparison(testFile);
}
/// <summary>
/// Test Markdown document preview
/// </summary>
[TestMethod("Peek.FilePreview.MarkdownDocument")]
[TestCategory("Preview files")]
public void PeekMarkdownDocumentPreview()
{
string markdownPath = Path.GetFullPath(@".\TestAssets\6.md");
TestSingleFilePreview(markdownPath, "6");
}
/// <summary>
/// Test ZIP archive preview
/// </summary>
[TestMethod("Peek.FilePreview.ZIPArchive")]
[TestCategory("Preview files")]
public void PeekZIPArchivePreview()
{
string zipPath = Path.GetFullPath(@".\TestAssets\7.zip");
TestSingleFilePreview(zipPath, "7");
}
/// <summary>
/// Test PNG image preview
/// </summary>
[TestMethod("Peek.FilePreview.PNGImage")]
[TestCategory("Preview files")]
public void PeekPNGImagePreview()
{
string pngPath = Path.GetFullPath(@".\TestAssets\8.png");
TestSingleFilePreview(pngPath, "8");
// Assert.Fail("All test files should be processed without failure. If this fails, check the TestAssets folder for missing or unsupported files.");
}
/// <summary>
@@ -488,8 +450,6 @@ public class PeekFilePreviewTests : UITestBase
{
"7.zip - File Explorer",
"7 - File Explorer",
"7",
"7.zip",
};
foreach (var title in possibleTitles)
@@ -700,38 +660,19 @@ public class PeekFilePreviewTests : UITestBase
}
}
/// <summary>
/// Test a single file preview with visual comparison
/// </summary>
/// <param name="filePath">Full path to the file to test</param>
/// <param name="expectedFileName">Expected file name for visual comparison</param>
private void TestSingleFilePreview(string filePath, string expectedFileName, int? delayMs = 5000)
private void TestFilePreviewWithVisualComparison(string filePath)
{
Element? previewWindow = null;
string fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
try
{
Debug.WriteLine($"Testing file preview: {Path.GetFileName(filePath)}");
Element previewWindow = OpenPeekWindow(filePath);
previewWindow = OpenPeekWindow(filePath);
Assert.IsNotNull(previewWindow, $"Should open Peek window for {fileNameWithoutExt}");
if (delayMs.HasValue)
{
Thread.Sleep(delayMs.Value); // Allow time for the preview to load
}
// previewWindow.SaveToPngFile(Path.Combine(ScreenshotDirectory ?? string.Empty, $"{fileNameWithoutExt}.png"));
VisualAssert.AreEqual(TestContext, previewWindow, fileNameWithoutExt );
Assert.IsNotNull(previewWindow, $"Should open Peek window for {Path.GetFileName(filePath)}");
// Perform visual comparison
VisualAssert.AreEqual(TestContext, previewWindow, expectedFileName);
Debug.WriteLine($"Successfully tested: {Path.GetFileName(filePath)}");
}
finally
{
// Always cleanup in finally block
ClosePeekAndExplorer();
}
// Close peek window
ClosePeekAndExplorer();
}
private Rectangle GetWindowBounds(Element window)
@@ -772,13 +713,51 @@ public class PeekFilePreviewTests : UITestBase
{
// Close Peek window
Session.CloseMainWindow();
Thread.Sleep(500);
SendKeys(Key.Win, Key.M);
Thread.Sleep(500); // Wait for window to close
}
catch (Exception ex)
{
Debug.WriteLine($"Error closing Peek window: {ex.Message}");
}
// Close all Explorer windows that have a main window handle
try
{
// Get all explorer processes that have a window (HasWindow=True)
var explorerProcesses = Process.GetProcessesByName("explorer")
.Where(p => p.MainWindowHandle != IntPtr.Zero)
.ToList();
foreach (var explorer in explorerProcesses)
{
try
{
explorer.CloseMainWindow();
// Give time for the window to close before continuing
Thread.Sleep(500);
// Force kill if still running after graceful close
if (!explorer.HasExited)
{
explorer.Kill();
explorer.WaitForExit(2000); // Wait up to 2 seconds for exit
}
}
catch (Exception ex)
{
Debug.WriteLine($"Error closing Explorer process {explorer.Id}: {ex.Message}");
}
finally
{
explorer.Dispose();
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"Error during Explorer cleanup: {ex.Message}");
}
}
/// <summary>

Binary file not shown.

View File

@@ -4,74 +4,46 @@ Build and package PowerToys (CmdPal and installer) for a specific platform and c
.DESCRIPTION
This script automates the end-to-end build and packaging process for PowerToys, including:
- Restoring and building all necessary solutions (CmdPal, BugReportTool, etc.)
- Restoring and building all necessary solutions (CmdPal, BugReportTool, StylesReportTool, etc.)
- Cleaning up old output
- Signing generated .msix packages
- Building the WiX-based MSI and bootstrapper installers
It is designed to work in local development.
The cert used to sign the packages is generated by
.PARAMETER Platform
Specifies the target platform for the build (e.g., 'arm64', 'x64'). Default is 'x64'.
Specifies the target platform for the build (e.g., 'arm64', 'x64'). Default is 'arm64'.
.PARAMETER Configuration
Specifies the build configuration (e.g., 'Debug', 'Release'). Default is 'Release'.
.PARAMETER PerUser
Specifies whether to build a per-user installer (true) or machine-wide installer (false). Default is true (per-user).
.EXAMPLE
.\build-installer.ps1
Runs the installer build pipeline for ARM64 Release (default).
.EXAMPLE
.\build-installer.ps1 -Platform x64 -Configuration Release
Runs the pipeline for x64 Release.
.EXAMPLE
.\build-installer.ps1 -Platform x64 -Configuration Release -PerUser false
Runs the pipeline for x64 Release with machine-wide installer.
Runs the pipeline for x64 Debug.
.NOTES
- Requires MSBuild, WiX Toolset, and Git to be installed and accessible from your environment.
- Make sure to run this script from a Developer PowerShell (e.g., VS2022 Developer PowerShell).
- Generated MSIX files will be signed using cert-sign-package.ps1.
- This script will clean previous outputs under the build directories and installer directory (except *.exe files).
- First time run need admin permission to trust the certificate.
- The built installer will be placed under: installer/PowerToysSetup/[Platform]/[Configuration]/User[Machine]Setup
- The built installer will be placed under: installer/PowerToysSetup/[Platform]/[Configuration]/UserSetup
relative to the solution root directory.
- To run the full installation in other machines, call "./cert-management.ps1" to export the cert used to sign the packages.
And trust the cert in the target machine.
- The installer can't be run right after the build, I need to copy it to another file before it can be run.
#>
param (
[string]$Platform = 'x64',
[string]$Configuration = 'Release',
[string]$PerUser = 'true'
[string]$Platform = 'arm64',
[string]$Configuration = 'Release'
)
# Find the PowerToys repository root automatically
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$repoRoot = $scriptDir
# Navigate up from the script location to find the repo root
# Script is typically in tools\build, so go up two levels
while ($repoRoot -and -not (Test-Path (Join-Path $repoRoot "PowerToys.sln"))) {
$parentDir = Split-Path -Parent $repoRoot
if ($parentDir -eq $repoRoot) {
# Reached the root of the drive, PowerToys.sln not found
Write-Error "Could not find PowerToys repository root. Make sure this script is in the PowerToys repository."
exit 1
}
$repoRoot = $parentDir
}
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot "PowerToys.sln"))) {
Write-Error "Could not locate PowerToys.sln. Please ensure this script is run from within the PowerToys repository."
exit 1
}
Write-Host "PowerToys repository root detected: $repoRoot"
$repoRoot = Resolve-Path "$PSScriptRoot\..\.."
Set-Location $repoRoot
function RunMSBuild {
param (
@@ -83,7 +55,6 @@ function RunMSBuild {
$Solution
"/p:Platform=`"$Platform`""
"/p:Configuration=$Configuration"
"/p:CIBuild=true"
'/verbosity:normal'
'/clp:Summary;PerformanceSummary;ErrorsOnly;WarningsOnly'
'/nologo'
@@ -91,18 +62,13 @@ function RunMSBuild {
$cmd = $base + ($ExtraArgs -split ' ')
Write-Host ("[MSBUILD] {0} {1}" -f $Solution, ($cmd -join ' '))
# Run MSBuild from the repository root directory
Push-Location $repoRoot
try {
& msbuild.exe @cmd
if ($LASTEXITCODE -ne 0) {
Write-Error ("Build failed: {0} {1}" -f $Solution, $ExtraArgs)
exit $LASTEXITCODE
}
} finally {
Pop-Location
& msbuild.exe @cmd
if ($LASTEXITCODE -ne 0) {
Write-Error ("Build failed: {0} {1}" -f $Solution, $ExtraArgs)
exit $LASTEXITCODE
}
}
function RestoreThenBuild {
@@ -115,9 +81,9 @@ function RestoreThenBuild {
}
Write-Host ("Make sure wix is installed and available")
& (Join-Path $PSScriptRoot "ensure-wix.ps1")
& "$PSScriptRoot\ensure-wix.ps1"
Write-Host ("[PIPELINE] Start | Platform={0} Configuration={1} PerUser={2}" -f $Platform, $Configuration, $PerUser)
Write-Host ("[PIPELINE] Start | Platform={0} Configuration={1}" -f $Platform, $Configuration)
Write-Host ''
$cmdpalOutputPath = Join-Path $repoRoot "$Platform\$Configuration\WinUI3Apps\CmdPal"
@@ -127,7 +93,7 @@ if (Test-Path $cmdpalOutputPath) {
Remove-Item $cmdpalOutputPath -Recurse -Force -ErrorAction Ignore
}
RestoreThenBuild 'PowerToys.sln'
RestoreThenBuild '.\PowerToys.sln'
$msixSearchRoot = Join-Path $repoRoot "$Platform\$Configuration"
$msixFiles = Get-ChildItem -Path $msixSearchRoot -Recurse -Filter *.msix |
@@ -135,27 +101,22 @@ Select-Object -ExpandProperty FullName
if ($msixFiles.Count) {
Write-Host ("[SIGN] .msix file(s): {0}" -f ($msixFiles -join '; '))
& (Join-Path $PSScriptRoot "cert-sign-package.ps1") -TargetPaths $msixFiles
& "$PSScriptRoot\cert-sign-package.ps1" -TargetPaths $msixFiles
}
else {
Write-Warning "[SIGN] No .msix files found in $msixSearchRoot"
}
RestoreThenBuild 'tools\BugReportTool\BugReportTool.sln'
RestoreThenBuild 'tools\StylesReportTool\StylesReportTool.sln'
RestoreThenBuild '.\tools\BugReportTool\BugReportTool.sln'
RestoreThenBuild '.\tools\StylesReportTool\StylesReportTool.sln'
Write-Host '[CLEAN] installer (keep *.exe)'
Push-Location $repoRoot
try {
git clean -xfd -e '*.exe' -- .\installer\ | Out-Null
} finally {
Pop-Location
}
git clean -xfd -e '*.exe' -- .\installer\ | Out-Null
RunMSBuild 'installer\PowerToysSetup.sln' '/t:restore /p:RestorePackagesConfig=true'
RunMSBuild '.\installer\PowerToysSetup.sln' '/t:restore /p:RestorePackagesConfig=true'
RunMSBuild 'installer\PowerToysSetup.sln' "/m /t:PowerToysInstaller /p:PerUser=$PerUser"
RunMSBuild '.\installer\PowerToysSetup.sln' '/m /t:PowerToysInstaller /p:PerUser=true'
RunMSBuild 'installer\PowerToysSetup.sln' "/m /t:PowerToysBootstrapper /p:PerUser=$PerUser"
RunMSBuild '.\installer\PowerToysSetup.sln' '/m /t:PowerToysBootstrapper /p:PerUser=true'
Write-Host '[PIPELINE] Completed'

View File

@@ -152,37 +152,4 @@ function Export-CertificateFiles {
if (-not $CerPath -and -not $PfxPath) {
Write-Warning "No output path specified. Nothing was exported."
}
}
# Main execution when script is run directly
if ($MyInvocation.InvocationName -ne '.') {
Write-Host "=== PowerToys Certificate Management ===" -ForegroundColor Green
Write-Host ""
# Ensure certificate exists and is trusted
Write-Host "Checking for existing certificate or creating new one..." -ForegroundColor Yellow
$cert = EnsureCertificate
if ($cert) {
# Export the certificate to a .cer file
$exportPath = Join-Path (Get-Location) "PowerToys-CodeSigning.cer"
Write-Host ""
Write-Host "Exporting certificate..." -ForegroundColor Yellow
Export-CertificateFiles -Certificate $cert -CerPath $exportPath
Write-Host ""
Write-Host "=== IMPORTANT NOTES ===" -ForegroundColor Red
Write-Host "The certificate has been exported to: $exportPath" -ForegroundColor White
Write-Host ""
Write-Host "To use this certificate for code signing, you need to:" -ForegroundColor Yellow
Write-Host "1. Import this certificate into 'Trusted People' store" -ForegroundColor White
Write-Host "2. Import this certificate into 'Trusted Root Certification Authorities' store" -ForegroundColor White
Write-Host "Certificate Details:" -ForegroundColor Green
Write-Host "Subject: $($cert.Subject)" -ForegroundColor White
Write-Host "Thumbprint: $($cert.Thumbprint)" -ForegroundColor White
Write-Host "Valid Until: $($cert.NotAfter)" -ForegroundColor White
} else {
Write-Error "Failed to create or find certificate. Please check the error messages above."
exit 1
}
}