[Run] Open in console functionality (#4739)

* Added open in console for indexer

* Added open in console fpr indexer and folder plugin

* Added open in console to program plugin

* Added string localization for program plugin

* Added test for win32 program

* Added test for win32 programs

* Added test for indexer plugin

* Localization for context menu title

* Added tests for folder plugin

* Added tests for indexer plugin

* Code cleanup

* Improved logging and nit fixes

* Updated tooltip for open in console

* Updates tests

* Removed subtitle property from contextmenuresult class

* Improved logging for context menu loaders
This commit is contained in:
Divyansh Srivastava 2020-07-08 09:56:26 -07:00 committed by GitHub
parent e3e6b23b7c
commit 638cd1dd48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 402 additions and 80 deletions

View File

@ -10,6 +10,7 @@ using Wox.Plugin.SharedCommands;
using Wox.Plugin;
using System.Reflection;
using System.Windows.Input;
using Wox.Infrastructure;
namespace Microsoft.Plugin.Folder
{
@ -33,14 +34,12 @@ namespace Microsoft.Plugin.Folder
}
var icoPath = (record.Type == ResultType.File) ? Main.FileImagePath : Main.FolderImagePath;
var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder";
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_folder_copy_path"),
Glyph = "\xE8C8",
FontFamily = "Segoe MDL2 Assets",
SubTitle = $"Copy the current {fileOrFolder} path to clipboard",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control,
Action = (context) =>
@ -59,6 +58,38 @@ namespace Microsoft.Plugin.Folder
}
}
});
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_folder_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
if (record.Type == ResultType.File)
{
Helper.OpenInConsole(Path.GetDirectoryName(record.FullPath));
}
else
{
Helper.OpenInConsole(record.FullPath);
}
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenuLoader.LoadContextMenus| Failed to open {record.FullPath} in console, {e.Message}", e);
return false;
}
}
});
}
return contextMenus;
@ -69,7 +100,7 @@ namespace Microsoft.Plugin.Folder
return new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = "Open containing folder",
Title = _context.API.GetTranslation("Microsoft_plugin_folder_open_containing_folder"),
Glyph = "\xE838",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.E,

View File

@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Ordner</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Öffne deine Lieblingsordner direkt von Wox aus</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Folder</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Open favorite folder from Wox directly</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Foldery</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Otwórz ulubione foldery bezpośrednio z poziomu Woxa</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Klasör</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Favori klasörünüzü doğrudan Wox'tan açın</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">文件夹</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">在Wox中直接打开收藏的文件夹</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">資料夾</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">在 Wox 中直接開啟收藏的資料夾</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@ -43,6 +43,12 @@
</None>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Wox.Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<Page Include="FolderPluginSettings.xaml">
<Generator>MSBuild:Compile</Generator>

View File

@ -8,6 +8,7 @@ using Wox.Plugin;
using Microsoft.Plugin.Indexer.SearchHelper;
using System.Windows.Input;
using System.Reflection;
using Wox.Infrastructure;
namespace Microsoft.Plugin.Indexer
{
@ -38,14 +39,12 @@ namespace Microsoft.Plugin.Indexer
contextMenus.Add(CreateOpenContainingFolderResult(record));
}
var fileOrFolder = (type == ResultType.File) ? "file" : "folder";
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_indexer_copy_path"),
Glyph = "\xE8C8",
FontFamily = "Segoe MDL2 Assets",
SubTitle = $"Copy the current {fileOrFolder} path to clipboard",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control,
@ -65,6 +64,37 @@ namespace Microsoft.Plugin.Indexer
}
}
});
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_indexer_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
if (type == ResultType.File)
{
Helper.OpenInConsole(Path.GetDirectoryName(record.Path));
}
else
{
Helper.OpenInConsole(record.Path);
}
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Indexer.ContextMenuLoader.LoadContextMenus| Failed to open {record.Path} in console, {e.Message}", e);
return false;
}
}
});
}
return contextMenus;

View File

