Adding FxCop to Program Plugin Unit Tests (#5884)

* Adding FxCop to Microsoft.Plugin.Program.UnitTests

* CA1707: Identifiers should not contain underscores
https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1707?view=vs-2019

* CA1307: Specify StringComparison
https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1307?view=vs-2019

* CA1812: Avoid uninstantiated internal classes
https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1812?view=vs-2019

* More CA1707: Identifiers should not contain underscores fixes now that class is public

* More fixes for https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1812?view=vs-2019

List Repository and Win32ProgramRepository

* More CA1707: Identifiers should not contain underscores fixes now that class is public

ListRepository and Win32ProgramRepository tests

* Adding `ConfigureAwait(false)` and removing Assert.DoesNotThrowAsync as thowing an exception will fail the test anyway, and the DoesNotThrowAsync method can't be awaited.

Fix for CA2007: Do not directly await a Task (Consider calling ConfigureAwait on the task).

CS1998 This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

* Setting treat warning as errors to true for release and debug.
This commit is contained in:
ryanbodrug-microsoft
2020-08-12 10:03:34 -07:00
committed by GitHub
parent a0832d3fb6
commit db6e9b6962
6 changed files with 60 additions and 54 deletions

View File

@@ -12,11 +12,11 @@ using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage
{
[TestFixture]
class ListRepositoryTests
public class ListRepositoryTests
{
[Test]
public void Contains_ShouldReturnTrue_WhenListIsInitializedWithItem()
public void ContainsShouldReturnTrueWhenListIsInitializedWithItem()
{
//Arrange
var itemName = "originalItem1";
@@ -30,7 +30,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[Test]
public void Contains_ShouldReturnTrue_WhenListIsUpdatedWithAdd()
public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd()
{
//Arrange
IRepository<string> repository = new ListRepository<string>();
@@ -45,7 +45,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[Test]
public void Contains_ShouldReturnFalse_WhenListIsUpdatedWithRemove()
public void ContainsShouldReturnFalseWhenListIsUpdatedWithRemove()
{
//Arrange
var itemName = "originalItem1";
@@ -60,7 +60,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[Test]
public async Task Add_ShouldNotThrow_WhenBeingIterated()
public async Task AddShouldNotThrowWhenBeingIterated()
{
//Arrange
ListRepository<string> repository = new ListRepository<string>();
@@ -96,14 +96,11 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
});
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
Assert.DoesNotThrowAsync(async () =>
{
await Task.WhenAll(new Task[] { iterationTask, addTask });
});
await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false);
}
[Test]
public async Task Remove_ShouldNotThrow_WhenBeingIterated()
public async Task RemoveShouldNotThrowWhenBeingIterated()
{
//Arrange
ListRepository<string> repository = new ListRepository<string>();
@@ -139,10 +136,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
});
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
Assert.DoesNotThrowAsync(async () =>
{
await Task.WhenAll(new Task[] { iterationTask, addTask });
});
await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false);
}
}
}

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Microsoft.Plugin.Program.UnitTests.Storage
{
class PackageRepositoryTest
public class PackageRepositoryTest
{
}
}

View File

