mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02: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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user