@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@ -58,6 +58,12 @@
</None>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Wox.Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<Content Include="Languages\de.xaml">
<Generator>MSBuild:Compile</Generator>
@ -95,6 +101,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -30,6 +30,7 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Als Administrator ausführen (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">Enthaltenden Ordner öffnen (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Programm</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Suche Programme mit Wox</system:String>

View File

@ -35,6 +35,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Run As Administrator (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_disable_program">Disable this program from displaying</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Search programs in Wox</system:String>

View File

@ -31,6 +31,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Run As Administrator (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Search programs in Wox</system:String>

View File

@ -33,6 +33,7 @@
<system:String x:Key="wox_plugin_program_plugin_name">Programy</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Szukaj i uruchamiaj programy z poziomu Woxa</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<!--Application subtitle-->
<system:String x:Key="powertoys_run_plugin_program_win32_application">Application</system:String>
@ -43,4 +44,5 @@
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -30,6 +30,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Yönetici Olarak Çalıştır (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">İçeren Klasörü Aç (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Programları Wox'tan arayın</system:String>

View File

@ -30,6 +30,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理员身份运行 (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">打开所属文件夹 (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程序</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在Wox中搜索程序</system:String>

View File

@ -30,6 +30,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">以系統管理員身分執行 (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">開啟檔案位置 (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程式</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在 Wox 中搜尋程式</system:String>

View File

@ -22,6 +22,7 @@ using System.Runtime.InteropServices.ComTypes;
using Wox.Plugin.SharedCommands;
using System.Reflection;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
namespace Microsoft.Plugin.Program.Programs
{
@ -357,6 +358,29 @@ namespace Microsoft.Plugin.Program.Programs
}
});
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
Helper.OpenInConsole(Package.Location);
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Program.UWP.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false;
}
}
});
return contextMenus;
}

View File

@ -14,6 +14,7 @@ using Wox.Plugin;
using System.Windows.Input;
using System.Reflection;
using System.Text.RegularExpressions;
using Wox.Infrastructure.Logger;
namespace Microsoft.Plugin.Program.Programs
{
@ -202,32 +203,11 @@ namespace Microsoft.Plugin.Program.Programs
public List<ContextMenuResult> ContextMenus(IPublicAPI api)
{
// To add a context menu only to open file location as Internet shortcut applications do not have the functionality to run as admin
if(AppType == (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION)
{
var contextMenuItems = new List<ContextMenuResult>
{
new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_open_containing_folder"),
Glyph = "\xE838",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.E,
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
Action = _ =>
{
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true;
}
}
};
return contextMenuItems;
}
var contextMenus = new List<ContextMenuResult>();
var contextMenus = new List<ContextMenuResult>
if (AppType != (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION)
{
new ContextMenuResult
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_run_as_administrator"),
@ -249,7 +229,10 @@ namespace Microsoft.Plugin.Program.Programs
return true;
}
},
});
}
contextMenus.Add(
new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
@ -263,8 +246,32 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true;
}
}
};
});
contextMenus.Add(
new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
Helper.OpenInConsole(ParentDirectory);
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Program.Win32.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false;
}
}
});
return contextMenus;
}

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@ -74,5 +75,16 @@ namespace Wox.Infrastructure
);
return formatted;
}
public static Process OpenInConsole(string path)
{
var processStartInfo = new ProcessStartInfo
{
WorkingDirectory = path,
FileName = "cmd.exe"
};
return Process.Start(processStartInfo);
}
}
}

View File

@ -7,9 +7,8 @@ namespace Wox.Plugin
public class ContextMenuResult
{
public string PluginName { get; set; }
public string Title { get; set; }
public string SubTitle { get; set; }
public string Title { get; set; }
public string Glyph { get; set; }
@ -26,7 +25,7 @@ namespace Wox.Plugin
public override string ToString()
{
return Title + SubTitle;
return Title;
}
}
}

View File

@ -0,0 +1,54 @@
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using Wox.Plugin;
using Microsoft.Plugin.Folder;
namespace Wox.Test.Plugins
{
class FolderPluginTest
{
[Test]
public void ContextMenuLoader_ReturnContextMenuForFolderWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Type = ResultType.Folder, FullPath = "C:/DummyFolder" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 2);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_open_in_console"), Times.Once());
}
[Test]
public void ContextMenuLoader_ReturnContextMenuForFileWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Type = ResultType.File, FullPath = "C:/DummyFile.cs" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_open_in_console"), Times.Once());
}
}
}

View File

