public void Win32ProgramRepository_MustCallOnAppRenamedForExeApps_WhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
        {
            // Arrange
            Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage <IList <Win32> >("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);
            Win32._fileVersionInfoWrapper = mockFileVersionInfo.Object;

            Win32 olditem = Win32.GetAppFromPath(oldFullPath);
            Win32 newitem = Win32.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 Win32ProgramRepositoryMustCallOnAppDeletedForLnkAppsWhenDeletedEventIsRaised(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.ShellLinkHelper = 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(0, win32ProgramRepository.Count());
        }
        public void Win32ProgramRepositoryMustCallOnAppRenamedForUrlAppsWhenRenamedEventIsRaised(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 <IFile>();

            mockFile.Setup(m => m.ReadLines(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(1, win32ProgramRepository.Count());
            Assert.IsTrue(win32ProgramRepository.Contains(newitem));
            Assert.IsFalse(win32ProgramRepository.Contains(olditem));
        }
        public void Win32ProgramRepositoryMustCallOnAppDeletedForApprefAppsWhenDeletedEventIsRaised(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(0, win32ProgramRepository.Count());
        }
Пример #5
0
        public void Win32ProgramRepositoryMustCallOnAppRenamedForLnkAppsWhenRenamedEventIsRaised(string directory, string oldpath, string path)
        {
            // Arrange
            Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, _settings, _pathsToWatch);
            RenamedEventArgs       e = new RenamedEventArgs(WatcherChangeTypes.Renamed, directory, path, oldpath);

            string oldFullPath = directory + "\\" + oldpath;
            string fullPath    = directory + "\\" + path;
            string linkingTo   = Directory.GetCurrentDirectory();

            // ShellLinkHelper must be mocked for lnk applications
            var mockShellLink = new Mock <IShellLinkHelper>();

            mockShellLink.Setup(m => m.RetrieveTargetPath(It.IsAny <string>())).Returns(linkingTo);
            Win32Program.ShellLinkHelper = mockShellLink.Object;

            // old item and new item are the actual items when they are in existence
            Win32Program olditem = new Win32Program
            {
                Name           = "oldpath",
                ExecutableName = oldpath,
                FullPath       = linkingTo,
            };

            Win32Program newitem = new Win32Program
            {
                Name           = "path",
                ExecutableName = path,
                FullPath       = linkingTo,
            };

            win32ProgramRepository.Add(olditem);

            // Act
            _fileSystemMocks[0].Raise(m => m.Renamed += null, e);

            // Assert
            Assert.AreEqual(1, win32ProgramRepository.Count());
            Assert.IsTrue(win32ProgramRepository.Contains(newitem));
            Assert.IsFalse(win32ProgramRepository.Contains(olditem));
        }
        public void Win32ProgramRepository_MustCallOnAppRenamedForLnkApps_WhenRenamedEventIsRaised(string directory, string oldpath, string path)
        {
            // Arrange
            Win32ProgramRepository _win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, new BinaryStorage <IList <Win32> >("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);
            Win32._helper = mockShellLink.Object;

            // old item and new item are the actual items when they are in existence
            Win32 olditem = new Win32
            {
                Name           = "oldpath",
                ExecutableName = path,
                FullPath       = FullPath,
            };

            Win32 newitem = new Win32
            {
                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 Win32ProgramRepositoryMustCallOnAppRenamedForApprefAppsWhenRenamedEventIsRaised(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(1, win32ProgramRepository.Count());
            Assert.IsTrue(win32ProgramRepository.Contains(newitem));
            Assert.IsFalse(win32ProgramRepository.Contains(olditem));
        }
        public void Win32ProgramRepositoryMustCallOnAppDeletedForExeAppsWhenDeletedEventIsRaised(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(0, win32ProgramRepository.Count());
        }
        public void Win32ProgramRepositoryMustCallOnAppDeletedForUrlAppsWhenDeletedEventIsRaised(string directory, string path)
        {
            // Arrange
            Win32ProgramRepository win32ProgramRepository = new Win32ProgramRepository(_fileSystemWatchers, _settings, _pathsToWatch);
            FileSystemEventArgs    e = new FileSystemEventArgs(WatcherChangeTypes.Deleted, directory, path);

            // File.ReadAllLines must be mocked for url applications
            var mockFile = new Mock <IFile>();

            mockFile.Setup(m => m.ReadLines(It.IsAny <string>())).Returns(new string[] { "URL=steam://rungameid/1258080", "IconFile=iconFile" });
            Win32Program.FileWrapper = mockFile.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(0, win32ProgramRepository.Count());
        }