2020-05-19 10:10:46 +00:00
using Flow.Launcher.Plugin ;
2020-05-11 13:19:41 +00:00
using Flow.Launcher.Plugin.Explorer ;
2020-05-19 10:10:46 +00:00
using Flow.Launcher.Plugin.Explorer.Search ;
2020-05-11 13:19:41 +00:00
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex ;
2020-05-24 10:14:36 +00:00
using Flow.Launcher.Plugin.SharedCommands ;
2020-05-11 13:15:15 +00:00
using NUnit.Framework ;
2020-05-11 13:19:41 +00:00
using System ;
2020-05-19 10:10:46 +00:00
using System.Collections.Generic ;
2020-05-11 13:15:15 +00:00
namespace Flow.Launcher.Test.Plugins
{
[TestFixture]
public class ExplorerTest
{
2020-05-25 08:58:28 +00:00
private List < Result > MethodWindowsIndexSearchReturnsZeroResults ( Query dummyQuery , string dummyString )
2020-05-19 10:10:46 +00:00
{
return new List < Result > ( ) ;
}
2020-05-24 10:14:36 +00:00
private List < Result > MethodDirectoryInfoClassSearchReturnsTwoResults ( Query dummyQuery , string dummyString )
2020-05-19 10:10:46 +00:00
{
return new List < Result >
{
new Result
{
Title = "Result 1"
} ,
new Result
{
Title = "Result 2"
}
} ;
}
private bool MethodIndexExistsReturnsTrue ( string dummyString ) = > true ;
private bool MethodIndexExistsReturnsFalse ( string dummyString ) = > false ;
2020-05-11 19:56:51 +00:00
[TestCase("C:\\Dropbox", "directory='file:C:\\Dropbox'")]
public void GivenWindowsIndexSearch_WhenProvidedFolderPath_ThenQueryWhereRestrictionsShouldUseDirectoryString ( string path , string expectedString )
2020-05-11 13:19:41 +00:00
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
// When
2020-05-11 19:56:51 +00:00
var folderPath = path ;
var result = queryConstructor . QueryWhereRestrictionsForTopLevelDirectorySearch ( folderPath ) ;
2020-05-11 13:19:41 +00:00
// Then
Assert . IsTrue ( result = = expectedString ,
$"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " +
$"Actual: {result}{Environment.NewLine}" ) ;
}
2020-05-11 13:15:15 +00:00
2020-05-19 08:46:42 +00:00
[TestCase("C:\\Dropbox", "SELECT TOP 100 System.FileName, System.ItemPathDisplay, System.ItemType FROM SystemIndex WHERE directory='file:C:\\Dropbox'")]
2020-05-11 20:50:17 +00:00
public void GivenWindowsIndexSearch_WhenSearchTypeIsSearchTopFolderLevel_ThenQueryShouldUseExpectedString ( string folderPath , string expectedString )
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
//When
var queryString = queryConstructor . QueryForTopLevelDirectorySearch ( folderPath ) ;
2020-05-19 10:10:46 +00:00
// Then
2020-05-11 20:50:17 +00:00
Assert . IsTrue ( queryString = = expectedString ,
2020-05-26 09:34:45 +00:00
$"Expected string: {expectedString}{Environment.NewLine} " +
2020-05-11 20:50:17 +00:00
$"Actual string was: {queryString}{Environment.NewLine}" ) ;
}
2020-05-18 10:14:38 +00:00
[TestCase("scope='file:'")]
public void GivenWindowsIndexSearch_WhenSearchAllFoldersAndFiles_ThenQueryWhereRestrictionsShouldUseScopeString ( string expectedString )
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
//When
var resultString = queryConstructor . QueryWhereRestrictionsForAllFilesAndFoldersSearch ( ) ;
2020-05-19 10:10:46 +00:00
// Then
2020-05-18 10:14:38 +00:00
Assert . IsTrue ( resultString = = expectedString ,
$"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " +
$"Actual string was: {resultString}{Environment.NewLine}" ) ;
}
2020-05-19 08:46:42 +00:00
[ TestCase ( "flow.launcher.sln" , "SELECT TOP 100 \"System.FileName\", \"System.ItemPathDisplay\", \"System.ItemType\" " +
2020-05-18 10:14:38 +00:00
"FROM \"SystemIndex\" WHERE (System.FileName LIKE 'flow.launcher.sln%' " +
"OR CONTAINS(System.FileName,'\"flow.launcher.sln*\"',1033)) AND scope='file:'" ) ]
public void GivenWindowsIndexSearch_WhenSearchAllFoldersAndFiles_ThenQueryShouldUseExpectedString (
string userSearchString , string expectedString )
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
//When
var resultString = queryConstructor . QueryForAllFilesAndFolders ( userSearchString ) ;
2020-05-19 10:10:46 +00:00
// Then
2020-05-18 10:14:38 +00:00
Assert . IsTrue ( resultString = = expectedString ,
$"Expected query string: {expectedString}{Environment.NewLine} " +
$"Actual string was: {resultString}{Environment.NewLine}" ) ;
}
2020-05-11 13:15:15 +00:00
2020-05-19 10:10:46 +00:00
[TestCase]
public void GivenWindowsIndexSearch_WhenReturnedZeroResultsAndIsNotIndexed_ThenSearchMethodShouldContinueDirectoryInfoClassSearch ( )
{
// Given
2020-05-19 12:36:56 +00:00
var searchManager = new SearchManager ( new Settings ( ) , new PluginInitContext ( ) ) ;
2020-05-19 10:10:46 +00:00
// When
2020-05-23 06:37:29 +00:00
var results = searchManager . TopLevelFolderSearchBehaviour (
2020-05-19 10:10:46 +00:00
MethodWindowsIndexSearchReturnsZeroResults ,
MethodDirectoryInfoClassSearchReturnsTwoResults ,
MethodIndexExistsReturnsFalse ,
2020-05-24 10:14:36 +00:00
new Query ( ) ,
"string not used" ) ;
2020-05-19 10:10:46 +00:00
// Then
Assert . IsTrue ( results . Count = = 2 ,
$"Expected to have 2 results from DirectoryInfoClassSearch {Environment.NewLine} " +
$"Actual number of results is {results.Count} {Environment.NewLine}" ) ;
}
[TestCase]
public void GivenWindowsIndexSearch_WhenReturnedZeroResultsAndIsIndexed_ThenSearchMethodShouldNotContinueDirectoryInfoClassSearch ( )
{
// Given
2020-05-19 12:36:56 +00:00
var searchManager = new SearchManager ( new Settings ( ) , new PluginInitContext ( ) ) ;
2020-05-19 10:10:46 +00:00
// When
2020-05-23 06:37:29 +00:00
var results = searchManager . TopLevelFolderSearchBehaviour (
2020-05-19 10:10:46 +00:00
MethodWindowsIndexSearchReturnsZeroResults ,
MethodDirectoryInfoClassSearchReturnsTwoResults ,
MethodIndexExistsReturnsTrue ,
2020-05-24 10:14:36 +00:00
new Query ( ) ,
"string not used" ) ;
2020-05-19 10:10:46 +00:00
// Then
Assert . IsTrue ( results . Count = = 0 ,
$"Expected to have 0 results because location is indexed {Environment.NewLine} " +
$"Actual number of results is {results.Count} {Environment.NewLine}" ) ;
}
2020-05-11 13:15:15 +00:00
2020-05-19 12:36:56 +00:00
[TestCase(@"c:\\", false)]
[TestCase(@"i:\", true)]
[TestCase(@"\c:\", false)]
[TestCase(@"cc:\", false)]
[TestCase(@"\\\SomeNetworkLocation\", false)]
[TestCase("RandomString", false)]
public void WhenGivenQuerySearchString_ThenShouldIndicateIfItIsLocationString ( string querySearchString , bool expectedResult )
{
// When, Given
2020-05-24 10:14:36 +00:00
var result = FilesFolders . IsLocationPathString ( querySearchString ) ;
2020-05-19 12:36:56 +00:00
//Then
Assert . IsTrue ( result = = expectedResult ,
$"Expected query search string check result is: {expectedResult} {Environment.NewLine} " +
$"Actual check result is {result} {Environment.NewLine}" ) ;
}
2020-05-25 08:58:28 +00:00
public void GivenWindowsIndexSearch_WhenSearchPatternHotKeyIsSearchAll_ThenQueryWhereRestrictionsShouldUseScopeString ( ) { }
2020-05-11 13:15:15 +00:00
}
}