@ -8,125 +8,142 @@ using Wox.Plugin;
using Microsoft.Plugin.Program.Programs;
using Moq;
using System.IO;
using Microsoft.Plugin.Program;
using System.IO.Packaging;
using Windows.ApplicationModel;
namespace Wox.Test.Plugins
{
[TestFixture]
public class Win32Tests
{
Win32 notepad_appdata = new Win32
static Win32 notepad_appdata = new Win32
{
Name = "Notepad",
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk"
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2
};
Win32 notepad_users = new Win32
static Win32 notepad_users = new Win32
{
Name = "Notepad",
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2
};
Win32 azure_command_prompt = new Win32
static Win32 azure_command_prompt = new Win32
{
Name = "Microsoft Azure Command Prompt - v2.9",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk",
AppType = 2
};
Win32 visual_studio_command_prompt = new Win32
static Win32 visual_studio_command_prompt = new Win32
{
Name = "x64 Native Tools Command Prompt for VS 2019",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk",
AppType = 2
};
Win32 command_prompt = new Win32
static Win32 command_prompt = new Win32
{
Name = "Command Prompt",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath ="c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk"
LnkResolvedPath ="c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk",
AppType = 2
};
Win32 file_explorer = new Win32
static Win32 file_explorer = new Win32
{
Name = "File Explorer",
ExecutableName = "File Explorer.lnk",
FullPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\file explorer.lnk",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 2
};
Win32 wordpad = new Win32
static Win32 wordpad = new Win32
{
Name = "Wordpad",
ExecutableName = "wordpad.exe",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk",
AppType = 2
};
Win32 wordpad_duplicate = new Win32
static Win32 wordpad_duplicate = new Win32
{
Name = "WORDPAD",
ExecutableName = "WORDPAD.EXE",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 2
};
Win32 twitter_pwa = new Win32
static Win32 twitter_pwa = new Win32
{
Name = "Twitter",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\chrome apps\\twitter.lnk",
Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi"
Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi",
AppType = 0
};
Win32 pinned_webpage = new Win32
static Win32 pinned_webpage = new Win32
{
Name = "Web page",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\web page.lnk",
Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd"
Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd",
AppType = 0
};
Win32 edge_named_pinned_webpage = new Win32
static Win32 edge_named_pinned_webpage = new Win32
{
Name = "edge - Bing",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\edge - bing.lnk",
Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd"
Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd",
AppType = 0
};
Win32 msedge = new Win32
static Win32 msedge = new Win32
{
Name = "Microsoft Edge",
ExecutableName = "msedge.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk",
AppType = 2
};
Win32 chrome = new Win32
static Win32 chrome = new Win32
{
Name = "Google Chrome",
ExecutableName = "chrome.exe",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk",
AppType = 2
};
Win32 dummy_proxy_app = new Win32
static Win32 dummy_proxy_app = new Win32
{
Name = "Proxy App",
ExecutableName = "test_proxy.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\test_proxy.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk",
AppType = 2
};
Win32 cmd_run_command = new Win32
static Win32 cmd_run_command = new Win32
{
Name = "cmd",
ExecutableName = "cmd.exe",
@ -135,7 +152,7 @@ namespace Wox.Test.Plugins
AppType = 3 // Run command
};
Win32 cmder_run_command = new Win32
static Win32 cmder_run_command = new Win32
{
Name = "Cmder",
Description = "Cmder: Lovely Console Emulator",
@ -145,22 +162,24 @@ namespace Wox.Test.Plugins
AppType = 3 // Run command
};
Win32 dummy_internetShortcut_app = new Win32
static Win32 dummy_internetShortcut_app = new Win32
{
Name = "Shop Titans",
ExecutableName = "Shop Titans.url",
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Steam",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 1
};
Win32 dummy_internetShortcut_app_duplicate = new Win32
static Win32 dummy_internetShortcut_app_duplicate = new Win32
{
Name = "Shop Titans",
ExecutableName = "Shop Titans.url",
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\Desktop",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 1
};
[Test]
@ -336,11 +355,77 @@ namespace Wox.Test.Plugins
}
[Test]
public void Win32Apps_ShouldSetNameAsTitle_WhileCreatingResult()
public void WEB_APPLICATION_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = pinned_webpage.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("wox_plugin_program_run_as_administrator"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void INTERNET_SHORTCUT_APPLICATION_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = dummy_internetShortcut_app.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 2);
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void WIN32_APPLICATION_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = chrome.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("wox_plugin_program_run_as_administrator"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void RUN_COMMAND_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = cmd_run_command.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("wox_plugin_program_run_as_administrator"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void Win32Apps_ShouldSetNameAsTitle_WhileCreatingResult()
{
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
StringMatcher.Instance = new StringMatcher();
// Act

View File

@ -7,6 +7,8 @@ using Microsoft.Plugin.Indexer.SearchHelper;
using Microsoft.Plugin.Indexer.Interface;
using Moq;
using System.Linq;
using Microsoft.Plugin.Indexer;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
@ -214,5 +216,46 @@ namespace Wox.Test.Plugins
Assert.IsFalse(windowsSearchAPIResults.Any(x => x.Title == "file1.txt"));
Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt"));
}
[Test]
public void ContextMenuLoader_ReturnContextMenuForFolderWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Path = "C:/DummyFolder", Title = "DummyFolder" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 2);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_open_in_console"), Times.Once());
}
[Test]
public void ContextMenuLoader_ReturnContextMenuForFileWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Path = "C:/DummyFile.cs", Title = "DummyFile.cs" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_open_in_console"), Times.Once());
}
}
}

View File

@ -39,6 +39,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Plugins\Microsoft.Plugin.Folder\Microsoft.Plugin.Folder.csproj" />
<ProjectReference Include="..\Plugins\Microsoft.Plugin.Indexer\Microsoft.Plugin.Indexer.csproj" />
<ProjectReference Include="..\Plugins\Microsoft.Plugin.Program\Microsoft.Plugin.Program.csproj" />
<ProjectReference Include="..\Wox.Core\Wox.Core.csproj" />