public void Win32ProgramRepository_MustCallOnAppRenamedForUrlApps_WhenRenamedEventIsRaised(string directory, string oldpath, string newpath) { // Arrange 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 var mockFile = new Mock <IFileWrapper>(); mockFile.Setup(m => m.ReadAllLines(It.IsAny <string>())).Returns(new string[] { "URL=steam://rungameid/1258080", "IconFile=iconFile" }); Win32Program.FileWrapper = mockFile.Object; string oldFullPath = directory + "\\" + oldpath; string newFullPath = directory + "\\" + newpath; Win32Program olditem = Win32Program.GetAppFromPath(oldFullPath); Win32Program newitem = Win32Program.GetAppFromPath(newFullPath); _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)); }
public void Win32ProgramRepository_MustCallOnAppRenamedForExeApps_WhenRenamedEventIsRaised(string directory, string oldpath, string newpath) { // Arrange 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; string newFullPath = directory + "\\" + newpath; // FileVersionInfo must be mocked for exe applications var mockFileVersionInfo = new Mock <IFileVersionInfoWrapper>(); mockFileVersionInfo.Setup(m => m.GetVersionInfo(It.IsAny <string>())).Returns((FileVersionInfo)null); Win32Program.FileVersionInfoWrapper = mockFileVersionInfo.Object; Win32Program olditem = Win32Program.GetAppFromPath(oldFullPath); Win32Program newitem = Win32Program.GetAppFromPath(newFullPath); _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)); }
public void Win32ProgramRepository_MustCallOnAppDeletedForLnkApps_WhenDeletedEventIsRaised(string directory, string path) { // Arrange 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 var mockShellLink = new Mock <IShellLinkHelper>(); mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny <string>())).Returns(String.Empty); Win32Program.Helper = mockShellLink.Object; string fullPath = directory + "\\" + path; Win32Program item = new Win32Program { Name = "path", ExecutableName = "path.exe", ParentDirectory = "directory", FullPath = "directory\\path.exe", LnkResolvedPath = "directory\\path.lnk" // This must be equal for lnk applications }; _win32ProgramRepository.Add(item); // Act _fileSystemMocks[0].Raise(m => m.Deleted += null, e); // Assert Assert.AreEqual(_win32ProgramRepository.Count(), 0); }
public void Win32Repository_MustNotStoreDuplicates_WhileAddingItemsWithSameHashCode(string name, string exename, string fullPath, string description1, string description2) { // Arrange Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage <IList <Win32Program> >("Win32"), _settings, _pathsToWatch); Win32Program item1 = new Win32Program { Name = name, ExecutableName = exename, FullPath = fullPath, Description = description1 }; Win32Program item2 = new Win32Program { Name = name, ExecutableName = exename, FullPath = fullPath, Description = description2 }; // Act _win32ProgramRepository.Add(item1); Assert.AreEqual(_win32ProgramRepository.Count(), 1); // To add an item with the same hashCode, ie, same name, exename and fullPath _win32ProgramRepository.Add(item2); // Assert, count still remains 1 because they are duplicate items Assert.AreEqual(_win32ProgramRepository.Count(), 1); }
public Win32Program.ApplicationType GetAppTypeFromPathShouldReturnCorrectAppTypeWhenAppPathIsPassedAsArgument(string path) { // Directory.Exists must be mocked Win32Program.DirectoryWrapper = GetMockedDirectoryWrapper(); // Act return(Win32Program.GetAppTypeFromPath(path)); }
private void OnAppRenamed(object sender, RenamedEventArgs e) { string oldPath = e.OldFullPath; string newPath = e.FullPath; string extension = Path.GetExtension(newPath); Programs.Win32Program newApp = Programs.Win32Program.GetAppFromPath(newPath); Programs.Win32Program oldApp = null; // Once the shortcut application is renamed, the old app does not exist and therefore when we try to get the FullPath we get the lnk path instead of the exe path // This changes the hashCode() of the old application. // Therefore, instead of retrieving the old app using the GetAppFromPath(), we construct the application ourself // This situation is not encountered for other application types because the fullPath is the path itself, instead of being computed by using the path to the app. try { if (extension.Equals(lnkExtension, StringComparison.OrdinalIgnoreCase)) { oldApp = new Win32Program() { Name = Path.GetFileNameWithoutExtension(e.OldName), ExecutableName = newApp.ExecutableName, FullPath = newApp.FullPath }; } else if (extension.Equals(urlExtension, StringComparison.OrdinalIgnoreCase)) { oldApp = new Win32Program() { Name = Path.GetFileNameWithoutExtension(e.OldName), ExecutableName = Path.GetFileName(e.OldName), FullPath = newApp.FullPath }; } else { oldApp = Win32Program.GetAppFromPath(oldPath); } } catch (Exception ex) { Log.Info($"|Win32ProgramRepository|OnAppRenamed-{extension}Program|{oldPath}|Unable to create program from {oldPath}| {ex.Message}"); } // To remove the old app which has been renamed and to add the new application. if (oldApp != null) { Remove(oldApp); } if (newApp != null) { Add(newApp); } }
public void DedupFunction_whenCalled_mustNotRemovelnkWhichdoesNotHaveExe() { // Arrange List <Win32Program> prgms = new List <Win32Program>(); prgms.Add(file_explorer); // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(apps.Length, 1); }
public void DedupFunction_whenCalled_MustRemoveInternetShortcuts() { // Arrange List <Win32Program> prgms = new List <Win32Program>(); prgms.Add(dummy_internetShortcut_app); prgms.Add(dummy_internetShortcut_app_duplicate); // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(apps.Length, 1); }
public void DedupFunctionWhenCalledMustNotRemovelnkWhichdoesNotHaveExe() { // Arrange List <Win32Program> prgms = new List <Win32Program> { _fileExplorerLink, }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(1, apps.Length); }
public void DedupFunction_whenCalled_mustRemoveDuplicateNotepads() { // Arrange List <Win32Program> prgms = new List <Win32Program>(); prgms.Add(notepad_appdata); prgms.Add(notepad_users); // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(apps.Length, 1); }
public void DedupFunctionWhenCalledMustRemoveInternetShortcuts() { // Arrange List <Win32Program> prgms = new List <Win32Program> { _dummyInternetShortcutApp, _dummyInternetShortcutAppDuplicate, }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(1, apps.Length); }
public void DedupFunctionWhenCalledMustRemoveDuplicateNotepads() { // Arrange List <Win32Program> prgms = new List <Win32Program> { _notepadAppdata, _notepadUsers, }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(1, apps.Length); }
public void DedupFunction_mustNotRemovePrograms_withSameExeNameAndFullPath() { // Arrange List <Win32Program> prgms = new List <Win32Program>(); prgms.Add(azure_command_prompt); prgms.Add(visual_studio_command_prompt); prgms.Add(command_prompt); // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(apps.Length, 3); }
public void DedupFunction_mustRemoveDuplicates_forExeExtensionsWithoutLnkResolvedPath() { // Arrange List <Win32Program> prgms = new List <Win32Program>(); prgms.Add(wordpad); prgms.Add(wordpad_duplicate); // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(apps.Length, 1); Assert.IsTrue(!string.IsNullOrEmpty(apps[0].LnkResolvedPath)); }
public void DedupFunctionMustNotRemoveProgramsWithSameExeNameAndFullPath() { // Arrange List <Win32Program> prgms = new List <Win32Program> { _azureCommandPrompt, _visualStudioCommandPrompt, _commandPrompt, }; // Act Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(3, apps.Length); }
public void DedupFunctionMustRemoveDuplicatesForExeExtensionsWithoutLnkResolvedPath() { // Arrange List <Win32Program> prgms = new List <Win32Program> { _wordpad, _wordpadDuplicate, }; // Act List <Win32Program> apps = Win32Program.DeduplicatePrograms(prgms.AsParallel()); // Assert Assert.AreEqual(1, apps.Count); Assert.IsTrue(!string.IsNullOrEmpty(apps[0].LnkResolvedPath)); }
public void Win32ProgramRepository_MustCallOnAppDeletedForApprefApps_WhenDeletedEventIsRaised(string directory, string path) { // Arrange 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); // Act _fileSystemMocks[0].Raise(m => m.Deleted += null, e); // Assert Assert.AreEqual(_win32ProgramRepository.Count(), 0); }
public void Win32ProgramRepository_MustCallOnAppRenamedForLnkApps_WhenRenamedEventIsRaised(string directory, string oldpath, string path) { // Arrange 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; // ShellLinkHelper must be mocked for lnk applications var mockShellLink = new Mock <IShellLinkHelper>(); mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny <string>())).Returns(String.Empty); Win32Program.Helper = mockShellLink.Object; // old item and new item are the actual items when they are in existence Win32Program olditem = new Win32Program { Name = "oldpath", ExecutableName = path, FullPath = FullPath, }; Win32Program newitem = new Win32Program { Name = "path", ExecutableName = path, FullPath = FullPath, }; _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)); }
public void Win32ProgramRepository_MustCallOnAppRenamedForApprefApps_WhenRenamedEventIsRaised(string directory, string oldpath, string newpath) { // Arrange 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; string newFullPath = directory + "\\" + newpath; Win32Program olditem = Win32Program.GetAppFromPath(oldFullPath); Win32Program newitem = Win32Program.GetAppFromPath(newFullPath); _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)); }
public void Win32ProgramRepository_MustCallOnAppDeletedForExeApps_WhenDeletedEventIsRaised(string directory, string path) { // Arrange 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 var mockFileVersionInfo = new Mock <IFileVersionInfoWrapper>(); mockFileVersionInfo.Setup(m => m.GetVersionInfo(It.IsAny <string>())).Returns((FileVersionInfo)null); Win32Program.FileVersionInfoWrapper = mockFileVersionInfo.Object; string fullPath = directory + "\\" + path; Win32Program item = Win32Program.GetAppFromPath(fullPath); _win32ProgramRepository.Add(item); // Act _fileSystemMocks[0].Raise(m => m.Deleted += null, e); // Assert Assert.AreEqual(_win32ProgramRepository.Count(), 0); }