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 void SetUp() { _dateTimeProvider = Substitute.For <IDateTime>(); _diskManager = Substitute.For <IStaticAbstraction>(); _diskManager.DateTime.Returns(_dateTimeProvider); _cache = new CacheContainer(_diskManager); }
protected void Init(IStaticAbstraction diskManager, string defaultColorFile, string customColorFile) { _diskManager = diskManager ?? new StAbWrapper(); var defColorFile = string.IsNullOrWhiteSpace(defaultColorFile) ? _defaultColorFileName : defaultColorFile; var custColorFile = string.IsNullOrWhiteSpace(customColorFile) ? _defaultCustomColorFileName : customColorFile; var path = _diskManager.NewFileInfo(_diskManager.Assembly.GetCallingAssembly().Location).DirectoryName; var testPath = DWPSUtils.IsFullPath(defColorFile) ? defColorFile : _diskManager.Path.Combine(path, defColorFile); if (_diskManager.File.Exists(testPath)) { _defaultColorFilePath = testPath; } else { testPath = _diskManager.Path.Combine(path, "psscripts", defColorFile); if (_diskManager.File.Exists(testPath)) { _defaultColorFilePath = testPath; } } _customColorFilePath = DWPSUtils.IsFullPath(custColorFile) ? custColorFile : _diskManager.Path.Combine(path, custColorFile); RefreshColors(); }
public void TestSetup() { dm = Substitute.For <IStaticAbstraction>(); defaultFileInfo = new MockFileInfo { Exists = true, Name = "default.csv", FullName = folder + "default.csv", LastWriteTime = DateTime.Now }; customFileInfo = new MockFileInfo { Exists = true, Name = "customColors.csv", FullName = folder + "customColors.csv", LastWriteTime = DateTime.Now }; if (_defaultColorFileText == null) { _defaultColorFileText = TestHelper.GetTestData("Colors/defaultColors.csv"); _defaultColorFileTextLines = _defaultColorFileText?.Split('\n'); _customColorFileText = TestHelper.GetTestData("Colors/customColors.csv"); _customColorFileTextLines = _customColorFileText?.Split('\n'); } MockCallsForFileInfo(defaultFileInfo, _defaultColorFileTextLines); MockCallsForFileInfo(customFileInfo, _customColorFileTextLines); }
public GitFileEntry(IStaticAbstraction diskManager, string currentPath, string relativePath, string targetPath = null) { _diskManager = diskManager; string finalRelPath = null; string originalRelPath = null; if (targetPath == null) { finalRelPath = relativePath.Replace("/", "\\"); } else { originalRelPath = relativePath.Replace("/", "\\"); finalRelPath = targetPath?.Replace("/", "\\"); } var valCurPath = GitUtils.Current.FixInvalidFileNameCharsInPath(currentPath); var valRelPath = GitUtils.Current.FixInvalidFileNameCharsInPath(finalRelPath); var dest = diskManager.Path.Combine(valCurPath, valRelPath); var info = _diskManager.NewFileInfo(dest); this.FullPath = info.FullName; this.Name = info.Name; if (originalRelPath != null) { var sourceFullPath = diskManager.Path.Combine(currentPath, originalRelPath); var oInfo = _diskManager.NewFileInfo(sourceFullPath); this.SourcePath = oInfo.FullName; } }
public CacheContainer(IStaticAbstraction diskManager) : this() { if (diskManager != null) { _diskManager = diskManager; } }
public void TestSetup() { dtp = Substitute.For <IDateTime>(); dm = Substitute.For <IStaticAbstraction>(); dm.DateTime.Returns(dtp); dtp.Now.Returns(DateTime.Now); cln = new CacheDependencyCollection(dm); }
public void Setup() { _diskManager = Substitute.For <IStaticAbstraction>(); _processManager = Substitute.For <IProcessManager>(); DWPSUtils._diskManager = _diskManager; DWPSUtils._processManager = _processManager; }
public HitDataManager(IDWGitshConfig config, IStaticAbstraction diskManager, IRepositoryPaths repoDirs, IGitUtils utils = null, IHitDataRepo hitRepo = null) { _utils = utils ?? GitUtils.Current; this._diskManager = diskManager ?? new StAbWrapper(); this.RepositoryDirectories = repoDirs; _hitDataRepo = hitRepo ?? new HitDataRepo(config.AppDataFolder, _diskManager); }
public CacheDependencyFile(IStaticAbstraction diskManager, string fullPath) { _diskManager = diskManager; if (string.IsNullOrWhiteSpace(fullPath)) { throw new ArgumentNullException("fullPath is required"); } GetState(fullPath); }
protected void Init(IStaticAbstraction diskManager, IProcessManager processManager, RepoPaths repoDirs, bool useCache) { this._diskManager = diskManager ?? new StAbWrapper(); this._processManager = processManager ?? new ProcessManager(); this.RepositoryDirectories = repoDirs; this.UseCache = useCache; _colorGroups = new ColorGroupReader(_diskManager); FindAppDataFolder(); }
// needed for unit testing internal GitUtils(IStaticAbstraction diskManager, ICacheContainer repoCache) : this() { if (diskManager != null) { _diskManager = diskManager; } if (repoCache != null) { RepoCache = repoCache; } Current = this; }
public void Setup() { _localAppDataHitsFile = $"{_dataPath}\\hitData.json"; _fileManager = Substitute.For <IFile>(); _diskManager = Substitute.For <IStaticAbstraction>(); _diskManager.File = _fileManager; _diskManager.Path.Combine(_dataPath, "hitData.json").Returns(_localAppDataHitsFile); _repo = new HitDataRepo(_dataPath, _diskManager); }
public DWGitshCommonArgs(IStaticAbstraction diskManager, IDWGitshConfig config, IRepositoryPaths repoPaths, IGitUtils utils, ICacheContainer cache) { this.DiskManager = diskManager ?? new StAbWrapper(); this.Config = config ?? new DWGitshConfig(DiskManager); this.Cache = cache ?? new CacheContainer(DiskManager); this.Utils = utils ?? new GitUtils(DiskManager, Cache); this.RepoPaths = repoPaths; }
public void Setup() { _diskManager = Substitute.For <IStaticAbstraction>(); _pathManager = Substitute.For <IPath>(); _pathManager.Combine(Arg.Any <string>(), Arg.Any <string>()).Returns(x => { var data = x.Arg <string[]>(); return(data[0].TrimEnd('\\') + "\\" + data[1].TrimStart('\\')); }); _diskManager.Path.Returns(_pathManager); _cacheManager = Substitute.For <ICacheContainer>(); _gitUtils = new GitUtils(_diskManager, _cacheManager); }
private static string FindAppDataFolder(IStaticAbstraction diskManager) { var basePath = diskManager.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var dataFolder = diskManager.Path.Combine(basePath, "DWGitsh"); if (!diskManager.Directory.Exists(dataFolder)) { diskManager.Directory.CreateDirectory(dataFolder); } return(dataFolder); }
public void Setup() { _hitManager = Substitute.For <IHitDataManager>(); _options = Substitute.For <IGitChangeDirectoryOptions>(); _diskManager = Substitute.For <IStaticAbstraction>(); _repoPaths = Substitute.For <IRepositoryPaths>(); _config = Substitute.For <IDWGitshConfig>(); _args = Substitute.For <IDWGitshCommonArgs>(); _args.DiskManager.Returns(_diskManager); _args.RepoPaths.Returns(_repoPaths); _args.Config.Returns(_config); }
public void TestSetup() { fullPath = "C:\\Some\\Folder\\With\\Files.txt"; fi = new MockFileInfo() { Name = "Files.txt", FullName = fullPath, LastWriteTime = DateTime.Now.AddDays(-1), Exists = true }; dm = Substitute.For <IStaticAbstraction>(); dm.File.Exists(Arg.Any <string>()).Returns(fi.Exists); dm.NewFileInfo(Arg.Any <string>()).Returns(fi); }
private static void ReadColorFile(IStaticAbstraction diskManager, string fullPath) { if (string.IsNullOrWhiteSpace(fullPath) || !diskManager.File.Exists(fullPath)) { return; } var lines = diskManager.File.ReadAllLines(fullPath); var isFirstLine = true; foreach (var line in lines) { // ignore blanks and the header line if (string.IsNullOrWhiteSpace(line) || (isFirstLine && line.IndexOf("Group,", StringComparison.InvariantCultureIgnoreCase) >= 0)) { continue; } var segments = line.Split(',').Select(x => x.Trim()).ToArray(); var groupName = segments[0]; ConsoleColor?fg = null; ConsoleColor?bg = null; if (segments.Length > 1) { fg = MatchColor(segments[1], true); } if (segments.Length > 2) { bg = MatchColor(segments[2], false); } if (fg.HasValue || bg.HasValue) { var color = new ColorPair(fg, bg); _definedColors[groupName] = color; if (_defaultGroupName == null) { _defaultGroupName = groupName; } } isFirstLine = false; } }
public static IProcessResult ExecuteCommandSync(IStaticAbstraction diskManager, IProcessManager processManager, string command, string runInfolder) { if (diskManager == null) { throw new ArgumentNullException(nameof(diskManager)); } if (processManager == null) { throw new ArgumentNullException(nameof(processManager)); } if (string.IsNullOrWhiteSpace(command)) { throw new ArgumentException("ExecuteCommandSync requires a valid command"); } if (!string.IsNullOrWhiteSpace(runInfolder) && !diskManager.Directory.Exists(runInfolder)) { throw new DirectoryNotFoundException($"ExecuteCommandSync - '{runInfolder}' does not exist"); } IProcessResult result = null; var curDir = diskManager.Directory.GetCurrentDirectory(); var changeDir = !string.IsNullOrWhiteSpace(runInfolder); try { if (changeDir) { diskManager.Directory.SetCurrentDirectory(runInfolder); } result = _processManager.Execute("cmd", "/c " + command, 10000); } catch (Exception ex) { throw ex; } if (changeDir) { diskManager.Directory.SetCurrentDirectory(curDir); } return(result); }
private static void LoadGitDirs(IStaticAbstraction diskManager) { _infoDir = diskManager.Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "gitsh", "localRepos"); if (!diskManager.Directory.Exists(_infoDir)) { return; } var repoNames = diskManager.Directory.GetFiles(_infoDir, "*.repo"); foreach (var repoName in repoNames) { var repoPath = diskManager.File.ReadAllText(repoName); var nameInfo = diskManager.NewFileInfo(repoName); var name = nameInfo.Name.Replace(nameInfo.Extension, ""); _gitDirs.Add(name, repoPath); } }
public DWGitshCommonArgs(IStaticAbstraction diskManager, IDWGitshConfig config, IRepositoryPaths repoPaths, IGitUtils utils) : this(diskManager, config, repoPaths, utils, null) { }
public DWGitshCommonArgs(IStaticAbstraction diskManager, IDWGitshConfig config) : this(diskManager, config, null, null, null) { }
public DWGitshCommonArgs(IStaticAbstraction diskManager) : this(diskManager, null, null, null, null) { }
public HitDataRepo(string dataFolder, IStaticAbstraction diskManager) { _diskManager = diskManager; _hitDataPath = _diskManager.Path.Combine(dataFolder, "hitData.json"); }
public DWGitshConfig(IStaticAbstraction diskManager) { _diskManager = diskManager; this.AppDataFolder = FindAppDataFolder(_diskManager); }
public void setup() { _diskManager = Substitute.For <IStaticAbstraction>(); DWPSUtils._diskManager = _diskManager; }
private GitUtils() { _diskManager = new StAbWrapper(); RepoCache = new CommandCache(); }
public WindowsAPI(IStaticAbstraction diskManager) { _diskManager = diskManager ?? new StAbWrapper(); }
public CacheDependencyCollection(IStaticAbstraction diskManager) { _diskManager = diskManager ?? new StAbWrapper(); }