public void ReadHitData_no_existing_file() { _diskManager.File.Exists(_localAppDataHitsFile).Returns(false); var data = _repo.Load(); Assert.NotNull(data); Assert.NotNull(data.Repositories); _diskManager.File.Received(1).Exists(_localAppDataHitsFile); _diskManager.File.Received(0).ReadAllText(_localAppDataHitsFile); }
public void LogCurrentDirectory_existingDir_incrementsHitCount() { var expectedName = "Hello"; var expectedFolder = "C:\\Junk\\Folder\\"; var expected = HitDataTestHelper.BuildHelperData(expectedName, expectedFolder); _hitRepo.Load().Returns(expected); _repoPaths.RepositoryFolder.Returns(expectedFolder); _manager.LogCurrentDirectory(); _hitRepo.Received(1).Save(Arg.Is <CommandData>(s => s.Repositories[0].HitCount == 2)); }
public void Setup() { _localAppDataFolder = $"{_localDataFolder}DWGitsh"; _fileManager = Substitute.For <IFile>(); _diskManager = Substitute.For <IStaticAbstraction>(); _diskManager.File = _fileManager; _diskManager.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).Returns(_localDataFolder); _diskManager.Path.Combine(_localDataFolder, "DWGitsh").Returns(_localAppDataFolder); _diskManager.Directory.Exists(_localAppDataFolder).Returns(true); _diskManager.NewDirectoryInfo(_localAppDataFolder).Returns(new MockDirectoryInfo { FullName = _localAppDataFolder, Name = "DWGitsh" }); _config = Substitute.For <IDWGitshConfig>(); _config.AppDataFolder.Returns(_localAppDataFolder); _repoPaths = Substitute.For <IRepositoryPaths>(); _repoPaths.RootFolder.Returns("C:\\Junk\\Folder\\"); _repoPaths.RepositoryFolder.Returns("C:\\Junk\\Folder\\.git\\"); _hitRepo = Substitute.For <IHitDataRepo>(); _manager = new HitDataManager(_config, _diskManager, _repoPaths, null, _hitRepo); _hitRepo.Load().Returns(new CommandData()); }
public virtual void LogCurrentDirectory() { if (this.RepositoryDirectories.RepositoryFolder == null) { return; } var data = _hitDataRepo.Load(); var updated = false; var compareFolder = _utils.TrimTrailingSlash(this.RepositoryDirectories.RootFolder); var branch = _utils.GetBranchName(this.RepositoryDirectories); foreach (var item in data.Repositories) { var itemFolder = _utils.TrimTrailingSlash(item.Directory); if (string.Compare(itemFolder, compareFolder, true) == 0) { item.HitCount++; item.DateLastHit = DateTime.Now; if (!string.IsNullOrEmpty(branch)) { item.LastBranch = branch; } updated = true; } } if (!updated) { var newHitData = new HitData { Directory = this.RepositoryDirectories.RootFolder, HitCount = 1, DateLastHit = DateTime.Now }; data.Repositories.Add(newHitData); } _hitDataRepo.Save(data); }