Fix build issue for nunit 4.3.2 & Improve code quality

This commit is contained in:
Jack251970 2025-02-22 22:32:26 +08:00
parent 2d90481968
commit 81d479c3a3
8 changed files with 113 additions and 133 deletions

View file

@ -1,5 +1,6 @@
using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Plugin.SharedCommands;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
namespace Flow.Launcher.Test namespace Flow.Launcher.Test
{ {
@ -35,7 +36,7 @@ namespace Flow.Launcher.Test
[TestCase(@"c:\barr", @"c:\foo\..\bar\baz", false)] [TestCase(@"c:\barr", @"c:\foo\..\bar\baz", false)]
public void GivenTwoPaths_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult) public void GivenTwoPaths_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult)
{ {
Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path)); ClassicAssert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path));
} }
// Equality // Equality
@ -47,7 +48,7 @@ namespace Flow.Launcher.Test
[TestCase(@"c:\foo", @"c:\foo\", true)] [TestCase(@"c:\foo", @"c:\foo\", true)]
public void GivenTwoPathsAreTheSame_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult) public void GivenTwoPathsAreTheSame_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult)
{ {
Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, allowEqual: expectedResult)); ClassicAssert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, allowEqual: expectedResult));
} }
} }
} }

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure;
using Flow.Launcher.Plugin; using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedModels; using Flow.Launcher.Plugin.SharedModels;
@ -21,8 +22,8 @@ namespace Flow.Launcher.Test
private const string MicrosoftSqlServerManagementStudio = "Microsoft SQL Server Management Studio"; private const string MicrosoftSqlServerManagementStudio = "Microsoft SQL Server Management Studio";
private const string VisualStudioCode = "Visual Studio Code"; private const string VisualStudioCode = "Visual Studio Code";
public List<string> GetSearchStrings() public static List<string> GetSearchStrings()
=> new List<string> => new()
{ {
Chrome, Chrome,
"Choose which programs you want Windows to use for activities like web browsing, editing photos, sending e-mail, and playing music.", "Choose which programs you want Windows to use for activities like web browsing, editing photos, sending e-mail, and playing music.",
@ -34,7 +35,7 @@ namespace Flow.Launcher.Test
OneOneOneOne OneOneOneOne
}; };
public List<int> GetPrecisionScores() public static List<int> GetPrecisionScores()
{ {
var listToReturn = new List<int>(); var listToReturn = new List<int>();
@ -71,10 +72,10 @@ namespace Flow.Launcher.Test
results = results.Where(x => x.Score > 0).OrderByDescending(x => x.Score).ToList(); results = results.Where(x => x.Score > 0).OrderByDescending(x => x.Score).ToList();
Assert.IsTrue(results.Count == 3); ClassicAssert.IsTrue(results.Count == 3);
Assert.IsTrue(results[0].Title == "Inste"); ClassicAssert.IsTrue(results[0].Title == "Inste");
Assert.IsTrue(results[1].Title == "Install Package"); ClassicAssert.IsTrue(results[1].Title == "Install Package");
Assert.IsTrue(results[2].Title == "file open in browser-test"); ClassicAssert.IsTrue(results[2].Title == "file open in browser-test");
} }
[TestCase("Chrome")] [TestCase("Chrome")]
@ -84,7 +85,7 @@ namespace Flow.Launcher.Test
var matcher = new StringMatcher(); var matcher = new StringMatcher();
var scoreResult = matcher.FuzzyMatch(searchString, compareString).RawScore; var scoreResult = matcher.FuzzyMatch(searchString, compareString).RawScore;
Assert.True(scoreResult == 0); ClassicAssert.True(scoreResult == 0);
} }
[TestCase("chr")] [TestCase("chr")]
@ -125,7 +126,7 @@ namespace Flow.Launcher.Test
Debug.WriteLine("###############################################"); Debug.WriteLine("###############################################");
Debug.WriteLine(""); Debug.WriteLine("");
Assert.IsFalse(filteredResult.Any(x => x.Score < precisionScore)); ClassicAssert.IsFalse(filteredResult.Any(x => x.Score < precisionScore));
} }
} }
@ -151,7 +152,7 @@ namespace Flow.Launcher.Test
var rawScore = matcher.FuzzyMatch(queryString, compareString).RawScore; var rawScore = matcher.FuzzyMatch(queryString, compareString).RawScore;
// Should // Should
Assert.AreEqual(expectedScore, rawScore, ClassicAssert.AreEqual(expectedScore, rawScore,
$"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}"); $"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}");
} }
@ -190,12 +191,12 @@ namespace Flow.Launcher.Test
Debug.WriteLine("###############################################"); Debug.WriteLine("###############################################");
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}"); Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
Debug.WriteLine( Debug.WriteLine(
$"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int) expectedPrecisionScore})"); $"RAW SCORE: {matchResult.RawScore}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int) expectedPrecisionScore})");
Debug.WriteLine("###############################################"); Debug.WriteLine("###############################################");
Debug.WriteLine(""); Debug.WriteLine("");
// Should // Should
Assert.AreEqual(expectedPrecisionResult, matchResult.IsSearchPrecisionScoreMet(), ClassicAssert.AreEqual(expectedPrecisionResult, matchResult.IsSearchPrecisionScoreMet(),
$"Query: {queryString}{Environment.NewLine} " + $"Query: {queryString}{Environment.NewLine} " +
$"Compare: {compareString}{Environment.NewLine}" + $"Compare: {compareString}{Environment.NewLine}" +
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" + $"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
@ -241,12 +242,12 @@ namespace Flow.Launcher.Test
Debug.WriteLine("###############################################"); Debug.WriteLine("###############################################");
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}"); Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
Debug.WriteLine( Debug.WriteLine(
$"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int) expectedPrecisionScore})"); $"RAW SCORE: {matchResult.RawScore}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int) expectedPrecisionScore})");
Debug.WriteLine("###############################################"); Debug.WriteLine("###############################################");
Debug.WriteLine(""); Debug.WriteLine("");
// Should // Should
Assert.AreEqual(expectedPrecisionResult, matchResult.IsSearchPrecisionScoreMet(), ClassicAssert.AreEqual(expectedPrecisionResult, matchResult.IsSearchPrecisionScoreMet(),
$"Query:{queryString}{Environment.NewLine} " + $"Query:{queryString}{Environment.NewLine} " +
$"Compare:{compareString}{Environment.NewLine}" + $"Compare:{compareString}{Environment.NewLine}" +
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" + $"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
@ -277,7 +278,7 @@ namespace Flow.Launcher.Test
Debug.WriteLine(""); Debug.WriteLine("");
// Should // Should
Assert.True(compareString1Result.Score > compareString2Result.Score, ClassicAssert.True(compareString1Result.Score > compareString2Result.Score,
$"Query: \"{queryString}\"{Environment.NewLine} " + $"Query: \"{queryString}\"{Environment.NewLine} " +
$"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}" + $"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}" +
$"Should be greater than{Environment.NewLine}" + $"Should be greater than{Environment.NewLine}" +
@ -310,7 +311,7 @@ namespace Flow.Launcher.Test
Debug.WriteLine(""); Debug.WriteLine("");
// Should // Should
Assert.True(compareString1Result.Score > compareString2Result.Score, ClassicAssert.True(compareString1Result.Score > compareString2Result.Score,
$"Query: \"{queryString}\"{Environment.NewLine} " + $"Query: \"{queryString}\"{Environment.NewLine} " +
$"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}" + $"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}" +
$"Should be greater than{Environment.NewLine}" + $"Should be greater than{Environment.NewLine}" +
@ -336,7 +337,7 @@ namespace Flow.Launcher.Test
var secondScore = new[] {secondNameMatch, secondDescriptionMatch, secondExecutableNameMatch}.Max(); var secondScore = new[] {secondNameMatch, secondDescriptionMatch, secondExecutableNameMatch}.Max();
// Assert // Assert
Assert.IsTrue(firstScore > secondScore, ClassicAssert.IsTrue(firstScore > secondScore,
$"Query: \"{queryString}\"{Environment.NewLine} " + $"Query: \"{queryString}\"{Environment.NewLine} " +
$"Name of first: \"{firstName}\", Final Score: {firstScore}{Environment.NewLine}" + $"Name of first: \"{firstName}\", Final Score: {firstScore}{Environment.NewLine}" +
$"Should be greater than{Environment.NewLine}" + $"Should be greater than{Environment.NewLine}" +
@ -360,7 +361,7 @@ namespace Flow.Launcher.Test
{ {
var matcher = new StringMatcher(); var matcher = new StringMatcher();
var score = matcher.FuzzyMatch(queryString, compareString).Score; var score = matcher.FuzzyMatch(queryString, compareString).Score;
Assert.IsTrue(score == desiredScore, ClassicAssert.IsTrue(score == desiredScore,
$@"Query: ""{queryString}"" $@"Query: ""{queryString}""
CompareString: ""{compareString}"" CompareString: ""{compareString}""
Score: {score} Score: {score}

View file

@ -1,4 +1,5 @@
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
using System; using System;
using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Infrastructure.Http; using Flow.Launcher.Infrastructure.Http;
@ -16,16 +17,16 @@ namespace Flow.Launcher.Test
proxy.Enabled = true; proxy.Enabled = true;
proxy.Server = "127.0.0.1"; proxy.Server = "127.0.0.1";
Assert.AreEqual(Http.WebProxy.Address, new Uri($"http://{proxy.Server}:{proxy.Port}")); ClassicAssert.AreEqual(Http.WebProxy.Address, new Uri($"http://{proxy.Server}:{proxy.Port}"));
Assert.IsNull(Http.WebProxy.Credentials); ClassicAssert.IsNull(Http.WebProxy.Credentials);
proxy.UserName = "test"; proxy.UserName = "test";
Assert.NotNull(Http.WebProxy.Credentials); ClassicAssert.NotNull(Http.WebProxy.Credentials);
Assert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").UserName, proxy.UserName); ClassicAssert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").UserName, proxy.UserName);
Assert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").Password, ""); ClassicAssert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").Password, "");
proxy.Password = "test password"; proxy.Password = "test password";
Assert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").Password, proxy.Password); ClassicAssert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").Password, proxy.Password);
} }
} }
} }

View file

@ -1,4 +1,5 @@
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Plugin; using Flow.Launcher.Plugin;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,37 +16,37 @@ namespace Flow.Launcher.Test
// Given // Given
var duplicateList = new List<PluginMetadata> var duplicateList = new List<PluginMetadata>
{ {
new PluginMetadata new()
{ {
ID = "CEA0TYUC6D3B4085823D60DC76F28855", ID = "CEA0TYUC6D3B4085823D60DC76F28855",
Version = "1.0.0" Version = "1.0.0"
}, },
new PluginMetadata new()
{ {
ID = "CEA0TYUC6D3B4085823D60DC76F28855", ID = "CEA0TYUC6D3B4085823D60DC76F28855",
Version = "1.0.1" Version = "1.0.1"
}, },
new PluginMetadata new()
{ {
ID = "CEA0TYUC6D3B4085823D60DC76F28855", ID = "CEA0TYUC6D3B4085823D60DC76F28855",
Version = "1.0.2" Version = "1.0.2"
}, },
new PluginMetadata new()
{ {
ID = "CEA0TYUC6D3B4085823D60DC76F28855", ID = "CEA0TYUC6D3B4085823D60DC76F28855",
Version = "1.0.0" Version = "1.0.0"
}, },
new PluginMetadata new()
{ {
ID = "CEA0TYUC6D3B4085823D60DC76F28855", ID = "CEA0TYUC6D3B4085823D60DC76F28855",
Version = "1.0.0" Version = "1.0.0"
}, },
new PluginMetadata new()
{ {
ID = "ABC0TYUC6D3B7855823D60DC76F28855", ID = "ABC0TYUC6D3B7855823D60DC76F28855",
Version = "1.0.0" Version = "1.0.0"
}, },
new PluginMetadata new()
{ {
ID = "ABC0TYUC6D3B7855823D60DC76F28855", ID = "ABC0TYUC6D3B7855823D60DC76F28855",
Version = "1.0.0" Version = "1.0.0"
@ -56,11 +57,11 @@ namespace Flow.Launcher.Test
(var unique, var duplicates) = PluginConfig.GetUniqueLatestPluginMetadata(duplicateList); (var unique, var duplicates) = PluginConfig.GetUniqueLatestPluginMetadata(duplicateList);
// Then // Then
Assert.True(unique.FirstOrDefault().ID == "CEA0TYUC6D3B4085823D60DC76F28855" && unique.FirstOrDefault().Version == "1.0.2"); ClassicAssert.True(unique.FirstOrDefault().ID == "CEA0TYUC6D3B4085823D60DC76F28855" && unique.FirstOrDefault().Version == "1.0.2");
Assert.True(unique.Count() == 1); ClassicAssert.True(unique.Count == 1);
Assert.False(duplicates.Any(x => x.Version == "1.0.2" && x.ID == "CEA0TYUC6D3B4085823D60DC76F28855")); ClassicAssert.False(duplicates.Any(x => x.Version == "1.0.2" && x.ID == "CEA0TYUC6D3B4085823D60DC76F28855"));
Assert.True(duplicates.Count() == 6); ClassicAssert.True(duplicates.Count == 6);
} }
[Test] [Test]
@ -69,12 +70,12 @@ namespace Flow.Launcher.Test
// Given // Given
var duplicateList = new List<PluginMetadata> var duplicateList = new List<PluginMetadata>
{ {
new PluginMetadata new()
{ {
ID = "CEA0TYUC6D3B7855823D60DC76F28855", ID = "CEA0TYUC6D3B7855823D60DC76F28855",
Version = "1.0.0" Version = "1.0.0"
}, },
new PluginMetadata new()
{ {
ID = "CEA0TYUC6D3B7855823D60DC76F28855", ID = "CEA0TYUC6D3B7855823D60DC76F28855",
Version = "1.0.0" Version = "1.0.0"
@ -85,8 +86,8 @@ namespace Flow.Launcher.Test
(var unique, var duplicates) = PluginConfig.GetUniqueLatestPluginMetadata(duplicateList); (var unique, var duplicates) = PluginConfig.GetUniqueLatestPluginMetadata(duplicateList);
// Then // Then
Assert.True(unique.Count() == 0); ClassicAssert.True(unique.Count == 0);
Assert.True(duplicates.Count() == 2); ClassicAssert.True(duplicates.Count == 2);
} }
} }
} }

View file

@ -5,12 +5,10 @@ using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo;
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex; using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Plugin.SharedCommands;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using static Flow.Launcher.Plugin.Explorer.Search.SearchManager; using static Flow.Launcher.Plugin.Explorer.Search.SearchManager;
namespace Flow.Launcher.Test.Plugins namespace Flow.Launcher.Test.Plugins
@ -22,28 +20,6 @@ namespace Flow.Launcher.Test.Plugins
[TestFixture] [TestFixture]
public class ExplorerTest public class ExplorerTest
{ {
#pragma warning disable CS1998 // async method with no await (more readable to leave it async to match the tested signature)
private async Task<List<Result>> MethodWindowsIndexSearchReturnsZeroResultsAsync(Query dummyQuery, string dummyString, CancellationToken dummyToken)
{
return new List<Result>();
}
#pragma warning restore CS1998
private List<Result> MethodDirectoryInfoClassSearchReturnsTwoResults(Query dummyQuery, string dummyString, CancellationToken token)
{
return new List<Result>
{
new Result
{
Title = "Result 1"
},
new Result
{
Title = "Result 2"
}
};
}
private bool PreviousLocationExistsReturnsTrue(string dummyString) => true; private bool PreviousLocationExistsReturnsTrue(string dummyString) => true;
private bool PreviousLocationNotExistReturnsFalse(string dummyString) => false; private bool PreviousLocationNotExistReturnsFalse(string dummyString) => false;
@ -57,7 +33,7 @@ namespace Flow.Launcher.Test.Plugins
var result = QueryConstructor.TopLevelDirectoryConstraint(folderPath); var result = QueryConstructor.TopLevelDirectoryConstraint(folderPath);
// Then // Then
Assert.IsTrue(result == expectedString, ClassicAssert.IsTrue(result == expectedString,
$"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " + $"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " +
$"Actual: {result}{Environment.NewLine}"); $"Actual: {result}{Environment.NewLine}");
} }
@ -74,7 +50,7 @@ namespace Flow.Launcher.Test.Plugins
var queryString = queryConstructor.Directory(folderPath); var queryString = queryConstructor.Directory(folderPath);
// Then // Then
Assert.IsTrue(queryString.Replace(" ", " ") == expectedString.Replace(" ", " "), ClassicAssert.IsTrue(queryString.Replace(" ", " ") == expectedString.Replace(" ", " "),
$"Expected string: {expectedString}{Environment.NewLine} " + $"Expected string: {expectedString}{Environment.NewLine} " +
$"Actual string was: {queryString}{Environment.NewLine}"); $"Actual string was: {queryString}{Environment.NewLine}");
} }
@ -94,7 +70,7 @@ namespace Flow.Launcher.Test.Plugins
var queryString = queryConstructor.Directory(folderPath, userSearchString); var queryString = queryConstructor.Directory(folderPath, userSearchString);
// Then // Then
Assert.AreEqual(expectedString, queryString); ClassicAssert.AreEqual(expectedString, queryString);
} }
[SupportedOSPlatform("windows7.0")] [SupportedOSPlatform("windows7.0")]
@ -105,7 +81,7 @@ namespace Flow.Launcher.Test.Plugins
const string resultString = QueryConstructor.RestrictionsForAllFilesAndFoldersSearch; const string resultString = QueryConstructor.RestrictionsForAllFilesAndFoldersSearch;
// Then // Then
Assert.AreEqual(expectedString, resultString); ClassicAssert.AreEqual(expectedString, resultString);
} }
[SupportedOSPlatform("windows7.0")] [SupportedOSPlatform("windows7.0")]
@ -128,7 +104,7 @@ namespace Flow.Launcher.Test.Plugins
var resultString = queryConstructor.FilesAndFolders(userSearchString); var resultString = queryConstructor.FilesAndFolders(userSearchString);
// Then // Then
Assert.AreEqual(expectedString, resultString); ClassicAssert.AreEqual(expectedString, resultString);
} }
@ -138,13 +114,13 @@ namespace Flow.Launcher.Test.Plugins
string querySearchString, string expectedString) string querySearchString, string expectedString)
{ {
// Given // Given
var queryConstructor = new QueryConstructor(new Settings()); _ = new QueryConstructor(new Settings());
//When //When
var resultString = QueryConstructor.RestrictionsForFileContentSearch(querySearchString); var resultString = QueryConstructor.RestrictionsForFileContentSearch(querySearchString);
// Then // Then
Assert.IsTrue(resultString == expectedString, ClassicAssert.IsTrue(resultString == expectedString,
$"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " + $"Expected QueryWhereRestrictions string: {expectedString}{Environment.NewLine} " +
$"Actual string was: {resultString}{Environment.NewLine}"); $"Actual string was: {resultString}{Environment.NewLine}");
} }
@ -162,12 +138,12 @@ namespace Flow.Launcher.Test.Plugins
var resultString = queryConstructor.FileContent(userSearchString); var resultString = queryConstructor.FileContent(userSearchString);
// Then // Then
Assert.IsTrue(resultString == expectedString, ClassicAssert.IsTrue(resultString == expectedString,
$"Expected query string: {expectedString}{Environment.NewLine} " + $"Expected query string: {expectedString}{Environment.NewLine} " +
$"Actual string was: {resultString}{Environment.NewLine}"); $"Actual string was: {resultString}{Environment.NewLine}");
} }
public void GivenQuery_WhenActionKeywordForFileContentSearchExists_ThenFileContentSearchRequiredShouldReturnTrue() public static void GivenQuery_WhenActionKeywordForFileContentSearchExists_ThenFileContentSearchRequiredShouldReturnTrue()
{ {
// Given // Given
var query = new Query var query = new Query
@ -181,7 +157,7 @@ namespace Flow.Launcher.Test.Plugins
var result = searchManager.IsFileContentSearch(query.ActionKeyword); var result = searchManager.IsFileContentSearch(query.ActionKeyword);
// Then // Then
Assert.IsTrue(result, ClassicAssert.IsTrue(result,
$"Expected True for file content search. {Environment.NewLine} " + $"Expected True for file content search. {Environment.NewLine} " +
$"Actual result was: {result}{Environment.NewLine}"); $"Actual result was: {result}{Environment.NewLine}");
} }
@ -206,7 +182,7 @@ namespace Flow.Launcher.Test.Plugins
var result = FilesFolders.IsLocationPathString(querySearchString); var result = FilesFolders.IsLocationPathString(querySearchString);
//Then //Then
Assert.IsTrue(result == expectedResult, ClassicAssert.IsTrue(result == expectedResult,
$"Expected query search string check result is: {expectedResult} {Environment.NewLine} " + $"Expected query search string check result is: {expectedResult} {Environment.NewLine} " +
$"Actual check result is {result} {Environment.NewLine}"); $"Actual check result is {result} {Environment.NewLine}");
@ -233,7 +209,7 @@ namespace Flow.Launcher.Test.Plugins
var previousDirectoryPath = FilesFolders.GetPreviousExistingDirectory(previousLocationExists, path); var previousDirectoryPath = FilesFolders.GetPreviousExistingDirectory(previousLocationExists, path);
//Then //Then
Assert.IsTrue(previousDirectoryPath == expectedString, ClassicAssert.IsTrue(previousDirectoryPath == expectedString,
$"Expected path string: {expectedString} {Environment.NewLine} " + $"Expected path string: {expectedString} {Environment.NewLine} " +
$"Actual path string is {previousDirectoryPath} {Environment.NewLine}"); $"Actual path string is {previousDirectoryPath} {Environment.NewLine}");
} }
@ -246,7 +222,7 @@ namespace Flow.Launcher.Test.Plugins
var returnedPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path); var returnedPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path);
//Then //Then
Assert.IsTrue(returnedPath == expectedString, ClassicAssert.IsTrue(returnedPath == expectedString,
$"Expected path string: {expectedString} {Environment.NewLine} " + $"Expected path string: {expectedString} {Environment.NewLine} " +
$"Actual path string is {returnedPath} {Environment.NewLine}"); $"Actual path string is {returnedPath} {Environment.NewLine}");
} }
@ -260,7 +236,7 @@ namespace Flow.Launcher.Test.Plugins
var resultString = QueryConstructor.RecursiveDirectoryConstraint(path); var resultString = QueryConstructor.RecursiveDirectoryConstraint(path);
// Then // Then
Assert.AreEqual(expectedString, resultString); ClassicAssert.AreEqual(expectedString, resultString);
} }
[SupportedOSPlatform("windows7.0")] [SupportedOSPlatform("windows7.0")]
@ -274,7 +250,7 @@ namespace Flow.Launcher.Test.Plugins
var resultString = DirectoryInfoSearch.ConstructSearchCriteria(path); var resultString = DirectoryInfoSearch.ConstructSearchCriteria(path);
// Then // Then
Assert.AreEqual(expectedString, resultString); ClassicAssert.AreEqual(expectedString, resultString);
} }
[TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "irrelevant", false, true, "c:\\somefolder\\someotherfolder\\")] [TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "irrelevant", false, true, "c:\\somefolder\\someotherfolder\\")]
@ -305,7 +281,7 @@ namespace Flow.Launcher.Test.Plugins
var result = ResultManager.GetPathWithActionKeyword(path, type, actionKeyword); var result = ResultManager.GetPathWithActionKeyword(path, type, actionKeyword);
// Then // Then
Assert.AreEqual(result, expectedResult); ClassicAssert.AreEqual(result, expectedResult);
} }
[TestCase("c:\\somefolder\\somefile", ResultType.File, "irrelevant", false, true, "e c:\\somefolder\\somefile")] [TestCase("c:\\somefolder\\somefile", ResultType.File, "irrelevant", false, true, "e c:\\somefolder\\somefile")]
@ -334,7 +310,7 @@ namespace Flow.Launcher.Test.Plugins
var result = ResultManager.GetPathWithActionKeyword(path, type, actionKeyword); var result = ResultManager.GetPathWithActionKeyword(path, type, actionKeyword);
// Then // Then
Assert.AreEqual(result, expectedResult); ClassicAssert.AreEqual(result, expectedResult);
} }
[TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "q", false, false, "q somefolder")] [TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "q", false, false, "q somefolder")]
@ -366,7 +342,7 @@ namespace Flow.Launcher.Test.Plugins
var result = ResultManager.GetAutoCompleteText(title, query, path, resultType); var result = ResultManager.GetAutoCompleteText(title, query, path, resultType);
// Then // Then
Assert.AreEqual(result, expectedResult); ClassicAssert.AreEqual(result, expectedResult);
} }
[TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "q", false, false, "q somefile")] [TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "q", false, false, "q somefile")]
@ -398,7 +374,7 @@ namespace Flow.Launcher.Test.Plugins
var result = ResultManager.GetAutoCompleteText(title, query, path, resultType); var result = ResultManager.GetAutoCompleteText(title, query, path, resultType);
// Then // Then
Assert.AreEqual(result, expectedResult); ClassicAssert.AreEqual(result, expectedResult);
} }
[TestCase(@"c:\foo", @"c:\foo", true)] [TestCase(@"c:\foo", @"c:\foo", true)]
@ -420,7 +396,7 @@ namespace Flow.Launcher.Test.Plugins
}; };
// When, Then // When, Then
Assert.AreEqual(expectedResult, comparator.Equals(result1, result2)); ClassicAssert.AreEqual(expectedResult, comparator.Equals(result1, result2));
} }
[TestCase(@"c:\foo\", @"c:\foo\")] [TestCase(@"c:\foo\", @"c:\foo\")]
@ -444,7 +420,7 @@ namespace Flow.Launcher.Test.Plugins
var hash2 = comparator.GetHashCode(result2); var hash2 = comparator.GetHashCode(result2);
// When, Then // When, Then
Assert.IsTrue(hash1 == hash2); ClassicAssert.IsTrue(hash1 == hash2);
} }
[TestCase(@"%appdata%", true)] [TestCase(@"%appdata%", true)]
@ -461,7 +437,7 @@ namespace Flow.Launcher.Test.Plugins
var result = EnvironmentVariables.HasEnvironmentVar(path); var result = EnvironmentVariables.HasEnvironmentVar(path);
// Then // Then
Assert.AreEqual(result, expectedResult); ClassicAssert.AreEqual(result, expectedResult);
} }
} }
} }

