2022-08-10 03:18:37 +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-27 22:55:41 +00:00
using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo ;
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 ;
2025-02-22 14:32:26 +00:00
using NUnit.Framework.Legacy ;
2020-05-11 13:19:41 +00:00
using System ;
2023-01-19 15:16:12 +00:00
using System.IO ;
2022-08-16 22:45:36 +00:00
using System.Runtime.Versioning ;
2023-01-19 15:16:12 +00:00
using static Flow . Launcher . Plugin . Explorer . Search . SearchManager ;
2020-05-11 13:15:15 +00:00
namespace Flow.Launcher.Test.Plugins
{
2020-06-12 11:19:55 +00:00
/// <summary>
/// These tests require the use of CSearchManager class from Microsoft.Search.Interop.
/// Windows Search service needs to be running to complete the tests
/// </summary>
2020-05-11 13:15:15 +00:00
[TestFixture]
public class ExplorerTest
{
2020-05-26 10:18:18 +00:00
private bool PreviousLocationExistsReturnsTrue ( string dummyString ) = > true ;
2020-05-26 09:49:18 +00:00
2020-05-26 10:18:18 +00:00
private bool PreviousLocationNotExistReturnsFalse ( string dummyString ) = > false ;
2020-05-26 09:49:18 +00:00
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2020-05-28 08:23:00 +00:00
[TestCase("C:\\SomeFolder\\", "directory='file:C:\\SomeFolder\\'")]
2020-05-11 19:56:51 +00:00
public void GivenWindowsIndexSearch_WhenProvidedFolderPath_ThenQueryWhereRestrictionsShouldUseDirectoryString ( string path , string expectedString )
2020-05-11 13:19:41 +00:00
{
// When
2020-05-11 19:56:51 +00:00
var folderPath = path ;
2022-11-04 04:57:47 +00:00
var result = QueryConstructor . TopLevelDirectoryConstraint ( folderPath ) ;
2020-05-11 13:19:41 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( result = = expectedString ,
2020-05-11 13:19:41 +00:00
$"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " +
$"Actual: {result}{Environment.NewLine}" ) ;
}
2020-05-11 13:15:15 +00:00
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2025-04-12 13:07:39 +00:00
[TestCase("C:\\", $"SELECT TOP 100 System.FileName, System.ItemUrl, System.ItemType FROM SystemIndex WHERE directory='file:C:\\' ORDER BY {QueryConstructor.OrderIdentifier}")]
[TestCase("C:\\SomeFolder\\", $"SELECT TOP 100 System.FileName, System.ItemUrl, System.ItemType FROM SystemIndex WHERE directory='file:C:\\SomeFolder\\' ORDER BY {QueryConstructor.OrderIdentifier}")]
2020-05-28 08:23:00 +00:00
public void GivenWindowsIndexSearch_WhenSearchTypeIsTopLevelDirectorySearch_ThenQueryShouldUseExpectedString ( string folderPath , string expectedString )
2020-05-11 20:50:17 +00:00
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
2021-01-03 02:52:59 +00:00
2020-05-11 20:50:17 +00:00
//When
2022-09-10 15:45:41 +00:00
var queryString = queryConstructor . Directory ( folderPath ) ;
2021-01-03 02:52:59 +00:00
2020-05-19 10:10:46 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( queryString . Replace ( " " , " " ) = = expectedString . Replace ( " " , " " ) ,
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}" ) ;
}
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2022-11-04 04:57:47 +00:00
[ TestCase ( "C:\\SomeFolder" , "flow.launcher.sln" , "SELECT TOP 100 System.FileName, System.ItemUrl, System.ItemType" +
" FROM SystemIndex WHERE directory='file:C:\\SomeFolder'" +
" AND (System.FileName LIKE 'flow.launcher.sln%' OR CONTAINS(System.FileName,'\"flow.launcher.sln*\"'))" +
2025-04-12 13:07:39 +00:00
$" ORDER BY {QueryConstructor.OrderIdentifier}" ) ]
2020-05-26 09:35:30 +00:00
public void GivenWindowsIndexSearchTopLevelDirectory_WhenSearchingForSpecificItem_ThenQueryShouldUseExpectedString (
2022-11-04 04:57:47 +00:00
string folderPath , string userSearchString , string expectedString )
2020-05-26 09:35:30 +00:00
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
//When
2022-11-04 04:57:47 +00:00
var queryString = queryConstructor . Directory ( folderPath , userSearchString ) ;
2020-05-26 09:35:30 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( expectedString , queryString ) ;
2020-05-26 09:35:30 +00:00
}
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2020-05-18 10:14:38 +00:00
[TestCase("scope='file:'")]
2021-01-03 02:52:59 +00:00
public void GivenWindowsIndexSearch_WhenSearchAllFoldersAndFiles_ThenQueryWhereRestrictionsShouldUseScopeString ( string expectedString )
2020-05-18 10:14:38 +00:00
{
//When
2022-11-04 04:57:47 +00:00
const string resultString = QueryConstructor . RestrictionsForAllFilesAndFoldersSearch ;
2020-05-18 10:14:38 +00:00
2020-05-19 10:10:46 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( expectedString , resultString ) ;
2020-05-18 10:14:38 +00:00
}
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2020-08-23 22:21:16 +00:00
[ TestCase ( "flow.launcher.sln" , "SELECT TOP 100 \"System.FileName\", \"System.ItemUrl\", \"System.ItemType\" " +
2022-08-16 22:45:36 +00:00
"FROM \"SystemIndex\" WHERE (System.FileName LIKE 'flow.launcher.sln%' " +
2025-04-12 13:07:39 +00:00
$"OR CONTAINS(System.FileName,'\" flow . launcher . sln * \ "',1033)) AND scope='file:' ORDER BY {QueryConstructor.OrderIdentifier}" ) ]
[TestCase("", $"SELECT TOP 100 \"System.FileName\", \"System.ItemUrl\", \"System.ItemType\" FROM \"SystemIndex\" WHERE WorkId IS NOT NULL AND scope='file:' ORDER BY {QueryConstructor.OrderIdentifier}")]
2020-05-18 10:14:38 +00:00
public void GivenWindowsIndexSearch_WhenSearchAllFoldersAndFiles_ThenQueryShouldUseExpectedString (
2021-01-03 02:52:59 +00:00
string userSearchString , string expectedString )
2020-05-18 10:14:38 +00:00
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
2022-12-15 11:03:54 +00:00
var baseQuery = queryConstructor . CreateBaseQuery ( ) ;
2022-11-04 04:57:47 +00:00
2021-07-18 12:40:53 +00:00
// system running this test could have different locale than the hard-coded 1033 LCID en-US.
2021-07-18 10:34:17 +00:00
var queryKeywordLocale = baseQuery . QueryKeywordLocale ;
expectedString = expectedString . Replace ( "1033" , queryKeywordLocale . ToString ( ) ) ;
2020-05-18 10:14:38 +00:00
//When
2022-09-10 15:45:41 +00:00
var resultString = queryConstructor . FilesAndFolders ( userSearchString ) ;
2020-05-18 10:14:38 +00:00
2020-05-19 10:10:46 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( expectedString , resultString ) ;
2020-05-18 10:14:38 +00:00
}
2022-11-04 04:57:47 +00:00
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2020-07-12 11:51:30 +00:00
[TestCase(@"some words", @"FREETEXT('some words')")]
public void GivenWindowsIndexSearch_WhenQueryWhereRestrictionsIsForFileContentSearch_ThenShouldReturnFreeTextString (
string querySearchString , string expectedString )
{
// Given
2025-02-22 14:32:26 +00:00
_ = new QueryConstructor ( new Settings ( ) ) ;
2020-07-12 11:51:30 +00:00
//When
2022-09-10 15:45:41 +00:00
var resultString = QueryConstructor . RestrictionsForFileContentSearch ( querySearchString ) ;
2020-07-12 11:51:30 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( resultString = = expectedString ,
2020-07-12 11:51:30 +00:00
$"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " +
$"Actual string was: {resultString}{Environment.NewLine}" ) ;
}
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2020-08-23 22:21:16 +00:00
[ TestCase ( "some words" , "SELECT TOP 100 System.FileName, System.ItemUrl, System.ItemType " +
2025-04-12 13:07:39 +00:00
$"FROM SystemIndex WHERE FREETEXT('some words') AND scope='file:' ORDER BY {QueryConstructor.OrderIdentifier}" ) ]
2020-07-12 11:51:30 +00:00
public void GivenWindowsIndexSearch_WhenSearchForFileContent_ThenQueryShouldUseExpectedString (
string userSearchString , string expectedString )
{
// Given
var queryConstructor = new QueryConstructor ( new Settings ( ) ) ;
//When
2022-09-10 15:45:41 +00:00
var resultString = queryConstructor . FileContent ( userSearchString ) ;
2020-07-12 11:51:30 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( resultString = = expectedString ,
2020-07-12 11:51:30 +00:00
$"Expected query string: {expectedString}{Environment.NewLine} " +
$"Actual string was: {resultString}{Environment.NewLine}" ) ;
}
2025-02-22 14:32:26 +00:00
public static void GivenQuery_WhenActionKeywordForFileContentSearchExists_ThenFileContentSearchRequiredShouldReturnTrue ( )
2020-07-12 12:41:01 +00:00
{
// Given
2022-11-04 04:57:47 +00:00
var query = new Query
{
ActionKeyword = "doc:" , Search = "search term"
} ;
2020-07-12 12:41:01 +00:00
2020-07-19 12:24:02 +00:00
var searchManager = new SearchManager ( new Settings ( ) , new PluginInitContext ( ) ) ;
2021-01-03 02:52:59 +00:00
2020-07-12 12:41:01 +00:00
// When
2023-01-19 06:47:42 +00:00
var result = searchManager . IsFileContentSearch ( query . ActionKeyword ) ;
2020-07-12 12:41:01 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( result ,
2020-07-12 12:41:01 +00:00
$"Expected True for file content search. {Environment.NewLine} " +
$"Actual result was: {result}{Environment.NewLine}" ) ;
}
2024-05-16 11:24:20 +00:00
[TestCase(@"c:\\", false)]
[TestCase(@"i:\", true)]
[TestCase(@"\c:\", false)]
[TestCase(@"cc:\", false)]
[TestCase(@"\\\SomeNetworkLocation\", false)]
[TestCase(@"\\SomeNetworkLocation\", true)]
[TestCase("RandomFile", false)]
[TestCase(@"c:\>*", true)]
[TestCase(@"c:\>", true)]
[TestCase(@"c:\SomeLocation\SomeOtherLocation\>", true)]
[TestCase(@"c:\SomeLocation\SomeOtherLocation", true)]
[TestCase(@"c:\SomeLocation\SomeOtherLocation\SomeFile.exe", true)]
2024-05-16 11:22:08 +00:00
[TestCase(@"\\SomeNetworkLocation\SomeFile.exe", true)]
2020-05-28 08:23:00 +00:00
public void WhenGivenQuerySearchString_ThenShouldIndicateIfIsLocationPathString ( string querySearchString , bool expectedResult )
2020-05-19 12:36:56 +00:00
{
// When, Given
2020-05-24 10:14:36 +00:00
var result = FilesFolders . IsLocationPathString ( querySearchString ) ;
2020-05-19 12:36:56 +00:00
//Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( result = = expectedResult ,
2020-05-19 12:36:56 +00:00
$"Expected query search string check result is: {expectedResult} {Environment.NewLine} " +
$"Actual check result is {result} {Environment.NewLine}" ) ;
}
2021-01-03 02:52:59 +00:00
2020-05-27 22:06:49 +00:00
[TestCase(@"C:\SomeFolder\SomeApp", true, @"C:\SomeFolder\")]
[TestCase(@"C:\SomeFolder\SomeApp\SomeFile", true, @"C:\SomeFolder\SomeApp\")]
[TestCase(@"C:\NonExistentFolder\SomeApp", false, "")]
2020-05-26 10:18:18 +00:00
public void GivenAPartialPath_WhenPreviousLevelDirectoryExists_ThenShouldReturnThePreviousDirectoryPathString (
string path , bool previousDirectoryExists , string expectedString )
2020-05-26 09:49:18 +00:00
{
2020-05-26 10:18:18 +00:00
// When
Func < string , bool > previousLocationExists = null ;
if ( previousDirectoryExists )
{
previousLocationExists = PreviousLocationExistsReturnsTrue ;
}
else
{
previousLocationExists = PreviousLocationNotExistReturnsFalse ;
}
2020-05-26 09:49:18 +00:00
2020-05-26 10:18:18 +00:00
// Given
var previousDirectoryPath = FilesFolders . GetPreviousExistingDirectory ( previousLocationExists , path ) ;
2020-05-26 09:49:18 +00:00
2020-05-26 10:18:18 +00:00
//Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( previousDirectoryPath = = expectedString ,
2020-05-26 10:18:18 +00:00
$"Expected path string: {expectedString} {Environment.NewLine} " +
$"Actual path string is {previousDirectoryPath} {Environment.NewLine}" ) ;
2020-05-26 09:49:18 +00:00
}
2020-05-25 08:58:28 +00:00
2020-05-28 11:33:18 +00:00
[TestCase(@"C:\NonExistentFolder\SomeApp", @"C:\NonExistentFolder\")]
[TestCase(@"C:\NonExistentFolder\SomeApp\", @"C:\NonExistentFolder\SomeApp\")]
public void WhenGivenAPath_ThenShouldReturnThePreviousDirectoryPathIfIncompleteOrOriginalString (
string path , string expectedString )
{
2020-06-02 10:21:28 +00:00
var returnedPath = FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( path ) ;
2020-05-28 11:33:18 +00:00
//Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( returnedPath = = expectedString ,
2020-05-28 11:33:18 +00:00
$"Expected path string: {expectedString} {Environment.NewLine} " +
$"Actual path string is {returnedPath} {Environment.NewLine}" ) ;
}
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2022-11-04 04:57:47 +00:00
[TestCase("c:\\SomeFolder", "scope='file:c:\\SomeFolder'")]
[TestCase("c:\\OtherFolder", "scope='file:c:\\OtherFolder'")]
public void GivenFilePath_WhenSearchPatternHotKeyIsSearchAll_ThenQueryWhereRestrictionsShouldUseScopeString ( string path , string expectedString )
2020-05-27 21:38:41 +00:00
{
//When
2022-11-04 04:57:47 +00:00
var resultString = QueryConstructor . RecursiveDirectoryConstraint ( path ) ;
2020-05-27 21:38:41 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( expectedString , resultString ) ;
2020-05-27 21:38:41 +00:00
}
2020-05-27 22:55:41 +00:00
2022-08-16 22:45:36 +00:00
[SupportedOSPlatform("windows7.0")]
2021-01-03 02:52:59 +00:00
[TestCase("c:\\somefolder\\>somefile", "*somefile*")]
2020-05-27 22:55:41 +00:00
[TestCase("c:\\somefolder\\somefile", "somefile*")]
[TestCase("c:\\somefolder\\", "*")]
public void GivenDirectoryInfoSearch_WhenSearchPatternHotKeyIsSearchAll_ThenSearchCriteriaShouldUseCriteriaString ( string path , string expectedString )
{
//When
2021-01-29 10:40:51 +00:00
var resultString = DirectoryInfoSearch . ConstructSearchCriteria ( path ) ;
2020-05-27 22:55:41 +00:00
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( expectedString , resultString ) ;
2020-05-27 22:55:41 +00:00
}
2022-12-24 11:50:50 +00:00
[TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "irrelevant", false, true, "c:\\somefolder\\someotherfolder\\")]
[TestCase("c:\\somefolder\\someotherfolder\\", ResultType.Folder, "irrelevant", true, true, "c:\\somefolder\\someotherfolder\\")]
[TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "irrelevant", true, false, "p c:\\somefolder\\someotherfolder\\")]
[TestCase("c:\\somefolder\\someotherfolder\\", ResultType.Folder, "irrelevant", false, false, "c:\\somefolder\\someotherfolder\\")]
[TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "p", true, false, "p c:\\somefolder\\someotherfolder\\")]
[TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "", true, true, "c:\\somefolder\\someotherfolder\\")]
public void GivenFolderResult_WhenGetPath_ThenPathShouldBeExpectedString (
string path ,
ResultType type ,
string actionKeyword ,
bool pathSearchKeywordEnabled ,
bool searchActionKeywordEnabled ,
string expectedResult )
{
// Given
var settings = new Settings ( )
{
PathSearchKeywordEnabled = pathSearchKeywordEnabled ,
PathSearchActionKeyword = "p" ,
SearchActionKeywordEnabled = searchActionKeywordEnabled ,
SearchActionKeyword = Query . GlobalPluginWildcardSign
} ;
ResultManager . Init ( new PluginInitContext ( ) , settings ) ;
// When
var result = ResultManager . GetPathWithActionKeyword ( path , type , actionKeyword ) ;
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( result , expectedResult ) ;
2022-12-24 11:50:50 +00:00
}
[TestCase("c:\\somefolder\\somefile", ResultType.File, "irrelevant", false, true, "e c:\\somefolder\\somefile")]
[TestCase("c:\\somefolder\\somefile", ResultType.File, "p", true, false, "p c:\\somefolder\\somefile")]
[TestCase("c:\\somefolder\\somefile", ResultType.File, "e", true, true, "e c:\\somefolder\\somefile")]
[TestCase("c:\\somefolder\\somefile", ResultType.File, "irrelevant", false, false, "e c:\\somefolder\\somefile")]
public void GivenFileResult_WhenGetPath_ThenPathShouldBeExpectedString (
string path ,
ResultType type ,
string actionKeyword ,
bool pathSearchKeywordEnabled ,
bool searchActionKeywordEnabled ,
string expectedResult )
{
// Given
var settings = new Settings ( )
{
PathSearchKeywordEnabled = pathSearchKeywordEnabled ,
PathSearchActionKeyword = "p" ,
SearchActionKeywordEnabled = searchActionKeywordEnabled ,
SearchActionKeyword = "e"
} ;
ResultManager . Init ( new PluginInitContext ( ) , settings ) ;
// When
var result = ResultManager . GetPathWithActionKeyword ( path , type , actionKeyword ) ;
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( result , expectedResult ) ;
2022-12-24 11:50:50 +00:00
}
2022-12-24 17:58:37 +00:00
[TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "q", false, false, "q somefolder")]
[TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "i", true, false, "p c:\\somefolder\\")]
[TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "irrelevant", true, true, "c:\\somefolder\\")]
public void GivenQueryWithFolderTypeResult_WhenGetAutoComplete_ThenResultShouldBeExpectedString (
string title ,
string path ,
ResultType resultType ,
string actionKeyword ,
bool pathSearchKeywordEnabled ,
bool searchActionKeywordEnabled ,
string expectedResult )
{
// Given
var query = new Query ( ) { ActionKeyword = actionKeyword } ;
var settings = new Settings ( )
{
PathSearchKeywordEnabled = pathSearchKeywordEnabled ,
PathSearchActionKeyword = "p" ,
SearchActionKeywordEnabled = searchActionKeywordEnabled ,
SearchActionKeyword = Query . GlobalPluginWildcardSign ,
QuickAccessActionKeyword = "q" ,
IndexSearchActionKeyword = "i"
} ;
ResultManager . Init ( new PluginInitContext ( ) , settings ) ;
// When
var result = ResultManager . GetAutoCompleteText ( title , query , path , resultType ) ;
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( result , expectedResult ) ;
2022-12-24 17:58:37 +00:00
}
[TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "q", false, false, "q somefile")]
[TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "i", true, false, "p c:\\somefolder\\somefile")]
[TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "irrelevant", true, true, "c:\\somefolder\\somefile")]
public void GivenQueryWithFileTypeResult_WhenGetAutoComplete_ThenResultShouldBeExpectedString (
string title ,
string path ,
ResultType resultType ,
string actionKeyword ,
bool pathSearchKeywordEnabled ,
bool searchActionKeywordEnabled ,
string expectedResult )
{
// Given
var query = new Query ( ) { ActionKeyword = actionKeyword } ;
var settings = new Settings ( )
{
QuickAccessActionKeyword = "q" ,
IndexSearchActionKeyword = "i" ,
PathSearchActionKeyword = "p" ,
PathSearchKeywordEnabled = pathSearchKeywordEnabled ,
SearchActionKeywordEnabled = searchActionKeywordEnabled ,
SearchActionKeyword = Query . GlobalPluginWildcardSign
} ;
ResultManager . Init ( new PluginInitContext ( ) , settings ) ;
// When
var result = ResultManager . GetAutoCompleteText ( title , query , path , resultType ) ;
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( result , expectedResult ) ;
2022-12-24 17:58:37 +00:00
}
2023-01-19 15:16:12 +00:00
[TestCase(@"c:\foo", @"c:\foo", true)]
[TestCase(@"C:\Foo\", @"c:\foo\", true)]
[TestCase(@"c:\foo", @"c:\foo\", false)]
2023-01-19 20:45:39 +00:00
public void GivenTwoPaths_WhenCompared_ThenShouldBeExpectedSameOrDifferent ( string path1 , string path2 , bool expectedResult )
2023-01-19 15:16:12 +00:00
{
2023-01-19 20:45:39 +00:00
// Given
2023-01-19 15:16:12 +00:00
var comparator = PathEqualityComparator . Instance ;
var result1 = new Result
{
Title = Path . GetFileName ( path1 ) ,
SubTitle = path1
} ;
var result2 = new Result
{
Title = Path . GetFileName ( path2 ) ,
SubTitle = path2
} ;
2023-01-19 20:45:39 +00:00
// When, Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( expectedResult , comparator . Equals ( result1 , result2 ) ) ;
2023-01-19 15:16:12 +00:00
}
[TestCase(@"c:\foo\", @"c:\foo\")]
[TestCase(@"C:\Foo\", @"c:\foo\")]
2023-01-19 20:45:39 +00:00
public void GivenTwoPaths_WhenComparedHasCode_ThenShouldBeSame ( string path1 , string path2 )
2023-01-19 15:16:12 +00:00
{
2023-01-19 20:45:39 +00:00
// Given
2023-01-19 15:16:12 +00:00
var comparator = PathEqualityComparator . Instance ;
var result1 = new Result
{
Title = Path . GetFileName ( path1 ) ,
SubTitle = path1
} ;
var result2 = new Result
{
Title = Path . GetFileName ( path2 ) ,
SubTitle = path2
} ;
2023-01-19 20:45:39 +00:00
2023-01-19 15:16:12 +00:00
var hash1 = comparator . GetHashCode ( result1 ) ;
var hash2 = comparator . GetHashCode ( result2 ) ;
2023-01-19 20:45:39 +00:00
// When, Then
2025-02-22 14:32:26 +00:00
ClassicAssert . IsTrue ( hash1 = = hash2 ) ;
2023-01-19 15:16:12 +00:00
}
2023-01-20 07:03:40 +00:00
[TestCase(@"%appdata%", true)]
[TestCase(@"%appdata%\123", true)]
[TestCase(@"c:\foo %appdata%\", false)]
[TestCase(@"c:\users\%USERNAME%\downloads", true)]
[TestCase(@"c:\downloads", false)]
[TestCase(@"%", false)]
[TestCase(@"%%", false)]
[TestCase(@"%bla%blabla%", false)]
public void GivenPath_WhenHavingEnvironmentVariableOrNot_ThenShouldBeExpected ( string path , bool expectedResult )
{
// When
var result = EnvironmentVariables . HasEnvironmentVar ( path ) ;
// Then
2025-02-22 14:32:26 +00:00
ClassicAssert . AreEqual ( result , expectedResult ) ;
2023-01-20 07:03:40 +00:00
}
2020-05-11 13:15:15 +00:00
}
}