diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/UWPTests.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/UWPTests.cs index 1d9c519291..3502ef727e 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/UWPTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/UWPTests.cs @@ -13,39 +13,36 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs [TestFixture] public class UWPTests { - static readonly PackageWrapper developmentModeApp = new PackageWrapper( + private static readonly PackageWrapper DevelopmentModeApp = new PackageWrapper( "DevelopmentApp", "DevelopmentApp", "DevelopmentApp", false, true, - "AppxManifests/DevelopmentApp" - ); + "AppxManifests/DevelopmentApp"); - static readonly PackageWrapper frameworkApp = new PackageWrapper( + private static readonly PackageWrapper FrameworkApp = new PackageWrapper( "FrameworkApp", "FrameworkApp", "FrameworkApp", true, false, - "AppxManifests/FrameworkApp" - ); + "AppxManifests/FrameworkApp"); - static readonly PackageWrapper packagedApp = new PackageWrapper( + private static readonly PackageWrapper PackagedApp = new PackageWrapper( "PackagedApp", "PackagedApp", "PackagedApp", false, false, - "AppxManifests/PackagedApp" - ); + "AppxManifests/PackagedApp"); [Test] public void AllShouldReturnPackagesWithDevelopmentModeWhenCalled() { // Arrange Main._settings = new ProgramPluginSettings(); - List packages = new List() { developmentModeApp, packagedApp }; + List packages = new List() { DevelopmentModeApp, PackagedApp }; var mock = new Mock(); mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages); UWP.PackageManagerWrapper = mock.Object; @@ -64,7 +61,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs { // Arrange Main._settings = new ProgramPluginSettings(); - List packages = new List() { frameworkApp, packagedApp }; + List packages = new List() { FrameworkApp, PackagedApp }; var mock = new Mock(); mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages); UWP.PackageManagerWrapper = mock.Object; diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/Win32Tests.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/Win32Tests.cs index 20a1f1fc10..7b7f70e17c 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/Win32Tests.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/Win32Tests.cs @@ -17,7 +17,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs [TestFixture] public class Win32Tests { - static Win32Program notepad_appdata = new Win32Program + private static Win32Program notepad_appdata = new Win32Program { Name = "Notepad", ExecutableName = "notepad.exe", @@ -26,7 +26,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program notepad_users = new Win32Program + private static Win32Program notepad_users = new Win32Program { Name = "Notepad", ExecutableName = "notepad.exe", @@ -35,7 +35,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program azure_command_prompt = new Win32Program + private static Win32Program azure_command_prompt = new Win32Program { Name = "Microsoft Azure Command Prompt - v2.9", ExecutableName = "cmd.exe", @@ -44,7 +44,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program visual_studio_command_prompt = new Win32Program + private static Win32Program visual_studio_command_prompt = new Win32Program { Name = "x64 Native Tools Command Prompt for VS 2019", ExecutableName = "cmd.exe", @@ -53,7 +53,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program command_prompt = new Win32Program + private static Win32Program command_prompt = new Win32Program { Name = "Command Prompt", ExecutableName = "cmd.exe", @@ -62,7 +62,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program file_explorer = new Win32Program + private static Win32Program file_explorer = new Win32Program { Name = "File Explorer", ExecutableName = "File Explorer.lnk", @@ -71,7 +71,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program wordpad = new Win32Program + private static Win32Program wordpad = new Win32Program { Name = "Wordpad", ExecutableName = "wordpad.exe", @@ -80,7 +80,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program wordpad_duplicate = new Win32Program + private static Win32Program wordpad_duplicate = new Win32Program { Name = "WORDPAD", ExecutableName = "WORDPAD.EXE", @@ -89,7 +89,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program twitter_pwa = new Win32Program + private static Win32Program twitter_pwa = new Win32Program { Name = "Twitter", FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome_proxy.exe", @@ -98,7 +98,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 0, }; - static Win32Program pinned_webpage = new Win32Program + private static Win32Program pinned_webpage = new Win32Program { Name = "Web page", FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe", @@ -107,7 +107,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 0, }; - static Win32Program edge_named_pinned_webpage = new Win32Program + private static Win32Program edge_named_pinned_webpage = new Win32Program { Name = "edge - Bing", FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe", @@ -116,7 +116,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 0, }; - static Win32Program msedge = new Win32Program + private static Win32Program msedge = new Win32Program { Name = "Microsoft Edge", ExecutableName = "msedge.exe", @@ -125,7 +125,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program chrome = new Win32Program + private static Win32Program chrome = new Win32Program { Name = "Google Chrome", ExecutableName = "chrome.exe", @@ -134,7 +134,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program dummy_proxy_app = new Win32Program + private static Win32Program dummy_proxy_app = new Win32Program { Name = "Proxy App", ExecutableName = "test_proxy.exe", @@ -143,7 +143,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 2, }; - static Win32Program cmd_run_command = new Win32Program + private static Win32Program cmd_run_command = new Win32Program { Name = "cmd", ExecutableName = "cmd.exe", @@ -152,7 +152,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 3, // Run command }; - static Win32Program cmder_run_command = new Win32Program + private static Win32Program cmder_run_command = new Win32Program { Name = "Cmder", Description = "Cmder: Lovely Console Emulator", @@ -162,7 +162,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 3, // Run command }; - static Win32Program dummy_internetShortcut_app = new Win32Program + private static Win32Program dummy_internetShortcut_app = new Win32Program { Name = "Shop Titans", ExecutableName = "Shop Titans.url", @@ -172,7 +172,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs AppType = 1, }; - static Win32Program dummy_internetShortcut_app_duplicate = new Win32Program + private static Win32Program dummy_internetShortcut_app_duplicate = new Win32Program { Name = "Shop Titans", ExecutableName = "Shop Titans.url", @@ -186,9 +186,11 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs public void DedupFunctionWhenCalledMustRemoveDuplicateNotepads() { // Arrange - List prgms = new List(); - prgms.Add(notepad_appdata); - prgms.Add(notepad_users); + List prgms = new List + { + notepad_appdata, + notepad_users + }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); @@ -201,9 +203,11 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs public void DedupFunctionWhenCalledMustRemoveInternetShortcuts() { // Arrange - List prgms = new List(); - prgms.Add(dummy_internetShortcut_app); - prgms.Add(dummy_internetShortcut_app_duplicate); + List prgms = new List + { + dummy_internetShortcut_app, + dummy_internetShortcut_app_duplicate + }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); @@ -216,8 +220,10 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs public void DedupFunctionWhenCalledMustNotRemovelnkWhichdoesNotHaveExe() { // Arrange - List prgms = new List(); - prgms.Add(file_explorer); + List prgms = new List + { + file_explorer + }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); @@ -230,9 +236,11 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs public void DedupFunctionMustRemoveDuplicatesForExeExtensionsWithoutLnkResolvedPath() { // Arrange - List prgms = new List(); - prgms.Add(wordpad); - prgms.Add(wordpad_duplicate); + List prgms = new List + { + wordpad, + wordpad_duplicate + }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); @@ -246,10 +254,12 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs public void DedupFunctionMustNotRemoveProgramsWithSameExeNameAndFullPath() { // Arrange - List prgms = new List(); - prgms.Add(azure_command_prompt); - prgms.Add(visual_studio_command_prompt); - prgms.Add(command_prompt); + List prgms = new List + { + azure_command_prompt, + visual_studio_command_prompt, + command_prompt + }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); @@ -328,6 +338,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs { return edge_named_pinned_webpage.FilterWebApplication(query); } + // unreachable code return true; } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ListRepositoryTests.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ListRepositoryTests.cs index c663f9d077..f203b13099 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ListRepositoryTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ListRepositoryTests.cs @@ -11,7 +11,6 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage [TestFixture] public class ListRepositoryTests { - [Test] public void ContainsShouldReturnTrueWhenListIsInitializedWithItem() { @@ -76,11 +75,10 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage foreach (var item in repository) { // keep iterating - } + --remainingIterations; } - }); // Act - Insert on another thread @@ -116,11 +114,10 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage foreach (var item in repository) { // keep iterating - } + --remainingIterations; } - }); // Act - Remove on another thread diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs index a98df8b97e..57e4c43219 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs @@ -2,7 +2,6 @@ // 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 System.Diagnostics; using System.IO; @@ -13,18 +12,17 @@ using Moq; using NUnit.Framework; using Wox.Infrastructure.FileSystemHelper; using Wox.Infrastructure.Storage; +using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program; namespace Microsoft.Plugin.Program.UnitTests.Storage { - using Win32Program = Program.Programs.Win32Program; - [TestFixture] public class Win32ProgramRepositoryTest { - List _fileSystemWatchers; - ProgramPluginSettings _settings = new ProgramPluginSettings(); - string[] _pathsToWatch = new string[] { "location1", "location2" }; - List> _fileSystemMocks; + private List _fileSystemWatchers; + private ProgramPluginSettings _settings = new ProgramPluginSettings(); + private string[] _pathsToWatch = new string[] { "location1", "location2" }; + private List> _fileSystemMocks; [SetUp] public void SetFileSystemWatchers() @@ -259,7 +257,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage // ShellLinkHelper must be mocked for lnk applications var mockShellLink = new Mock(); - mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(String.Empty); + mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(string.Empty); Win32Program.Helper = mockShellLink.Object; // Act @@ -320,7 +318,6 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage Assert.IsFalse(_win32ProgramRepository.Contains(olditem)); } - [TestCase("path.lnk")] public void Win32ProgramRepositoryMustCallOnAppCreatedForLnkAppsWhenCreatedEventIsRaised(string path) { @@ -330,7 +327,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage // ShellLinkHelper must be mocked for lnk applications var mockShellLink = new Mock(); - mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(String.Empty); + mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(string.Empty); Win32Program.Helper = mockShellLink.Object; // Act @@ -350,7 +347,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage // ShellLinkHelper must be mocked for lnk applications var mockShellLink = new Mock(); - mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(String.Empty); + mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(string.Empty); Win32Program.Helper = mockShellLink.Object; string fullPath = directory + "\\" + path; @@ -383,7 +380,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage // ShellLinkHelper must be mocked for lnk applications var mockShellLink = new Mock(); - mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(String.Empty); + mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny())).Returns(string.Empty); Win32Program.Helper = mockShellLink.Object; // old item and new item are the actual items when they are in existence