View file

@ -1,12 +1,11 @@
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Plugin; using Flow.Launcher.Plugin;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Text; using System.Text;
using System.Text.Json;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
namespace Flow.Launcher.Test.Plugins namespace Flow.Launcher.Test.Plugins
@ -40,13 +39,13 @@ namespace Flow.Launcher.Test.Plugins
Search = resultText Search = resultText
}, default); }, default);
Assert.IsNotNull(results); ClassicAssert.IsNotNull(results);
foreach (var result in results) foreach (var result in results)
{ {
Assert.IsNotNull(result); ClassicAssert.IsNotNull(result);
Assert.IsNotNull(result.AsyncAction); ClassicAssert.IsNotNull(result.AsyncAction);
Assert.IsNotNull(result.Title); ClassicAssert.IsNotNull(result.Title);
} }
} }
@ -56,12 +55,11 @@ namespace Flow.Launcher.Test.Plugins
new JsonRPCQueryResponseModel(0, new List<JsonRPCResult>()), new JsonRPCQueryResponseModel(0, new List<JsonRPCResult>()),
new JsonRPCQueryResponseModel(0, new List<JsonRPCResult> new JsonRPCQueryResponseModel(0, new List<JsonRPCResult>
{ {
new JsonRPCResult new()
{ {
Title = "Test1", SubTitle = "Test2" Title = "Test1", SubTitle = "Test2"
} }
}) })
}; };
} }
} }

