mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 23:19:13 +08:00
Fix all file naming tweaks (#5945)
This commit is contained in:
parent
e02977edc0
commit
38b0d427f8
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
@ -46,7 +46,7 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<!--<ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
@ -60,5 +60,5 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>-->
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -17,7 +17,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
[TestFixture]
|
||||
public class Win32Tests
|
||||
{
|
||||
private static Win32Program notepad_appdata = new Win32Program
|
||||
private static readonly Win32Program _notepadAppdata = new Win32Program
|
||||
{
|
||||
Name = "Notepad",
|
||||
ExecutableName = "notepad.exe",
|
||||
@ -26,7 +26,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program notepad_users = new Win32Program
|
||||
private static readonly Win32Program _notepadUsers = new Win32Program
|
||||
{
|
||||
Name = "Notepad",
|
||||
ExecutableName = "notepad.exe",
|
||||
@ -35,7 +35,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program azure_command_prompt = new Win32Program
|
||||
private static readonly Win32Program _azureCommandPrompt = new Win32Program
|
||||
{
|
||||
Name = "Microsoft Azure Command Prompt - v2.9",
|
||||
ExecutableName = "cmd.exe",
|
||||
@ -44,7 +44,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program visual_studio_command_prompt = new Win32Program
|
||||
private static readonly Win32Program _visualStudioCommandPrompt = 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,
|
||||
};
|
||||
|
||||
private static Win32Program command_prompt = new Win32Program
|
||||
private static readonly Win32Program _commandPrompt = new Win32Program
|
||||
{
|
||||
Name = "Command Prompt",
|
||||
ExecutableName = "cmd.exe",
|
||||
@ -62,7 +62,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program file_explorer = new Win32Program
|
||||
private static readonly Win32Program _fileExplorer = new Win32Program
|
||||
{
|
||||
Name = "File Explorer",
|
||||
ExecutableName = "File Explorer.lnk",
|
||||
@ -71,7 +71,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program wordpad = new Win32Program
|
||||
private static readonly Win32Program _wordpad = new Win32Program
|
||||
{
|
||||
Name = "Wordpad",
|
||||
ExecutableName = "wordpad.exe",
|
||||
@ -80,7 +80,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program wordpad_duplicate = new Win32Program
|
||||
private static readonly Win32Program _wordpadDuplicate = new Win32Program
|
||||
{
|
||||
Name = "WORDPAD",
|
||||
ExecutableName = "WORDPAD.EXE",
|
||||
@ -89,7 +89,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program twitter_pwa = new Win32Program
|
||||
private static readonly Win32Program _twitterChromePwa = 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,
|
||||
};
|
||||
|
||||
private static Win32Program pinned_webpage = new Win32Program
|
||||
private static readonly Win32Program _pinnedWebpage = 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,
|
||||
};
|
||||
|
||||
private static Win32Program edge_named_pinned_webpage = new Win32Program
|
||||
private static readonly Win32Program _edgeNamedPinnedWebpage = 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,
|
||||
};
|
||||
|
||||
private static Win32Program msedge = new Win32Program
|
||||
private static readonly Win32Program _msedge = new Win32Program
|
||||
{
|
||||
Name = "Microsoft Edge",
|
||||
ExecutableName = "msedge.exe",
|
||||
@ -125,7 +125,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program chrome = new Win32Program
|
||||
private static readonly Win32Program _chrome = new Win32Program
|
||||
{
|
||||
Name = "Google Chrome",
|
||||
ExecutableName = "chrome.exe",
|
||||
@ -134,7 +134,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program dummy_proxy_app = new Win32Program
|
||||
private static readonly Win32Program _dummyProxyApp = new Win32Program
|
||||
{
|
||||
Name = "Proxy App",
|
||||
ExecutableName = "test_proxy.exe",
|
||||
@ -143,7 +143,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2,
|
||||
};
|
||||
|
||||
private static Win32Program cmd_run_command = new Win32Program
|
||||
private static readonly Win32Program _cmdRunCommand = new Win32Program
|
||||
{
|
||||
Name = "cmd",
|
||||
ExecutableName = "cmd.exe",
|
||||
@ -152,7 +152,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 3, // Run command
|
||||
};
|
||||
|
||||
private static Win32Program cmder_run_command = new Win32Program
|
||||
private static readonly Win32Program _cmderRunCommand = new Win32Program
|
||||
{
|
||||
Name = "Cmder",
|
||||
Description = "Cmder: Lovely Console Emulator",
|
||||
@ -162,7 +162,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 3, // Run command
|
||||
};
|
||||
|
||||
private static Win32Program dummy_internetShortcut_app = new Win32Program
|
||||
private static readonly Win32Program _dummyInternetShortcutApp = new Win32Program
|
||||
{
|
||||
Name = "Shop Titans",
|
||||
ExecutableName = "Shop Titans.url",
|
||||
@ -172,7 +172,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 1,
|
||||
};
|
||||
|
||||
private static Win32Program dummy_internetShortcut_app_duplicate = new Win32Program
|
||||
private static readonly Win32Program _dummyInternetShortcutAppDuplicate = new Win32Program
|
||||
{
|
||||
Name = "Shop Titans",
|
||||
ExecutableName = "Shop Titans.url",
|
||||
@ -188,8 +188,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
// Arrange
|
||||
List<Win32Program> prgms = new List<Win32Program>
|
||||
{
|
||||
notepad_appdata,
|
||||
notepad_users
|
||||
_notepadAppdata,
|
||||
_notepadUsers,
|
||||
};
|
||||
|
||||
// Act
|
||||
@ -205,8 +205,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
// Arrange
|
||||
List<Win32Program> prgms = new List<Win32Program>
|
||||
{
|
||||
dummy_internetShortcut_app,
|
||||
dummy_internetShortcut_app_duplicate
|
||||
_dummyInternetShortcutApp,
|
||||
_dummyInternetShortcutAppDuplicate,
|
||||
};
|
||||
|
||||
// Act
|
||||
@ -222,7 +222,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
// Arrange
|
||||
List<Win32Program> prgms = new List<Win32Program>
|
||||
{
|
||||
file_explorer
|
||||
_fileExplorer,
|
||||
};
|
||||
|
||||
// Act
|
||||
@ -238,8 +238,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
// Arrange
|
||||
List<Win32Program> prgms = new List<Win32Program>
|
||||
{
|
||||
wordpad,
|
||||
wordpad_duplicate
|
||||
_wordpad,
|
||||
_wordpadDuplicate,
|
||||
};
|
||||
|
||||
// Act
|
||||
@ -256,9 +256,9 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
// Arrange
|
||||
List<Win32Program> prgms = new List<Win32Program>
|
||||
{
|
||||
azure_command_prompt,
|
||||
visual_studio_command_prompt,
|
||||
command_prompt
|
||||
_azureCommandPrompt,
|
||||
_visualStudioCommandPrompt,
|
||||
_commandPrompt,
|
||||
};
|
||||
|
||||
// Act
|
||||
@ -272,20 +272,20 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void FunctionIsWebApplicationShouldReturnTrueForWebApplications()
|
||||
{
|
||||
// The IsWebApplication(() function must return true for all PWAs and pinned web pages
|
||||
Assert.IsTrue(twitter_pwa.IsWebApplication());
|
||||
Assert.IsTrue(pinned_webpage.IsWebApplication());
|
||||
Assert.IsTrue(edge_named_pinned_webpage.IsWebApplication());
|
||||
Assert.IsTrue(_twitterChromePwa.IsWebApplication());
|
||||
Assert.IsTrue(_pinnedWebpage.IsWebApplication());
|
||||
Assert.IsTrue(_edgeNamedPinnedWebpage.IsWebApplication());
|
||||
|
||||
// Should not filter apps whose executable name ends with proxy.exe
|
||||
Assert.IsFalse(dummy_proxy_app.IsWebApplication());
|
||||
Assert.IsFalse(_dummyProxyApp.IsWebApplication());
|
||||
}
|
||||
|
||||
[TestCase("ignore")]
|
||||
public void FunctionFilterWebApplicationShouldReturnFalseWhenSearchingForTheMainApp(string query)
|
||||
{
|
||||
// Irrespective of the query, the FilterWebApplication() Function must not filter main apps such as edge and chrome
|
||||
Assert.IsFalse(msedge.FilterWebApplication(query));
|
||||
Assert.IsFalse(chrome.FilterWebApplication(query));
|
||||
Assert.IsFalse(_msedge.FilterWebApplication(query));
|
||||
Assert.IsFalse(_chrome.FilterWebApplication(query));
|
||||
}
|
||||
|
||||
[TestCase("edge", ExpectedResult = true)]
|
||||
@ -297,7 +297,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
[TestCase("Edge Web page", ExpectedResult = false)]
|
||||
public bool EdgeWebSitesShouldBeFilteredWhenSearchingForEdge(string query)
|
||||
{
|
||||
return pinned_webpage.FilterWebApplication(query);
|
||||
return _pinnedWebpage.FilterWebApplication(query);
|
||||
}
|
||||
|
||||
[TestCase("chrome", ExpectedResult = true)]
|
||||
@ -307,7 +307,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
[TestCase("Google Chrome twitter", ExpectedResult = false)]
|
||||
public bool ChromeWebSitesShouldBeFilteredWhenSearchingForChrome(string query)
|
||||
{
|
||||
return twitter_pwa.FilterWebApplication(query);
|
||||
return _twitterChromePwa.FilterWebApplication(query);
|
||||
}
|
||||
|
||||
[TestCase("twitter", 0, ExpectedResult = false)]
|
||||
@ -318,25 +318,24 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
[TestCase("WEB PAGE", 1, ExpectedResult = false)]
|
||||
[TestCase("edge", 2, ExpectedResult = false)]
|
||||
[TestCase("EDGE", 2, ExpectedResult = false)]
|
||||
public bool PinnedWebPagesShouldNotBeFilteredWhenSearchingForThem(string query, int Case)
|
||||
public bool PinnedWebPagesShouldNotBeFilteredWhenSearchingForThem(string query, int scenario)
|
||||
{
|
||||
const uint CASE_TWITTER = 0;
|
||||
const uint CASE_WEB_PAGE = 1;
|
||||
const uint CASE_EDGE_NAMED_WEBPAGE = 2;
|
||||
const int CASE_TWITTER = 0;
|
||||
const int CASE_WEB_PAGE = 1;
|
||||
const int CASE_EDGE_NAMED_WEBPAGE = 2;
|
||||
|
||||
// If the query is a part of the name of the web application, it should not be filtered,
|
||||
// even if the name is the same as that of the main application, eg: case 2 - edge
|
||||
if (Case == CASE_TWITTER)
|
||||
switch (scenario)
|
||||
{
|
||||
return twitter_pwa.FilterWebApplication(query);
|
||||
}
|
||||
else if (Case == CASE_WEB_PAGE)
|
||||
{
|
||||
return pinned_webpage.FilterWebApplication(query);
|
||||
}
|
||||
else if (Case == CASE_EDGE_NAMED_WEBPAGE)
|
||||
{
|
||||
return edge_named_pinned_webpage.FilterWebApplication(query);
|
||||
case CASE_TWITTER:
|
||||
return _twitterChromePwa.FilterWebApplication(query);
|
||||
case CASE_WEB_PAGE:
|
||||
return _pinnedWebpage.FilterWebApplication(query);
|
||||
case CASE_EDGE_NAMED_WEBPAGE:
|
||||
return _edgeNamedPinnedWebpage.FilterWebApplication(query);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// unreachable code
|
||||
@ -350,7 +349,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void Win32ApplicationsShouldNotBeFilteredWhenFilteringRunCommands(string query)
|
||||
{
|
||||
// Even if there is an exact match in the name or exe name, win32 applications should never be filtered
|
||||
Assert.IsTrue(command_prompt.QueryEqualsNameForRunCommands(query));
|
||||
Assert.IsTrue(_commandPrompt.QueryEqualsNameForRunCommands(query));
|
||||
}
|
||||
|
||||
[TestCase("cmd")]
|
||||
@ -359,10 +358,10 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void RunCommandsShouldNotBeFilteredOnExactMatch(string query)
|
||||
{
|
||||
// Partial matches should be filtered as cmd is not equal to cmder
|
||||
Assert.IsFalse(cmder_run_command.QueryEqualsNameForRunCommands(query));
|
||||
Assert.IsFalse(_cmderRunCommand.QueryEqualsNameForRunCommands(query));
|
||||
|
||||
// the query matches the name (cmd) and is therefore not filtered (case-insensitive)
|
||||
Assert.IsTrue(cmd_run_command.QueryEqualsNameForRunCommands(query));
|
||||
Assert.IsTrue(_cmdRunCommand.QueryEqualsNameForRunCommands(query));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -373,7 +372,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
|
||||
|
||||
// Act
|
||||
List<ContextMenuResult> contextMenuResults = pinned_webpage.ContextMenus(mock.Object);
|
||||
List<ContextMenuResult> contextMenuResults = _pinnedWebpage.ContextMenus(mock.Object);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(contextMenuResults.Count, 3);
|
||||
@ -390,7 +389,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
|
||||
|
||||
// Act
|
||||
List<ContextMenuResult> contextMenuResults = dummy_internetShortcut_app.ContextMenus(mock.Object);
|
||||
List<ContextMenuResult> contextMenuResults = _dummyInternetShortcutApp.ContextMenus(mock.Object);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(contextMenuResults.Count, 2);
|
||||
@ -406,7 +405,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
|
||||
|
||||
// Act
|
||||
List<ContextMenuResult> contextMenuResults = chrome.ContextMenus(mock.Object);
|
||||
List<ContextMenuResult> contextMenuResults = _chrome.ContextMenus(mock.Object);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(contextMenuResults.Count, 3);
|
||||
@ -423,7 +422,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
|
||||
|
||||
// Act
|
||||
List<ContextMenuResult> contextMenuResults = cmd_run_command.ContextMenus(mock.Object);
|
||||
List<ContextMenuResult> contextMenuResults = _cmdRunCommand.ContextMenus(mock.Object);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(contextMenuResults.Count, 3);
|
||||
@ -440,11 +439,11 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
StringMatcher.Instance = new StringMatcher();
|
||||
|
||||
// Act
|
||||
var result = cmder_run_command.Result("cmder", mock.Object);
|
||||
var result = _cmderRunCommand.Result("cmder", mock.Object);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result.Title.Equals(cmder_run_command.Name, StringComparison.Ordinal));
|
||||
Assert.IsFalse(result.Title.Equals(cmder_run_command.Description, StringComparison.Ordinal));
|
||||
Assert.IsTrue(result.Title.Equals(_cmderRunCommand.Name, StringComparison.Ordinal));
|
||||
Assert.IsFalse(result.Title.Equals(_cmderRunCommand.Description, StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,10 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
[TestFixture]
|
||||
public class Win32ProgramRepositoryTest
|
||||
{
|
||||
private readonly ProgramPluginSettings _settings = new ProgramPluginSettings();
|
||||
private readonly string[] _pathsToWatch = new string[] { "location1", "location2" };
|
||||
|
||||
private List<IFileSystemWatcherWrapper> _fileSystemWatchers;
|
||||
private ProgramPluginSettings _settings = new ProgramPluginSettings();
|
||||
private string[] _pathsToWatch = new string[] { "location1", "location2" };
|
||||
private List<Mock<IFileSystemWatcherWrapper>> _fileSystemMocks;
|
||||
|
||||
[SetUp]
|
||||
@ -41,7 +42,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
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);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
|
||||
Win32Program item1 = new Win32Program
|
||||
{
|
||||
@ -60,55 +61,55 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
};
|
||||
|
||||
// Act
|
||||
_win32ProgramRepository.Add(item1);
|
||||
win32ProgramRepository.Add(item1);
|
||||
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
|
||||
// To add an item with the same hashCode, ie, same name, exename and fullPath
|
||||
_win32ProgramRepository.Add(item2);
|
||||
win32ProgramRepository.Add(item2);
|
||||
|
||||
// Assert, count still remains 1 because they are duplicate items
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
}
|
||||
|
||||
[TestCase("path.appref-ms")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppCreatedForApprefAppsWhenCreatedEventIsRaised(string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Created, "directory", path);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Created += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(_win32ProgramRepository.ElementAt(0).AppType, 2);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(win32ProgramRepository.ElementAt(0).AppType, 2);
|
||||
}
|
||||
|
||||
[TestCase("directory", "path.appref-ms")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppDeletedForApprefAppsWhenDeletedEventIsRaised(string directory, string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Deleted, directory, path);
|
||||
|
||||
string fullPath = directory + "\\" + path;
|
||||
Win32Program item = Win32Program.GetAppFromPath(fullPath);
|
||||
_win32ProgramRepository.Add(item);
|
||||
win32ProgramRepository.Add(item);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Deleted += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 0);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 0);
|
||||
}
|
||||
|
||||
[TestCase("directory", "oldpath.appref-ms", "newpath.appref-ms")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppRenamedForApprefAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
RenamedEventArgs e = new RenamedEventArgs(WatcherChangeTypes.Renamed, directory, newpath, oldpath);
|
||||
|
||||
string oldFullPath = directory + "\\" + oldpath;
|
||||
@ -116,22 +117,22 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
|
||||
Win32Program olditem = Win32Program.GetAppFromPath(oldFullPath);
|
||||
Win32Program newitem = Win32Program.GetAppFromPath(newFullPath);
|
||||
_win32ProgramRepository.Add(olditem);
|
||||
win32ProgramRepository.Add(olditem);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Renamed += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(_win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(_win32ProgramRepository.Contains(olditem));
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(win32ProgramRepository.Contains(olditem));
|
||||
}
|
||||
|
||||
[TestCase("path.exe")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppCreatedForExeAppsWhenCreatedEventIsRaised(string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Created, "directory", path);
|
||||
|
||||
// FileVersionInfo must be mocked for exe applications
|
||||
@ -143,15 +144,15 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
_fileSystemMocks[0].Raise(m => m.Created += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(_win32ProgramRepository.ElementAt(0).AppType, 2);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(win32ProgramRepository.ElementAt(0).AppType, 2);
|
||||
}
|
||||
|
||||
[TestCase("directory", "path.exe")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppDeletedForExeAppsWhenDeletedEventIsRaised(string directory, string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Deleted, directory, path);
|
||||
|
||||
// FileVersionInfo must be mocked for exe applications
|
||||
@ -161,20 +162,20 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
|
||||
string fullPath = directory + "\\" + path;
|
||||
Win32Program item = Win32Program.GetAppFromPath(fullPath);
|
||||
_win32ProgramRepository.Add(item);
|
||||
win32ProgramRepository.Add(item);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Deleted += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 0);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 0);
|
||||
}
|
||||
|
||||
[TestCase("directory", "oldpath.appref-ms", "newpath.appref-ms")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppRenamedForExeAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
RenamedEventArgs e = new RenamedEventArgs(WatcherChangeTypes.Renamed, directory, newpath, oldpath);
|
||||
|
||||
string oldFullPath = directory + "\\" + oldpath;
|
||||
@ -187,22 +188,22 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
|
||||
Win32Program olditem = Win32Program.GetAppFromPath(oldFullPath);
|
||||
Win32Program newitem = Win32Program.GetAppFromPath(newFullPath);
|
||||
_win32ProgramRepository.Add(olditem);
|
||||
win32ProgramRepository.Add(olditem);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Renamed += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(_win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(_win32ProgramRepository.Contains(olditem));
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(win32ProgramRepository.Contains(olditem));
|
||||
}
|
||||
|
||||
[TestCase("path.url")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppChangedForUrlAppsWhenChangedEventIsRaised(string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Changed, "directory", path);
|
||||
|
||||
// File.ReadAllLines must be mocked for url applications
|
||||
@ -214,8 +215,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
_fileSystemMocks[0].Raise(m => m.Changed += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(_win32ProgramRepository.ElementAt(0).AppType, 1); // Internet Shortcut Application
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(win32ProgramRepository.ElementAt(0).AppType, 1); // Internet Shortcut Application
|
||||
}
|
||||
|
||||
[TestCase("path.url")]
|
||||
@ -224,7 +225,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
// We are handing internet shortcut apps using the Changed event instead
|
||||
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Created, "directory", path);
|
||||
|
||||
// File.ReadAllLines must be mocked for url applications
|
||||
@ -236,7 +237,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
_fileSystemMocks[0].Raise(m => m.Created += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 0);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 0);
|
||||
}
|
||||
|
||||
[TestCase("path.exe")]
|
||||
@ -247,7 +248,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
// We are handing internet shortcut apps using the Changed event instead
|
||||
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Changed, "directory", path);
|
||||
|
||||
// FileVersionInfo must be mocked for exe applications
|
||||
@ -264,14 +265,14 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
_fileSystemMocks[0].Raise(m => m.Changed += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 0);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 0);
|
||||
}
|
||||
|
||||
[TestCase("directory", "path.url")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppDeletedForUrlAppsWhenDeletedEventIsRaised(string directory, string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Deleted, directory, path);
|
||||
|
||||
// File.ReadAllLines must be mocked for url applications
|
||||
@ -281,20 +282,20 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
|
||||
string fullPath = directory + "\\" + path;
|
||||
Win32Program item = Win32Program.GetAppFromPath(fullPath);
|
||||
_win32ProgramRepository.Add(item);
|
||||
win32ProgramRepository.Add(item);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Deleted += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 0);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 0);
|
||||
}
|
||||
|
||||
[TestCase("directory", "oldpath.url", "newpath.url")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppRenamedForUrlAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
RenamedEventArgs e = new RenamedEventArgs(WatcherChangeTypes.Renamed, directory, newpath, oldpath);
|
||||
|
||||
// File.ReadAllLines must be mocked for url applications
|
||||
@ -307,22 +308,22 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
|
||||
Win32Program olditem = Win32Program.GetAppFromPath(oldFullPath);
|
||||
Win32Program newitem = Win32Program.GetAppFromPath(newFullPath);
|
||||
_win32ProgramRepository.Add(olditem);
|
||||
win32ProgramRepository.Add(olditem);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Renamed += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(_win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(_win32ProgramRepository.Contains(olditem));
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(win32ProgramRepository.Contains(olditem));
|
||||
}
|
||||
|
||||
[TestCase("path.lnk")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppCreatedForLnkAppsWhenCreatedEventIsRaised(string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Created, "directory", path);
|
||||
|
||||
// ShellLinkHelper must be mocked for lnk applications
|
||||
@ -334,15 +335,15 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
_fileSystemMocks[0].Raise(m => m.Created += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(_win32ProgramRepository.ElementAt(0).AppType, 2);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.AreEqual(win32ProgramRepository.ElementAt(0).AppType, 2);
|
||||
}
|
||||
|
||||
[TestCase("directory", "path.lnk")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppDeletedForLnkAppsWhenDeletedEventIsRaised(string directory, string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Deleted, directory, path);
|
||||
|
||||
// ShellLinkHelper must be mocked for lnk applications
|
||||
@ -359,24 +360,24 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
FullPath = "directory\\path.exe",
|
||||
LnkResolvedPath = "directory\\path.lnk", // This must be equal for lnk applications
|
||||
};
|
||||
_win32ProgramRepository.Add(item);
|
||||
win32ProgramRepository.Add(item);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Deleted += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 0);
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 0);
|
||||
}
|
||||
|
||||
[TestCase("directory", "oldpath.lnk", "path.lnk")]
|
||||
public void Win32ProgramRepositoryMustCallOnAppRenamedForLnkAppsWhenRenamedEventIsRaised(string directory, string oldpath, string path)
|
||||
{
|
||||
// Arrange
|
||||
Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage<IList<Win32Program>>("Win32"), _settings, _pathsToWatch);
|
||||
RenamedEventArgs e = new RenamedEventArgs(WatcherChangeTypes.Renamed, directory, path, oldpath);
|
||||
|
||||
string oldFullPath = directory + "\\" + oldpath;
|
||||
string FullPath = directory + "\\" + path;
|
||||
string fullPath = directory + "\\" + path;
|
||||
|
||||
// ShellLinkHelper must be mocked for lnk applications
|
||||
var mockShellLink = new Mock<IShellLinkHelper>();
|
||||
@ -388,25 +389,25 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
{
|
||||
Name = "oldpath",
|
||||
ExecutableName = path,
|
||||
FullPath = FullPath,
|
||||
FullPath = fullPath,
|
||||
};
|
||||
|
||||
Win32Program newitem = new Win32Program
|
||||
{
|
||||
Name = "path",
|
||||
ExecutableName = path,
|
||||
FullPath = FullPath,
|
||||
FullPath = fullPath,
|
||||
};
|
||||
|
||||
_win32ProgramRepository.Add(olditem);
|
||||
win32ProgramRepository.Add(olditem);
|
||||
|
||||
// Act
|
||||
_fileSystemMocks[0].Raise(m => m.Renamed += null, e);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(_win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(_win32ProgramRepository.Contains(olditem));
|
||||
Assert.AreEqual(win32ProgramRepository.Count(), 1);
|
||||
Assert.IsTrue(win32ProgramRepository.Contains(newitem));
|
||||
Assert.IsFalse(win32ProgramRepository.Contains(olditem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,10 +52,9 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
var namespaces = XmlNamespaces(path);
|
||||
InitPackageVersion(namespaces);
|
||||
|
||||
IStream stream;
|
||||
const uint noAttribute = 0x80;
|
||||
const Stgm exclusiveRead = Stgm.Read;
|
||||
var hResult = NativeMethods.SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);
|
||||
var hResult = NativeMethods.SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out IStream stream);
|
||||
|
||||
if (hResult == Hresult.Ok)
|
||||
{
|
||||
|
@ -193,14 +193,13 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
private async void Launch(IPublicAPI api)
|
||||
{
|
||||
var appManager = new ApplicationActivationHelper.ApplicationActivationManager();
|
||||
uint unusedPid;
|
||||
const string noArgs = "";
|
||||
const ApplicationActivationHelper.ActivateOptions noFlags = ApplicationActivationHelper.ActivateOptions.None;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
appManager.ActivateApplication(UserModelId, noArgs, noFlags, out unusedPid);
|
||||
appManager.ActivateApplication(UserModelId, noArgs, noFlags, out uint unusedPid);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user