mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
FxCopAnalyzer fixes for Wox.Test (#7312)
* Added InvarientCulture info (CA1305: Specify IFormatProvider) * Removed underscore from method names (CA1707: Identifiers should not contain underscores) * Marked members as static (CA1822: Mark members as static) * Removed initialization for DummyTestClass::IsFunctionCalled (CA1805: Do not initialize unnecessarily) * Replaced Count with Any (CA1827: Do not use Count/LongCount when Any can be used) * Changed WoxTest::DummyTestClass to private (CA1034: Nested types should not be visible) * Suppressed warnings for uninstantiated internal classes used as TestFixtures (CA1812: Avoid uninstantiated internal classes) * Enabled FxCopAnalyzer for Wox.Test * Added suppression message for CA1812 in GlobalSuppressions.cs and removed inline supression messages (CA1812: Avoid uninstantiated internal classes) * Changed InvariantCulture to Ordinal where appropriate * Addressing comments: Updated justification for CA1812 in GlobalSuppressions.cs (Avoid uninstantiated internal classes)
This commit is contained in:
@@ -45,3 +45,6 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Templates.Core.Locations.JunctionNativeMethods.ThrowLastWin32Error(System.String)", Scope = "member", Target = "Microsoft.Templates.Core.Locations.JunctionNativeMethods.#InternalGetTarget(Microsoft.Win32.SafeHandles.SafeFileHandle)", Justification = "Only used for local generation")]
|
||||
[assembly: SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Templates.Core.Locations.JunctionNativeMethods.ThrowLastWin32Error(System.String)", Scope = "member", Target = "Microsoft.Templates.Core.Locations.JunctionNativeMethods.#OpenReparsePoint(System.String,Microsoft.Templates.Core.Locations.JunctionNativeMethods+EFileAccess)", Justification = "Only used for local generation")]
|
||||
[assembly: SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Documents.InlineCollection.Add(System.String)", Scope = "member", Target = "Microsoft.Templates.UI.Extensions.TextBlockExtensions.#OnSequentialFlowStepChanged(System.Windows.DependencyObject,System.Windows.DependencyPropertyChangedEventArgs)", Justification = "No text here")]
|
||||
|
||||
// FxCop warning suppression for uninstantiated TestFixture classes
|
||||
[assembly: SuppressMessage("Microsoft.Performance", "CA1812: Avoid uninstantiated internal classes", Scope = "module", Justification = "CA1812 will be thrown for every file in the test project. This is mentioned here: dotnet/roslyn-analyzers#1830")]
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Wox.Infrastructure;
|
||||
@@ -23,7 +24,7 @@ namespace Wox.Test
|
||||
private const string OneOneOneOne = "1111";
|
||||
private const string MicrosoftSqlServerManagementStudio = "Microsoft SQL Server Management Studio";
|
||||
|
||||
public List<string> GetSearchStrings()
|
||||
public static List<string> GetSearchStrings()
|
||||
=> new List<string>
|
||||
{
|
||||
Chrome,
|
||||
@@ -36,7 +37,7 @@ namespace Wox.Test
|
||||
OneOneOneOne,
|
||||
};
|
||||
|
||||
public List<int> GetPrecisionScores()
|
||||
public static List<int> GetPrecisionScores()
|
||||
{
|
||||
var listToReturn = new List<int>();
|
||||
|
||||
@@ -117,7 +118,8 @@ namespace Wox.Test
|
||||
Debug.WriteLine("SEARCHTERM: " + searchTerm + ", GreaterThanSearchPrecisionScore: " + precisionScore);
|
||||
foreach (var item in filteredResult)
|
||||
{
|
||||
Debug.WriteLine("SCORE: " + item.Score.ToString() + ", FoundString: " + item.Title);
|
||||
// Using InvariantCulture since this is used for testing
|
||||
Debug.WriteLine("SCORE: " + item.Score.ToString(CultureInfo.InvariantCulture) + ", FoundString: " + item.Title);
|
||||
}
|
||||
|
||||
Debug.WriteLine("###############################################");
|
||||
@@ -128,7 +130,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[TestCase("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
|
||||
public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(string queryString, string firstName, string firstDescription, string firstExecutableName, string secondName, string secondDescription, string secondExecutableName)
|
||||
public void WhenMultipleResultsExactMatchingResultShouldHaveGreatestScore(string queryString, string firstName, string firstDescription, string firstExecutableName, string secondName, string secondDescription, string secondExecutableName)
|
||||
{
|
||||
// Act
|
||||
var matcher = new StringMatcher();
|
||||
@@ -228,7 +230,7 @@ namespace Wox.Test
|
||||
|
||||
[TestCase("Windows Terminal", "Windows_Terminal", "term")]
|
||||
[TestCase("Windows Terminal", "WindowsTerminal", "term")]
|
||||
public void FuzzyMatchingScore_ShouldBeHigher_WhenPreceedingCharacterIsSpace(string firstCompareStr, string secondCompareStr, string query)
|
||||
public void FuzzyMatchingScoreShouldBeHigherWhenPreceedingCharacterIsSpace(string firstCompareStr, string secondCompareStr, string query)
|
||||
{
|
||||
// Arrange
|
||||
var matcher = new StringMatcher();
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Wox.Test
|
||||
[TestCase(null, "dummyQueryText", "dummyTitle", "dummyQueryText")]
|
||||
[TestCase(null, null, "dummyTitle", "dummyTitle")]
|
||||
[TestCase(null, "", "dummyTitle", "dummyTitle")]
|
||||
public void QueryForPlugin_SetsActionKeyword_WhenQueryTextDisplayIsEmpty(string actionKeyword, string queryTextDisplay, string title, string expectedResult)
|
||||
public void QueryForPluginSetsActionKeywordWhenQueryTextDisplayIsEmpty(string actionKeyword, string queryTextDisplay, string title, string expectedResult)
|
||||
{
|
||||
// Arrange
|
||||
var query = new Query
|
||||
|
||||
@@ -18,14 +18,14 @@ namespace Wox.Test.Plugins
|
||||
[TestFixture]
|
||||
public class WindowsIndexerTest
|
||||
{
|
||||
private WindowsSearchAPI GetWindowsSearchAPI()
|
||||
private static WindowsSearchAPI GetWindowsSearchAPI()
|
||||
{
|
||||
var mock = new Mock<ISearch>();
|
||||
mock.Setup(x => x.Query("dummy-connection-string", "dummy-query")).Returns(new List<OleDBResult>());
|
||||
return new WindowsSearchAPI(mock.Object);
|
||||
}
|
||||
|
||||
private ISearchManager GetMockSearchManager()
|
||||
private static ISearchManager GetMockSearchManager()
|
||||
{
|
||||
var sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE CONTAINS(System.FileName,'\"FilePath\"',1033) AND scope='file:' ORDER BY System.DateModified DESC";
|
||||
var mockSearchManager = new Mock<ISearchManager>();
|
||||
@@ -40,7 +40,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitQueryHelper_ShouldInitialize_WhenFunctionIsCalled()
|
||||
public void InitQueryHelperShouldInitializeWhenFunctionIsCalled()
|
||||
{
|
||||
// Arrange
|
||||
int maxCount = 10;
|
||||
@@ -57,7 +57,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternIsAsterisk()
|
||||
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternIsAsterisk()
|
||||
{
|
||||
// Arrange
|
||||
ISearchQueryHelper queryHelper;
|
||||
@@ -70,12 +70,13 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("LIKE"));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("LIKE", StringComparison.Ordinal));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternContainsAsterisk()
|
||||
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsAsterisk()
|
||||
{
|
||||
// Arrange
|
||||
ISearchQueryHelper queryHelper;
|
||||
@@ -88,12 +89,13 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE"));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE", StringComparison.Ordinal));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternContainsPercent()
|
||||
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsPercent()
|
||||
{
|
||||
// Arrange
|
||||
ISearchQueryHelper queryHelper;
|
||||
@@ -106,12 +108,13 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE"));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE", StringComparison.Ordinal));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternContainsUnderScore()
|
||||
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsUnderScore()
|
||||
{
|
||||
// Arrange
|
||||
ISearchQueryHelper queryHelper;
|
||||
@@ -124,12 +127,13 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE"));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE", StringComparison.Ordinal));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternContainsQuestionMark()
|
||||
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsQuestionMark()
|
||||
{
|
||||
// Arrange
|
||||
ISearchQueryHelper queryHelper;
|
||||
@@ -142,12 +146,13 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE"));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE", StringComparison.Ordinal));
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternDoesNotContainSplSymbols()
|
||||
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternDoesNotContainSplSymbols()
|
||||
{
|
||||
// Arrange
|
||||
ISearchQueryHelper queryHelper;
|
||||
@@ -160,12 +165,13 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("LIKE"));
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("Contains"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("LIKE", StringComparison.Ordinal));
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldReturnResults_WhenSearchWasExecuted()
|
||||
public void WindowsSearchAPIShouldReturnResultsWhenSearchWasExecuted()
|
||||
{
|
||||
// Arrange
|
||||
OleDBResult unHiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", "file1.txt" });
|
||||
@@ -186,7 +192,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldNotReturnResultsWithNullValue_WhenDbResultHasANullColumn()
|
||||
public void WindowsSearchAPIShouldNotReturnResultsWithNullValueWhenDbResultHasANullColumn()
|
||||
{
|
||||
// Arrange
|
||||
OleDBResult unHiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", DBNull.Value });
|
||||
@@ -207,7 +213,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldRequestNormalRequest_WhenDisplayHiddenFilesIsTrue()
|
||||
public void WindowsSearchAPIShouldRequestNormalRequestWhenDisplayHiddenFilesIsTrue()
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "notepad";
|
||||
@@ -220,11 +226,12 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldRequestFilteredRequest_WhenDisplayHiddenFilesIsFalse()
|
||||
public void WindowsSearchAPIShouldRequestFilteredRequestWhenDisplayHiddenFilesIsFalse()
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "notepad";
|
||||
@@ -237,11 +244,12 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldRequestNormalRequest_WhenDisplayHiddenFilesIsTrue_AfterRuntimeSwap()
|
||||
public void WindowsSearchAPIShouldRequestNormalRequestWhenDisplayHiddenFilesIsTrueAfterRuntimeSwap()
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "notepad";
|
||||
@@ -257,14 +265,15 @@ namespace Wox.Test.Plugins
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2"));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[TestCase("item.exe")]
|
||||
[TestCase("item.bat")]
|
||||
[TestCase("item.appref-ms")]
|
||||
[TestCase("item.lnk")]
|
||||
public void LoadContextMenus_MustLoadAllItems_WhenFileIsAnApp(string path)
|
||||
public void LoadContextMenusMustLoadAllItemsWhenFileIsAnApp(string path)
|
||||
{
|
||||
// Arrange
|
||||
var mockapi = new Mock<IPublicAPI>();
|
||||
@@ -292,7 +301,7 @@ namespace Wox.Test.Plugins
|
||||
[TestCase("item.xls")]
|
||||
[TestCase("item.ppt")]
|
||||
[TestCase("C:/DummyFile.cs")]
|
||||
public void LoadContextMenus_MustNotLoadRunAsAdmin_WhenFileIsAnNotApp(string path)
|
||||
public void LoadContextMenusMustNotLoadRunAsAdminWhenFileIsAnNotApp(string path)
|
||||
{
|
||||
// Arrange
|
||||
var mockapi = new Mock<IPublicAPI>();
|
||||
@@ -317,7 +326,7 @@ namespace Wox.Test.Plugins
|
||||
|
||||
[TestCase("C:/DummyFolder")]
|
||||
[TestCase("TestFolder")]
|
||||
public void LoadContextMenus_MustNotLoadRunAsAdminAndOpenContainingFolder_ForFolder(string path)
|
||||
public void LoadContextMenusMustNotLoadRunAsAdminAndOpenContainingFolderForFolder(string path)
|
||||
{
|
||||
// Arrange
|
||||
var mockapi = new Mock<IPublicAPI>();
|
||||
@@ -343,7 +352,7 @@ namespace Wox.Test.Plugins
|
||||
[TestCase(0, true, ExpectedResult = false)]
|
||||
[TestCase(1, false, ExpectedResult = false)]
|
||||
[TestCase(1, true, ExpectedResult = false)]
|
||||
public bool DriveDetection_MustDisplayWarning_WhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus)
|
||||
public bool DriveDetectionMustDisplayWarningWhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus)
|
||||
{
|
||||
// Arrange
|
||||
var mockRegistry = new Mock<IRegistryWrapper>();
|
||||
@@ -357,7 +366,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SimplifyQuery_ShouldRemoveLikeQuery_WhenSQLQueryUsesLIKESyntax()
|
||||
public void SimplifyQueryShouldRemoveLikeQueryWhenSQLQueryUsesLIKESyntax()
|
||||
{
|
||||
// Arrange
|
||||
string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE (System.FileName LIKE 'abcd.%' OR CONTAINS(System.FileName,'\"abcd.*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC";
|
||||
@@ -372,7 +381,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SimplifyQuery_ShouldReturnArgument_WhenSQLQueryDoesNotUseLIKESyntax()
|
||||
public void SimplifyQueryShouldReturnArgumentWhenSQLQueryDoesNotUseLIKESyntax()
|
||||
{
|
||||
// Arrange
|
||||
string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE CONTAINS(System.FileName,'\"abcd*\"',1033) AND scope='file:' ORDER BY System.DateModified DESC";
|
||||
@@ -385,7 +394,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SimplifyQuery_ShouldRemoveAllOccurrencesOfLikeQuery_WhenSQLQueryUsesLIKESyntaxMultipleTimes()
|
||||
public void SimplifyQueryShouldRemoveAllOccurrencesOfLikeQueryWhenSQLQueryUsesLIKESyntaxMultipleTimes()
|
||||
{
|
||||
// Arrange
|
||||
string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\", \"System.FileExtension\" FROM \"SystemIndex\" WHERE (System.FileName LIKE 'ab.%' OR CONTAINS(System.FileName,'\"ab.*\"',1033)) AND (System.FileExtension LIKE '.cd%' OR CONTAINS(System.FileName,'\".cd*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC";
|
||||
@@ -400,7 +409,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SimplifyQuery_ShouldRemoveLikeQuery_WhenSQLQueryUsesLIKESyntaxAndContainsEscapedSingleQuotationMarks()
|
||||
public void SimplifyQueryShouldRemoveLikeQueryWhenSQLQueryUsesLIKESyntaxAndContainsEscapedSingleQuotationMarks()
|
||||
{
|
||||
// Arrange
|
||||
string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE (System.FileName LIKE '''ab.cd''%' OR CONTAINS(System.FileName,'\"'ab.cd'*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC";
|
||||
@@ -415,7 +424,7 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldReturnEmptyResults_WhenIsFullQueryIsTrueAndTheQueryDoesNotRequireLIKESyntax()
|
||||
public void WindowsSearchAPIShouldReturnEmptyResultsWhenIsFullQueryIsTrueAndTheQueryDoesNotRequireLIKESyntax()
|
||||
{
|
||||
// Arrange
|
||||
OleDBResult file1 = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", DBNull.Value });
|
||||
@@ -431,7 +440,7 @@ namespace Wox.Test.Plugins
|
||||
var windowsSearchAPIResults = api.Search("file", searchManager, true);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(windowsSearchAPIResults.Count() == 0);
|
||||
Assert.IsTrue(!windowsSearchAPIResults.Any());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Wox.Core.Plugin;
|
||||
@@ -11,15 +12,16 @@ namespace Wox.Test
|
||||
{
|
||||
public class QueryBuilderTest
|
||||
{
|
||||
private bool AreEqual(Query firstQuery, Query secondQuery)
|
||||
private static bool AreEqual(Query firstQuery, Query secondQuery)
|
||||
{
|
||||
return firstQuery.ActionKeyword.Equals(secondQuery.ActionKeyword)
|
||||
&& firstQuery.Search.Equals(secondQuery.Search)
|
||||
&& firstQuery.RawQuery.Equals(secondQuery.RawQuery);
|
||||
// Using Ordinal since this is used internally
|
||||
return firstQuery.ActionKeyword.Equals(secondQuery.ActionKeyword, StringComparison.Ordinal)
|
||||
&& firstQuery.Search.Equals(secondQuery.Search, StringComparison.Ordinal)
|
||||
&& firstQuery.RawQuery.Equals(secondQuery.RawQuery, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuilder_ShouldRemoveExtraSpaces_ForNonGlobalPlugin()
|
||||
public void QueryBuilderShouldRemoveExtraSpacesForNonGlobalPlugin()
|
||||
{
|
||||
// Arrange
|
||||
var nonGlobalPlugins = new Dictionary<string, PluginPair>
|
||||
@@ -36,7 +38,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuilder_ShouldRemoveExtraSpaces_ForDisabledNonGlobalPlugin()
|
||||
public void QueryBuilderShouldRemoveExtraSpacesForDisabledNonGlobalPlugin()
|
||||
{
|
||||
// Arrange
|
||||
var nonGlobalPlugins = new Dictionary<string, PluginPair>
|
||||
@@ -53,7 +55,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuilder_ShouldRemoveExtraSpaces_ForGlobalPlugin()
|
||||
public void QueryBuilderShouldRemoveExtraSpacesForGlobalPlugin()
|
||||
{
|
||||
// Arrange
|
||||
string searchQuery = "file.txt file2 file3";
|
||||
@@ -66,7 +68,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuilder_ShouldGenerateSameQuery_IfEitherActionKeywordOrActionKeywordsListIsSet()
|
||||
public void QueryBuilderShouldGenerateSameQueryIfEitherActionKeywordOrActionKeywordsListIsSet()
|
||||
{
|
||||
// Arrange
|
||||
string searchQuery = "> query";
|
||||
@@ -98,7 +100,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuilder_ShouldGenerateCorrectQueries_ForPluginsWithMultipleActionKeywords()
|
||||
public void QueryBuilderShouldGenerateCorrectQueriesForPluginsWithMultipleActionKeywords()
|
||||
{
|
||||
// Arrange
|
||||
var plugin = new PluginPair { Metadata = new PluginMetadata { ActionKeywords = new List<string> { "a", "b" } } };
|
||||
@@ -124,7 +126,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuild_ShouldGenerateSameSearchQuery_WithOrWithoutSpaceAfterActionKeyword()
|
||||
public void QueryBuildShouldGenerateSameSearchQueryWithOrWithoutSpaceAfterActionKeyword()
|
||||
{
|
||||
// Arrange
|
||||
var plugin = new PluginPair { Metadata = new PluginMetadata { ActionKeywords = new List<string> { "a" } } };
|
||||
@@ -144,12 +146,13 @@ namespace Wox.Test
|
||||
var secondQuery = secondPluginQueryPairs.GetValueOrDefault(plugin);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(firstQuery.Search.Equals(secondQuery.Search));
|
||||
Assert.IsTrue(firstQuery.ActionKeyword.Equals(secondQuery.ActionKeyword));
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsTrue(firstQuery.Search.Equals(secondQuery.Search, StringComparison.Ordinal));
|
||||
Assert.IsTrue(firstQuery.ActionKeyword.Equals(secondQuery.ActionKeyword, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuild_ShouldGenerateCorrectQuery_ForPluginsWhoseActionKeywordsHaveSamePrefix()
|
||||
public void QueryBuildShouldGenerateCorrectQueryForPluginsWhoseActionKeywordsHaveSamePrefix()
|
||||
{
|
||||
// Arrange
|
||||
string searchQuery = "abcdefgh";
|
||||
@@ -174,7 +177,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueryBuilder_ShouldSetTermsCorrently_WhenCalled()
|
||||
public void QueryBuilderShouldSetTermsCorrentlyWhenCalled()
|
||||
{
|
||||
// Arrange
|
||||
string searchQuery = "abcd efgh";
|
||||
@@ -194,8 +197,9 @@ namespace Wox.Test
|
||||
var secondQuery = pluginQueryPairs.GetValueOrDefault(secondPlugin);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(firstQuery.Terms[0].Equals("cd") && firstQuery.Terms[1].Equals("efgh") && firstQuery.Terms.Length == 2);
|
||||
Assert.IsTrue(secondQuery.Terms[0].Equals("efgh") && secondQuery.Terms.Length == 1);
|
||||
// Using Ordinal since this is used internally
|
||||
Assert.IsTrue(firstQuery.Terms[0].Equals("cd", StringComparison.Ordinal) && firstQuery.Terms[1].Equals("efgh", StringComparison.Ordinal) && firstQuery.Terms.Length == 2);
|
||||
Assert.IsTrue(secondQuery.Terms[0].Equals("efgh", StringComparison.Ordinal) && secondQuery.Terms.Length == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Moq" Version="4.14.5" />
|
||||
<PackageReference Include="nunit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace Wox.Test
|
||||
public class WoxTest
|
||||
{
|
||||
// A Dummy class to test that OnPropertyChanged() is called while we set the variable
|
||||
public class DummyTestClass : BaseModel
|
||||
private class DummyTestClass : BaseModel
|
||||
{
|
||||
public bool IsFunctionCalled { get; set; } = false;
|
||||
public bool IsFunctionCalled { get; set; }
|
||||
|
||||
private ICommand _item;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Wox.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyVariable_MustCallOnPropertyChanged_WhenSet()
|
||||
public void AnyVariableMustCallOnPropertyChangedWhenSet()
|
||||
{
|
||||
// Arrange
|
||||
DummyTestClass testClass = new DummyTestClass();
|
||||
|
||||
Reference in New Issue
Block a user