View file

@ -1,7 +1,8 @@
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
using Flow.Launcher.Plugin.Url; using Flow.Launcher.Plugin.Url;
namespace Flow.Launcher.Test namespace Flow.Launcher.Test.Plugins
{ {
[TestFixture] [TestFixture]
public class UrlPluginTest public class UrlPluginTest
@ -10,23 +11,23 @@ namespace Flow.Launcher.Test
public void URLMatchTest() public void URLMatchTest()
{ {
var plugin = new Main(); var plugin = new Main();
Assert.IsTrue(plugin.IsURL("http://www.google.com")); ClassicAssert.IsTrue(plugin.IsURL("http://www.google.com"));
Assert.IsTrue(plugin.IsURL("https://www.google.com")); ClassicAssert.IsTrue(plugin.IsURL("https://www.google.com"));
Assert.IsTrue(plugin.IsURL("http://google.com")); ClassicAssert.IsTrue(plugin.IsURL("http://google.com"));
Assert.IsTrue(plugin.IsURL("www.google.com")); ClassicAssert.IsTrue(plugin.IsURL("www.google.com"));
Assert.IsTrue(plugin.IsURL("google.com")); ClassicAssert.IsTrue(plugin.IsURL("google.com"));
Assert.IsTrue(plugin.IsURL("http://localhost")); ClassicAssert.IsTrue(plugin.IsURL("http://localhost"));
Assert.IsTrue(plugin.IsURL("https://localhost")); ClassicAssert.IsTrue(plugin.IsURL("https://localhost"));
Assert.IsTrue(plugin.IsURL("http://localhost:80")); ClassicAssert.IsTrue(plugin.IsURL("http://localhost:80"));
Assert.IsTrue(plugin.IsURL("https://localhost:80")); ClassicAssert.IsTrue(plugin.IsURL("https://localhost:80"));
Assert.IsTrue(plugin.IsURL("http://110.10.10.10")); ClassicAssert.IsTrue(plugin.IsURL("http://110.10.10.10"));
Assert.IsTrue(plugin.IsURL("110.10.10.10")); ClassicAssert.IsTrue(plugin.IsURL("110.10.10.10"));
Assert.IsTrue(plugin.IsURL("ftp://110.10.10.10")); ClassicAssert.IsTrue(plugin.IsURL("ftp://110.10.10.10"));
Assert.IsFalse(plugin.IsURL("wwww")); ClassicAssert.IsFalse(plugin.IsURL("wwww"));
Assert.IsFalse(plugin.IsURL("wwww.c")); ClassicAssert.IsFalse(plugin.IsURL("wwww.c"));
Assert.IsFalse(plugin.IsURL("wwww.c")); ClassicAssert.IsFalse(plugin.IsURL("wwww.c"));
} }
} }
} }

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Legacy;
using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Plugin; using Flow.Launcher.Plugin;
@ -17,17 +18,17 @@ namespace Flow.Launcher.Test
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins); Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins);
Assert.AreEqual("> ping google.com -n 20 -6", q.RawQuery); ClassicAssert.AreEqual("> ping google.com -n 20 -6", q.RawQuery);
Assert.AreEqual("ping google.com -n 20 -6", q.Search, "Search should not start with the ActionKeyword."); ClassicAssert.AreEqual("ping google.com -n 20 -6", q.Search, "Search should not start with the ActionKeyword.");
Assert.AreEqual(">", q.ActionKeyword); ClassicAssert.AreEqual(">", q.ActionKeyword);
Assert.AreEqual(5, q.SearchTerms.Length, "The length of SearchTerms should match."); ClassicAssert.AreEqual(5, q.SearchTerms.Length, "The length of SearchTerms should match.");
Assert.AreEqual("ping", q.FirstSearch); ClassicAssert.AreEqual("ping", q.FirstSearch);
Assert.AreEqual("google.com", q.SecondSearch); ClassicAssert.AreEqual("google.com", q.SecondSearch);
Assert.AreEqual("-n", q.ThirdSearch); ClassicAssert.AreEqual("-n", q.ThirdSearch);
Assert.AreEqual("google.com -n 20 -6", q.SecondToEndSearch, "SecondToEndSearch should be trimmed of multiple whitespace characters"); ClassicAssert.AreEqual("google.com -n 20 -6", q.SecondToEndSearch, "SecondToEndSearch should be trimmed of multiple whitespace characters");
} }
[Test] [Test]
@ -40,11 +41,11 @@ namespace Flow.Launcher.Test
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins); Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins);
Assert.AreEqual("> ping google.com -n 20 -6", q.Search); ClassicAssert.AreEqual("> ping google.com -n 20 -6", q.Search);
Assert.AreEqual(q.Search, q.RawQuery, "RawQuery should be equal to Search."); ClassicAssert.AreEqual(q.Search, q.RawQuery, "RawQuery should be equal to Search.");
Assert.AreEqual(6, q.SearchTerms.Length, "The length of SearchTerms should match."); ClassicAssert.AreEqual(6, q.SearchTerms.Length, "The length of SearchTerms should match.");
Assert.AreNotEqual(">", q.ActionKeyword, "ActionKeyword should not match that of a disabled plugin."); ClassicAssert.AreNotEqual(">", q.ActionKeyword, "ActionKeyword should not match that of a disabled plugin.");
Assert.AreEqual("ping google.com -n 20 -6", q.SecondToEndSearch, "SecondToEndSearch should be trimmed of multiple whitespace characters"); ClassicAssert.AreEqual("ping google.com -n 20 -6", q.SecondToEndSearch, "SecondToEndSearch should be trimmed of multiple whitespace characters");
} }
[Test] [Test]
@ -52,13 +53,13 @@ namespace Flow.Launcher.Test
{ {
Query q = QueryBuilder.Build("file.txt file2 file3", new Dictionary<string, PluginPair>()); Query q = QueryBuilder.Build("file.txt file2 file3", new Dictionary<string, PluginPair>());
Assert.AreEqual("file.txt file2 file3", q.Search); ClassicAssert.AreEqual("file.txt file2 file3", q.Search);
Assert.AreEqual("", q.ActionKeyword); ClassicAssert.AreEqual("", q.ActionKeyword);
Assert.AreEqual("file.txt", q.FirstSearch); ClassicAssert.AreEqual("file.txt", q.FirstSearch);
Assert.AreEqual("file2", q.SecondSearch); ClassicAssert.AreEqual("file2", q.SecondSearch);
Assert.AreEqual("file3", q.ThirdSearch); ClassicAssert.AreEqual("file3", q.ThirdSearch);
Assert.AreEqual("file2 file3", q.SecondToEndSearch); ClassicAssert.AreEqual("file2 file3", q.SecondToEndSearch);
} }
} }
} }