Beispiel #1
0
        public void GetPathToRepository_gitPathUpTree()
        {
            var dirPath  = "C:\\junk\\folder\\does\\not\\exist";
            var dirInfo  = BuildDirectoryInfo(dirPath);
            var expected = "C:\\junk\\";

            _diskManager.NewDirectoryInfo("somePath").Returns(dirInfo);
            _diskManager.Directory.Exists(expected + ".git").Returns(true);

            var result = _gitUtils.GetPathToRepository("somePath");

            Assert.AreEqual(result, expected);
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        public string GetPathToRepository(string currentPath)
        {
            if (string.IsNullOrWhiteSpace(currentPath))
            {
                return(null);
            }
            var curDir = _diskManager.NewDirectoryInfo(currentPath);

            if (curDir == null)
            {
                return(null);
            }

            while (curDir != null)
            {
                var path = _diskManager.Path.Combine(curDir.FullName, ".git");
                if (_diskManager.Directory.Exists(path))
                {
                    return(DWPSUtils.ForceTrailingSlash(curDir.FullName));
                }
                curDir = curDir.Parent;
            }

            return(null);
        }
Beispiel #4
0
        public void GetDirectoryPath_existingFolder(string folder, string expected)
        {
            _diskManager.File.Exists(Arg.Any <string>()).Returns(false);
            _diskManager.Directory.Exists(folder).Returns(true);
            var info = Substitute.For <IDirectoryInfo>();

            info.FullName.Returns(folder);

            _diskManager.NewDirectoryInfo(folder).Returns(info);

            var result = DWPSUtils.GetDirectoryPath(folder);

            Assert.AreEqual(result, expected);
        }
Beispiel #5
0
        private int GetPathAttribute(string path)
        {
            var di = _diskManager.NewDirectoryInfo(path);

            if (di.Exists)
            {
                return(FILE_ATTRIBUTE_DIRECTORY);
            }

            var fi = _diskManager.NewFileInfo(path);

            if (fi.Exists)
            {
                return(FILE_ATTRIBUTE_NORMAL);
            }
            else if (!string.IsNullOrEmpty(fi.Extension))
            {
                // guess that if it has an extension that it should be a file
                return(FILE_ATTRIBUTE_NORMAL);
            }

            throw new FileNotFoundException();
        }
Beispiel #6
0
        public void BuildRelativePath_basic(string source, string target, string expected)
        {
            _diskManager.NewDirectoryInfo(source).Returns(new MockDirectoryInfo {
                Exists = true
            });
            _diskManager.NewFileInfo(source).Returns(new MockFileInfo {
                Exists = false
            });

            _diskManager.NewDirectoryInfo(target).Returns(new MockDirectoryInfo {
                Exists = true
            });
            _diskManager.NewFileInfo(target).Returns(new MockFileInfo {
                Exists = false
            });

            var relPath = DWPSUtils.BuildRelativePath(source, target);

            Assert.AreEqual(expected, relPath);
        }