@@ -16,7 +16,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
using Win32Program = Program.Programs.Win32Program;
[TestFixture]
class Win32ProgramRepositoryTest
public class Win32ProgramRepositoryTest
{
List<IFileSystemWatcherWrapper> _fileSystemWatchers;
ProgramPluginSettings _settings = new ProgramPluginSettings();
@@ -37,7 +37,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("Name", "ExecutableName", "FullPath", "description1", "description2")]
public void Win32Repository_MustNotStoreDuplicates_WhileAddingItemsWithSameHashCode(string name, string exename, string fullPath, string description1, string description2)
public void Win32RepositoryMustNotStoreDuplicatesWhileAddingItemsWithSameHashCode(string name, string exename, string fullPath, string description1, string description2)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -71,7 +71,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("path.appref-ms")]
public void Win32ProgramRepository_MustCallOnAppCreatedForApprefApps_WhenCreatedEventIsRaised(string path)
public void Win32ProgramRepositoryMustCallOnAppCreatedForApprefAppsWhenCreatedEventIsRaised(string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -86,7 +86,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "path.appref-ms")]
public void Win32ProgramRepository_MustCallOnAppDeletedForApprefApps_WhenDeletedEventIsRaised(string directory, string path)
public void Win32ProgramRepositoryMustCallOnAppDeletedForApprefAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -104,7 +104,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "oldpath.appref-ms", "newpath.appref-ms")]
public void Win32ProgramRepository_MustCallOnAppRenamedForApprefApps_WhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
public void Win32ProgramRepositoryMustCallOnAppRenamedForApprefAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -127,7 +127,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("path.exe")]
public void Win32ProgramRepository_MustCallOnAppCreatedForExeApps_WhenCreatedEventIsRaised(string path)
public void Win32ProgramRepositoryMustCallOnAppCreatedForExeAppsWhenCreatedEventIsRaised(string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -147,7 +147,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "path.exe")]
public void Win32ProgramRepository_MustCallOnAppDeletedForExeApps_WhenDeletedEventIsRaised(string directory, string path)
public void Win32ProgramRepositoryMustCallOnAppDeletedForExeAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -170,7 +170,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "oldpath.appref-ms", "newpath.appref-ms")]
public void Win32ProgramRepository_MustCallOnAppRenamedForExeApps_WhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
public void Win32ProgramRepositoryMustCallOnAppRenamedForExeAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -198,7 +198,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("path.url")]
public void Win32ProgramRepository_MustCallOnAppChangedForUrlApps_WhenChangedEventIsRaised(string path)
public void Win32ProgramRepositoryMustCallOnAppChangedForUrlAppsWhenChangedEventIsRaised(string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -218,7 +218,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("path.url")]
public void Win32ProgramRepository_MustNotCreateUrlApp_WhenCreatedEventIsRaised(string path)
public void Win32ProgramRepositoryMustNotCreateUrlAppWhenCreatedEventIsRaised(string path)
{
// We are handing internet shortcut apps using the Changed event instead
@@ -241,7 +241,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
[TestCase("path.exe")]
[TestCase("path.lnk")]
[TestCase("path.appref-ms")]
public void Win32ProgramRepository_MustNotCreateAnyAppOtherThanUrlApp_WhenChangedEventIsRaised(string path)
public void Win32ProgramRepositoryMustNotCreateAnyAppOtherThanUrlAppWhenChangedEventIsRaised(string path)
{
// We are handing internet shortcut apps using the Changed event instead
@@ -267,7 +267,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "path.url")]
public void Win32ProgramRepository_MustCallOnAppDeletedForUrlApps_WhenDeletedEventIsRaised(string directory, string path)
public void Win32ProgramRepositoryMustCallOnAppDeletedForUrlAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -290,7 +290,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "oldpath.url", "newpath.url")]
public void Win32ProgramRepository_MustCallOnAppRenamedForUrlApps_WhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
public void Win32ProgramRepositoryMustCallOnAppRenamedForUrlAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -319,7 +319,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
[TestCase("path.lnk")]
public void Win32ProgramRepository_MustCallOnAppCreatedForLnkApps_WhenCreatedEventIsRaised(string path)
public void Win32ProgramRepositoryMustCallOnAppCreatedForLnkAppsWhenCreatedEventIsRaised(string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -339,7 +339,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "path.lnk")]
public void Win32ProgramRepository_MustCallOnAppDeletedForLnkApps_WhenDeletedEventIsRaised(string directory, string path)
public void Win32ProgramRepositoryMustCallOnAppDeletedForLnkAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
@@ -369,7 +369,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
[TestCase("directory", "oldpath.lnk", "path.lnk")]
public void Win32ProgramRepository_MustCallOnAppRenamedForLnkApps_WhenRenamedEventIsRaised(string directory, string oldpath, string path)
public void Win32ProgramRepositoryMustCallOnAppRenamedForLnkAppsWhenRenamedEventIsRaised(string directory, string oldpath, string path)
{
// Arrange
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);