public void Win32ProgramRepositoryMustNotCreateAnyAppOtherThanUrlAppWhenChangedEventIsRaised(string path)
        {
            // We are handing internet shortcut apps using the Changed event instead

            // Arrange
            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
            var mockFileVersionInfo = new Mock <IFileVersionInfoWrapper>();

            mockFileVersionInfo.Setup(m => m.GetVersionInfo(It.IsAny <string>())).Returns((FileVersionInfo)null);
            Win32Program.FileVersionInfoWrapper = mockFileVersionInfo.Object;

            // 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;

            // Act
            _fileSystemMocks[0].Raise(m => m.Changed += 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.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(1, win32ProgramRepository.Count());
            Assert.IsTrue(win32ProgramRepository.Contains(newitem));
            Assert.IsFalse(win32ProgramRepository.Contains(olditem));
        }
        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);

            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(1, win32ProgramRepository.Count());

            // 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(1, win32ProgramRepository.Count());
        }
Example #4
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage <ProgramPluginSettings>();
            Settings         = _settingsStorage.Load();

            // This helper class initializes the file system watchers based on the locations to watch
            _win32ProgramRepositoryHelper = new Win32ProgramFileSystemWatchers();

            // Initialize the Win32ProgramRepository with the settings object
            _win32ProgramRepository = new Win32ProgramRepository(_win32ProgramRepositoryHelper.FileSystemWatchers.Cast <IFileSystemWatcherWrapper>().ToList(), new BinaryStorage <IList <Programs.Win32Program> >("Win32"), Settings, _win32ProgramRepositoryHelper.PathsToWatch);

            var a = Task.Run(() =>
            {
                Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _win32ProgramRepository.IndexPrograms);
            });

            var b = Task.Run(() =>
            {
                Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
            });

            Task.WaitAll(a, b);

            Settings.LastIndexTime = DateTime.Today;
        }
        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.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(0, win32ProgramRepository.Count());
        }
        public void Win32ProgramRepositoryMustCallOnAppRenamedForExeAppsWhenRenamedEventIsRaised(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(1, win32ProgramRepository.Count());
            Assert.IsTrue(win32ProgramRepository.Contains(newitem));
            Assert.IsFalse(win32ProgramRepository.Contains(olditem));
        }
Example #7
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage <ProgramPluginSettings>();
            Settings         = _settingsStorage.Load();

            // This helper class initializes the file system watchers based on the locations to watch
            _win32ProgramRepositoryHelper = new Win32ProgramFileSystemWatchers();

            // Initialize the Win32ProgramRepository with the settings object
            _win32ProgramRepository = new Win32ProgramRepository(_win32ProgramRepositoryHelper.FileSystemWatchers.Cast <IFileSystemWatcherWrapper>().ToList(), new BinaryStorage <IList <Programs.Win32Program> >("Win32"), Settings, _win32ProgramRepositoryHelper.PathsToWatch);
        }
        public void Win32ProgramRepositoryMustCallOnAppCreatedForApprefAppsWhenCreatedEventIsRaised(string path)
        {
            // Arrange
            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(1, win32ProgramRepository.Count());
            Assert.AreEqual(Win32Program.ApplicationType.ApprefApplication, win32ProgramRepository.ElementAt(0).AppType);
        }
        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());
        }
        public void Win32ProgramRepositoryMustCallOnAppCreatedForExeAppsWhenCreatedEventIsRaised(string path)
        {
            // Arrange
            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
            var mockFileVersionInfo = new Mock <IFileVersionInfoWrapper>();

            mockFileVersionInfo.Setup(m => m.GetVersionInfo(It.IsAny <string>())).Returns((FileVersionInfo)null);
            Win32Program.FileVersionInfoWrapper = mockFileVersionInfo.Object;

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

            // Assert
            Assert.AreEqual(1, win32ProgramRepository.Count());
            Assert.AreEqual(Win32Program.ApplicationType.Win32Application, win32ProgramRepository.ElementAt(0).AppType);
        }
Example #11
0
        public void Win32ProgramRepositoryMustCallOnAppCreatedForLnkAppsWhenCreatedEventIsRaised(string path)
        {
            // Arrange
            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
            var mockShellLink = new Mock <IShellLinkHelper>();

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

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

            // Assert
            Assert.AreEqual(win32ProgramRepository.Count(), 1);
            Assert.AreEqual(win32ProgramRepository.ElementAt(0).AppType, Win32Program.ApplicationType.Win32Application);
        }
Example #12
0
        public void Win32ProgramRepositoryMustCallOnAppChangedForUrlAppsWhenChangedEventIsRaised(string path)
        {
            // Arrange
            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
            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;

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

            // Assert
            Assert.AreEqual(win32ProgramRepository.Count(), 1);
            Assert.AreEqual(win32ProgramRepository.ElementAt(0).AppType, Win32Program.ApplicationType.InternetShortcutApplication); // Internet Shortcut Application
        }
        public void Win32ProgramRepositoryMustNotCreateUrlAppWhenCreatedEventIsRaised(string path)
        {
            // We are handing internet shortcut apps using the Changed event instead

            // Arrange
            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
            var mockFile = new Mock <IFile>();

            mockFile.Setup(m => m.ReadAllLines(It.IsAny <string>())).Returns(new string[] { "URL=steam://rungameid/1258080", "IconFile=iconFile" });
            Win32Program.FileWrapper = mockFile.Object;

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

            // Assert
            Assert.AreEqual(0, win32ProgramRepository.Count());
        }
Example #14
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));
        }
Example #17
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage <Settings>();
            _settings        = _settingsStorage.Load();
            // This helper class initializes the file system watchers based on the locations to watch
            _win32ProgramRepositoryHelper = new Win32ProgramFileSystemWatchers();

            // Initialize the Win32ProgramRepository with the settings object
            _win32ProgramRepository = new Win32ProgramRepository(_win32ProgramRepositoryHelper._fileSystemWatchers.Cast <IFileSystemWatcherWrapper>().ToList(), new BinaryStorage <IList <Programs.Win32> >("Win32"), _settings, _win32ProgramRepositoryHelper._pathsToWatch);

            Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Preload programs cost", () =>
            {
                _win32ProgramRepository.Load();
                _packageRepository.Load();
            });
            Log.Info($"|Microsoft.Plugin.Program.Main|Number of preload win32 programs <{_win32ProgramRepository.Count()}>");

            var a = Task.Run(() =>
            {
                if (IsStartupIndexProgramsRequired || !_win32ProgramRepository.Any())
                {
                    Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _win32ProgramRepository.IndexPrograms);
                }
            });

            var b = Task.Run(() =>
            {
                if (IsStartupIndexProgramsRequired || !_packageRepository.Any())
                {
                    Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
                }
            });


            Task.WaitAll(a, b);

            _settings.LastIndexTime = DateTime.Today;
        }
        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());
        }
        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());
        }