2020-08-12 11:46:11 -07:00
// 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 ;
2020-07-09 13:14:53 -07:00
using System.Collections.Generic ;
using System.Linq ;
2020-08-12 11:46:11 -07:00
using Moq ;
using NUnit.Framework ;
2020-07-09 13:14:53 -07:00
using Wox.Infrastructure ;
using Wox.Plugin ;
namespace Microsoft.Plugin.Program.UnitTests.Programs
{
2020-08-11 09:08:44 -07:00
using Win32Program = Microsoft . Plugin . Program . Programs . Win32Program ;
2020-07-09 13:14:53 -07:00
[TestFixture]
2020-07-07 15:00:17 -07:00
public class Win32Tests
2020-07-09 13:14:53 -07:00
{
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _notepadAppdata = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _notepadUsers = new Win32Program
2020-07-09 13:14:53 -07:00
{
Name = "Notepad" ,
ExecutableName = "notepad.exe" ,
FullPath = "c:\\windows\\system32\\notepad.exe" ,
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _azureCommandPrompt = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _visualStudioCommandPrompt = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _commandPrompt = new Win32Program
2020-07-09 13:14:53 -07:00
{
Name = "Command Prompt" ,
ExecutableName = "cmd.exe" ,
FullPath = "c:\\windows\\system32\\cmd.exe" ,
2020-07-22 13:27:17 -07:00
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _fileExplorer = new Win32Program
2020-07-09 13:14:53 -07:00
{
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 ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _wordpad = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _wordpadDuplicate = new Win32Program
2020-07-09 13:14:53 -07:00
{
Name = "WORDPAD" ,
ExecutableName = "WORDPAD.EXE" ,
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe" ,
LnkResolvedPath = null ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _twitterChromePwa = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 0 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _pinnedWebpage = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 0 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _edgeNamedPinnedWebpage = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 0 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _msedge = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _chrome = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _dummyProxyApp = new Win32Program
2020-07-09 13:14:53 -07:00
{
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" ,
2020-08-12 11:46:11 -07:00
AppType = 2 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _cmdRunCommand = new Win32Program
2020-07-09 13:14:53 -07:00
{
Name = "cmd" ,
ExecutableName = "cmd.exe" ,
FullPath = "c:\\windows\\system32\\cmd.exe" ,
LnkResolvedPath = null ,
2020-08-12 11:46:11 -07:00
AppType = 3 , // Run command
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _cmderRunCommand = new Win32Program
2020-07-09 13:14:53 -07:00
{
Name = "Cmder" ,
Description = "Cmder: Lovely Console Emulator" ,
ExecutableName = "Cmder.exe" ,
FullPath = "c:\\tools\\cmder\\cmder.exe" ,
LnkResolvedPath = null ,
2020-08-12 11:46:11 -07:00
AppType = 3 , // Run command
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _dummyInternetShortcutApp = new Win32Program
2020-07-09 13:14:53 -07:00
{
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 ,
2020-08-12 11:46:11 -07:00
AppType = 1 ,
2020-07-09 13:14:53 -07:00
} ;
2020-08-13 15:31:32 -07:00
private static readonly Win32Program _dummyInternetShortcutAppDuplicate = new Win32Program
2020-07-09 13:14:53 -07:00
{
Name = "Shop Titans" ,
ExecutableName = "Shop Titans.url" ,
FullPath = "steam://rungameid/1258080" ,
ParentDirectory = "C:\\Users\\temp\\Desktop" ,
LnkResolvedPath = null ,
2020-08-12 11:46:11 -07:00
AppType = 1 ,
2020-07-09 13:14:53 -07:00
} ;
[Test]
2020-08-12 10:03:34 -07:00
public void DedupFunctionWhenCalledMustRemoveDuplicateNotepads ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
2020-08-13 11:10:55 -07:00
List < Win32Program > prgms = new List < Win32Program >
{
2020-08-13 15:31:32 -07:00
_notepadAppdata ,
_notepadUsers ,
2020-08-13 11:10:55 -07:00
} ;
2020-07-09 13:14:53 -07:00
// Act
2020-08-11 09:08:44 -07:00
Win32Program [ ] apps = Win32Program . DeduplicatePrograms ( prgms . AsParallel ( ) ) ;
2020-07-09 13:14:53 -07:00
// Assert
Assert . AreEqual ( apps . Length , 1 ) ;
}
[Test]
2020-08-12 10:03:34 -07:00
public void DedupFunctionWhenCalledMustRemoveInternetShortcuts ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
2020-08-13 11:10:55 -07:00
List < Win32Program > prgms = new List < Win32Program >
{
2020-08-13 15:31:32 -07:00
_dummyInternetShortcutApp ,
_dummyInternetShortcutAppDuplicate ,
2020-08-13 11:10:55 -07:00
} ;
2020-07-09 13:14:53 -07:00
// Act
2020-08-11 09:08:44 -07:00
Win32Program [ ] apps = Win32Program . DeduplicatePrograms ( prgms . AsParallel ( ) ) ;
2020-07-09 13:14:53 -07:00
// Assert
Assert . AreEqual ( apps . Length , 1 ) ;
}
[Test]
2020-08-12 10:03:34 -07:00
public void DedupFunctionWhenCalledMustNotRemovelnkWhichdoesNotHaveExe ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
2020-08-13 11:10:55 -07:00
List < Win32Program > prgms = new List < Win32Program >
{
2020-08-13 15:31:32 -07:00
_fileExplorer ,
2020-08-13 11:10:55 -07:00
} ;
2020-07-09 13:14:53 -07:00
// Act
2020-08-11 09:08:44 -07:00
Win32Program [ ] apps = Win32Program . DeduplicatePrograms ( prgms . AsParallel ( ) ) ;
2020-07-09 13:14:53 -07:00
// Assert
Assert . AreEqual ( apps . Length , 1 ) ;
}
[Test]
2020-08-12 10:03:34 -07:00
public void DedupFunctionMustRemoveDuplicatesForExeExtensionsWithoutLnkResolvedPath ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
2020-08-13 11:10:55 -07:00
List < Win32Program > prgms = new List < Win32Program >
{
2020-08-13 15:31:32 -07:00
_wordpad ,
_wordpadDuplicate ,
2020-08-13 11:10:55 -07:00
} ;
2020-07-09 13:14:53 -07:00
// Act
2020-08-11 09:08:44 -07:00
Win32Program [ ] apps = Win32Program . DeduplicatePrograms ( prgms . AsParallel ( ) ) ;
2020-07-09 13:14:53 -07:00
// Assert
Assert . AreEqual ( apps . Length , 1 ) ;
Assert . IsTrue ( ! string . IsNullOrEmpty ( apps [ 0 ] . LnkResolvedPath ) ) ;
}
[Test]
2020-08-12 10:03:34 -07:00
public void DedupFunctionMustNotRemoveProgramsWithSameExeNameAndFullPath ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
2020-08-13 11:10:55 -07:00
List < Win32Program > prgms = new List < Win32Program >
{
2020-08-13 15:31:32 -07:00
_azureCommandPrompt ,
_visualStudioCommandPrompt ,
_commandPrompt ,
2020-08-13 11:10:55 -07:00
} ;
2020-07-09 13:14:53 -07:00
// Act
2020-08-11 09:08:44 -07:00
Win32Program [ ] apps = Win32Program . DeduplicatePrograms ( prgms . AsParallel ( ) ) ;
2020-07-09 13:14:53 -07:00
// Assert
Assert . AreEqual ( apps . Length , 3 ) ;
}
[Test]
2020-08-12 10:03:34 -07:00
public void FunctionIsWebApplicationShouldReturnTrueForWebApplications ( )
2020-07-09 13:14:53 -07:00
{
// The IsWebApplication(() function must return true for all PWAs and pinned web pages
2020-08-13 15:31:32 -07:00
Assert . IsTrue ( _twitterChromePwa . IsWebApplication ( ) ) ;
Assert . IsTrue ( _pinnedWebpage . IsWebApplication ( ) ) ;
Assert . IsTrue ( _edgeNamedPinnedWebpage . IsWebApplication ( ) ) ;
2020-07-09 13:14:53 -07:00
// Should not filter apps whose executable name ends with proxy.exe
2020-08-13 15:31:32 -07:00
Assert . IsFalse ( _dummyProxyApp . IsWebApplication ( ) ) ;
2020-07-09 13:14:53 -07:00
}
[TestCase("ignore")]
2020-08-12 10:03:34 -07:00
public void FunctionFilterWebApplicationShouldReturnFalseWhenSearchingForTheMainApp ( string query )
2020-07-09 13:14:53 -07:00
{
// Irrespective of the query, the FilterWebApplication() Function must not filter main apps such as edge and chrome
2020-08-13 15:31:32 -07:00
Assert . IsFalse ( _msedge . FilterWebApplication ( query ) ) ;
Assert . IsFalse ( _chrome . FilterWebApplication ( query ) ) ;
2020-07-09 13:14:53 -07:00
}
[TestCase("edge", ExpectedResult = true)]
[TestCase("EDGE", ExpectedResult = true)]
[TestCase("msedge", ExpectedResult = true)]
[TestCase("Microsoft", ExpectedResult = true)]
[TestCase("edg", ExpectedResult = true)]
[TestCase("Edge page", ExpectedResult = false)]
[TestCase("Edge Web page", ExpectedResult = false)]
2020-08-12 10:03:34 -07:00
public bool EdgeWebSitesShouldBeFilteredWhenSearchingForEdge ( string query )
2020-07-09 13:14:53 -07:00
{
2020-08-13 15:31:32 -07:00
return _pinnedWebpage . FilterWebApplication ( query ) ;
2020-07-09 13:14:53 -07:00
}
[TestCase("chrome", ExpectedResult = true)]
[TestCase("CHROME", ExpectedResult = true)]
[TestCase("Google", ExpectedResult = true)]
[TestCase("Google Chrome", ExpectedResult = true)]
[TestCase("Google Chrome twitter", ExpectedResult = false)]
2020-08-12 10:03:34 -07:00
public bool ChromeWebSitesShouldBeFilteredWhenSearchingForChrome ( string query )
2020-07-09 13:14:53 -07:00
{
2020-08-13 15:31:32 -07:00
return _twitterChromePwa . FilterWebApplication ( query ) ;
2020-07-09 13:14:53 -07:00
}
[TestCase("twitter", 0, ExpectedResult = false)]
[TestCase("Twit", 0, ExpectedResult = false)]
[TestCase("TWITTER", 0, ExpectedResult = false)]
[TestCase("web", 1, ExpectedResult = false)]
[TestCase("Page", 1, ExpectedResult = false)]
[TestCase("WEB PAGE", 1, ExpectedResult = false)]
[TestCase("edge", 2, ExpectedResult = false)]
[TestCase("EDGE", 2, ExpectedResult = false)]
2020-08-13 15:31:32 -07:00
public bool PinnedWebPagesShouldNotBeFilteredWhenSearchingForThem ( string query , int scenario )
2020-07-09 13:14:53 -07:00
{
2020-08-13 15:31:32 -07:00
const int CASE_TWITTER = 0 ;
const int CASE_WEB_PAGE = 1 ;
const int CASE_EDGE_NAMED_WEBPAGE = 2 ;
2020-07-09 13:14:53 -07:00
// If the query is a part of the name of the web application, it should not be filtered,
// even if the name is the same as that of the main application, eg: case 2 - edge
2020-08-13 15:31:32 -07:00
switch ( scenario )
2020-07-09 13:14:53 -07:00
{
2020-08-13 15:31:32 -07:00
case CASE_TWITTER :
return _twitterChromePwa . FilterWebApplication ( query ) ;
case CASE_WEB_PAGE :
return _pinnedWebpage . FilterWebApplication ( query ) ;
case CASE_EDGE_NAMED_WEBPAGE :
return _edgeNamedPinnedWebpage . FilterWebApplication ( query ) ;
default :
break ;
2020-07-09 13:14:53 -07:00
}
2020-08-13 11:10:55 -07:00
2020-07-09 13:14:53 -07:00
// unreachable code
return true ;
}
[TestCase("Command Prompt")]
[TestCase("cmd")]
[TestCase("cmd.exe")]
[TestCase("ignoreQueryText")]
2020-08-12 10:03:34 -07:00
public void Win32ApplicationsShouldNotBeFilteredWhenFilteringRunCommands ( string query )
2020-07-09 13:14:53 -07:00
{
// Even if there is an exact match in the name or exe name, win32 applications should never be filtered
2020-08-13 15:31:32 -07:00
Assert . IsTrue ( _commandPrompt . QueryEqualsNameForRunCommands ( query ) ) ;
2020-07-09 13:14:53 -07:00
}
[TestCase("cmd")]
[TestCase("Cmd")]
[TestCase("CMD")]
2020-08-12 10:03:34 -07:00
public void RunCommandsShouldNotBeFilteredOnExactMatch ( string query )
2020-07-09 13:14:53 -07:00
{
// Partial matches should be filtered as cmd is not equal to cmder
2020-08-13 15:31:32 -07:00
Assert . IsFalse ( _cmderRunCommand . QueryEqualsNameForRunCommands ( query ) ) ;
2020-07-09 13:14:53 -07:00
// the query matches the name (cmd) and is therefore not filtered (case-insensitive)
2020-08-13 15:31:32 -07:00
Assert . IsTrue ( _cmdRunCommand . QueryEqualsNameForRunCommands ( query ) ) ;
2020-07-09 13:14:53 -07:00
}
[Test]
2020-08-12 10:03:34 -07:00
public void WebApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
var mock = new Mock < IPublicAPI > ( ) ;
mock . Setup ( x = > x . GetTranslation ( It . IsAny < string > ( ) ) ) . Returns ( It . IsAny < string > ( ) ) ;
// Act
2020-08-13 15:31:32 -07:00
List < ContextMenuResult > contextMenuResults = _pinnedWebpage . ContextMenus ( mock . Object ) ;
2020-07-09 13:14:53 -07:00
// 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]
2020-08-12 10:03:34 -07:00
public void InternetShortcutApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
var mock = new Mock < IPublicAPI > ( ) ;
mock . Setup ( x = > x . GetTranslation ( It . IsAny < string > ( ) ) ) . Returns ( It . IsAny < string > ( ) ) ;
// Act
2020-08-13 15:31:32 -07:00
List < ContextMenuResult > contextMenuResults = _dummyInternetShortcutApp . ContextMenus ( mock . Object ) ;
2020-07-09 13:14:53 -07:00
// 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]
2020-08-12 10:03:34 -07:00
public void Win32ApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
var mock = new Mock < IPublicAPI > ( ) ;
mock . Setup ( x = > x . GetTranslation ( It . IsAny < string > ( ) ) ) . Returns ( It . IsAny < string > ( ) ) ;
// Act
2020-08-13 15:31:32 -07:00
List < ContextMenuResult > contextMenuResults = _chrome . ContextMenus ( mock . Object ) ;
2020-07-09 13:14:53 -07:00
// 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]
2020-08-12 10:03:34 -07:00
public void RunCommandShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled ( )
2020-07-09 13:14:53 -07:00
{
// Arrange
var mock = new Mock < IPublicAPI > ( ) ;
mock . Setup ( x = > x . GetTranslation ( It . IsAny < string > ( ) ) ) . Returns ( It . IsAny < string > ( ) ) ;
// Act
2020-08-13 15:31:32 -07:00
List < ContextMenuResult > contextMenuResults = _cmdRunCommand . ContextMenus ( mock . Object ) ;
2020-07-09 13:14:53 -07:00
// 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]
2020-08-12 10:03:34 -07:00
public void Win32AppsShouldSetNameAsTitleWhileCreatingResult ( )
2020-07-09 13:14:53 -07:00
{
var mock = new Mock < IPublicAPI > ( ) ;
mock . Setup ( x = > x . GetTranslation ( It . IsAny < string > ( ) ) ) . Returns ( It . IsAny < string > ( ) ) ;
StringMatcher . Instance = new StringMatcher ( ) ;
// Act
2020-08-13 15:31:32 -07:00
var result = _cmderRunCommand . Result ( "cmder" , mock . Object ) ;
2020-07-09 13:14:53 -07:00
// Assert
2020-08-13 15:31:32 -07:00
Assert . IsTrue ( result . Title . Equals ( _cmderRunCommand . Name , StringComparison . Ordinal ) ) ;
Assert . IsFalse ( result . Title . Equals ( _cmderRunCommand . Description , StringComparison . Ordinal ) ) ;
2020-07-09 13:14:53 -07:00
}
}
}