public void Resolve_should_return_original_path_if_git_file_or_folder_absent() { _directory.Exists(_gitWorkingDir).Returns(false); _file.Exists(Arg.Any <string>()).Returns(false); _resolver.Resolve(_workingDir).Should().Be(_workingDir); }
private string GetPathWithCorrectDirectoryCapitalization(string fullPath) { string[] splitPath = fullPath.Split(Path.DirectorySeparatorChar); string leftHalf = fullPath; string rightHalf = ""; for (int i = splitPath.Length - 1; i > 1; i--) { rightHalf = i == splitPath.Length - 1 ? splitPath[i] : splitPath[i] + Path.DirectorySeparatorChar + rightHalf; int lastSeparator = leftHalf.LastIndexOf(Path.DirectorySeparatorChar); leftHalf = lastSeparator > 0 ? leftHalf.Substring(0, lastSeparator) : leftHalf; if (_directory.Exists(leftHalf)) { leftHalf += Path.DirectorySeparatorChar; leftHalf = _pathField.GetFullPath(leftHalf); string baseDirectory = AllDirectories.First(dir => dir.Equals(leftHalf, StringComparison.OrdinalIgnoreCase)); return(baseDirectory + rightHalf); } } return(fullPath); }
public void AddFile(string path, MockFileData mockFile) { string fixedPath = FixPath(path); lock (_files) { if (FileExists(fixedPath)) { bool isReadOnly = (_files[fixedPath].Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; bool isHidden = (_files[fixedPath].Attributes & FileAttributes.Hidden) == FileAttributes.Hidden; if (isReadOnly || isHidden) { throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ACCESS_TO_THE_PATH_IS_DENIED, path)); } } string directoryPath = Path.GetDirectoryName(fixedPath); if (!_directory.Exists(directoryPath)) { AddDirectory(directoryPath); } _files[fixedPath] = mockFile; } }
public void AddFile(string path, MockFileData mockFile) { var fixedPath = FixPath(path); lock (files) { if (FileExists(fixedPath)) { var isReadOnly = (files[fixedPath].Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; var isHidden = (files[fixedPath].Attributes & FileAttributes.Hidden) == FileAttributes.Hidden; if (isReadOnly || isHidden) { throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture, "Access to the path '{0}' is denied.", path)); } } var directoryPath = Path.GetDirectoryName(fixedPath); if (!directory.Exists(directoryPath)) { AddDirectory(directoryPath); } files[fixedPath] = mockFile; } }
public void AddFile(string path, MockFileData mockFile) { var fixedPath = FixPath(path); lock (files) { if (FileExists(fixedPath)) { var isReadOnly = (files[fixedPath].Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; var isHidden = (files[fixedPath].Attributes & FileAttributes.Hidden) == FileAttributes.Hidden; if (isReadOnly || isHidden) { throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("ACCESS_TO_THE_PATH_IS_DENIED"), path)); } } var directoryPath = Path.GetDirectoryName(fixedPath); if (!directory.Exists(directoryPath)) { AddDirectory(directoryPath); } files[fixedPath] = mockFile; } }
public async Task Clear_should_return_if_folder_absent() { _directory.Exists(Arg.Any <string>()).Returns(false); await _cache.ClearAsync(); _directory.DidNotReceive().GetFiles(Arg.Any <string>()); }
public void MergeOrCommitMessage_should_write_merge_message_if_exists() { bool correctlyWritten = false; _file.When(x => x.WriteAllText(_mergeMessagePath, _newMessage, _encoding)).Do(_ => correctlyWritten = true); _file.Exists(_commitMessagePath).Returns(true); _file.Exists(_mergeMessagePath).Returns(true); _directory.Exists(Path.GetDirectoryName(_commitMessagePath)).Returns(true); _manager.MergeOrCommitMessage = _newMessage; Assert.That(correctlyWritten); }
public void ConfigRepositoryRemoveSiteTest() { FileHelper.FileSystem = new MockFileSystem(new Dictionary <string, MockFileData>() { { @"c:\site1.publishsettings", new MockFileData(string.Format(ProfileTemplate, "site1")) }, { @"c:\site2.foo.publishsettings", new MockFileData(string.Format(ProfileTemplate, "site2")) }, { @"c:\foo.txt", new MockFileData("bar") }, { @"c:\site1\", new MockDirectoryData() } }); IConfigRepository repository = new ConfigRepository(); repository.RemoveSite("site1"); repository.RemoveSite("site2"); FileBase fileBase = FileHelper.FileSystem.File; DirectoryBase dirBase = FileHelper.FileSystem.Directory; Assert.IsFalse(fileBase.Exists(@"c:\site1.publishSettings"), "site1 publishSettings still exists"); Assert.IsFalse(dirBase.Exists(@"c:\site1"), "site1 folder still exists"); Assert.IsFalse(fileBase.Exists(@"c:\site2.foo.publishsettings"), "sit2 publishSettings still exists"); }
public void Setup() { _gitFile = Path.Combine(_workingDir, ".git"); _gitWorkingDir = _gitFile.EnsureTrailingPathSeparator(); _file = Substitute.For <FileBase>(); _directory = Substitute.For <DirectoryBase>(); _fileSystem = Substitute.For <IFileSystem>(); _fileSystem.Directory.Returns(_directory); _fileSystem.File.Returns(_file); _directory.Exists(_workingDir).Returns(true); _resolver = new GitDirectoryResolver(_fileSystem); }
public void AddFile(string path, MockFileData mockFile) { var fixedPath = FixPath(path); throwExceptionWhenReadonly(path, fixedPath); var directoryPath = Path.GetDirectoryName(fixedPath); lock (files) { if (!directory.Exists(directoryPath)) { directory.CreateDirectory(directoryPath); } files[fixedPath] = mockFile; } }
public void Setup() { if (Type.GetType("Mono.Runtime") != null) { _workingDir = "/home/user/repo"; } _gitFile = Path.Combine(_workingDir, ".git"); _gitWorkingDir = _gitFile.EnsureTrailingPathSeparator(); _file = Substitute.For <FileBase>(); _directory = Substitute.For <DirectoryBase>(); _fileSystem = Substitute.For <IFileSystem>(); _fileSystem.Directory.Returns(_directory); _fileSystem.File.Returns(_file); _directory.Exists(_workingDir).Returns(true); _resolver = new GitDirectoryResolver(_fileSystem); }
public MockFileSystem(IDictionary<string, MockFileData> files) { file = new MockFile(this); directory = new MockDirectory(this, file); fileInfoFactory = new MockFileInfoFactory(this); path = new MockPath(); directoryInfoFactory = new MockDirectoryInfoFactory(this); //For each mock file add a file to the files dictionary //Also add a file entry for all directories leading up to this file this.files = new Dictionary<string, MockFileData>(StringComparer.InvariantCultureIgnoreCase); foreach (var entry in files) { var directoryPath = Path.GetDirectoryName(entry.Key); if (!directory.Exists(directoryPath)) directory.CreateDirectory(directoryPath); if (!file.Exists(entry.Key)) this.files.Add(entry.Key, entry.Value); } }
public void AddFile(string path, MockFileData mockFile) { var fixedPath = FixPath(path); if (FileExists(fixedPath) && (files[fixedPath].Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { throw new UnauthorizedAccessException(string.Format("Access to the path '{0}' is denied.", path)); } var directoryPath = Path.GetDirectoryName(fixedPath); lock (files) { if (!directory.Exists(directoryPath)) { directory.CreateDirectory(directoryPath); } files[fixedPath] = mockFile; } }