public void CopyDirectory_CreateDestDirsNoOverwriteNoRecurse() { var srcDir = new DirectoryInfo(TargetDirToCopy); var uniqueFolder = Guid.NewGuid().ToString(); var destDir = new DirectoryInfo(Path.Combine(TargetDestDir, uniqueFolder, srcDir.Name)); var subDir = new DirectoryInfo(Path.Combine(TargetDestDir, uniqueFolder, srcDir.Name, TargetDirToCopySubdirName)); var target = new FileCopier(FileCopierFlags.CreateDestinationDirectories); target.CopyDirectory(srcDir.FullName, destDir.FullName); Assert.IsTrue(destDir.Exists); Assert.IsTrue(File.Exists(Path.Combine(destDir.FullName, ExistingDestTxtName))); Assert.IsTrue(File.Exists(Path.Combine(destDir.FullName, SrcFileName))); Assert.IsTrue(File.Exists(Path.Combine(destDir.FullName, ReadOnlyDestTxtName))); Assert.IsFalse(subDir.Exists); Assert.IsFalse(File.Exists(Path.Combine(subDir.FullName, ExistingDestTxtName))); Assert.IsFalse(File.Exists(Path.Combine(subDir.FullName, SrcFileName))); Assert.IsFalse(File.Exists(Path.Combine(subDir.FullName, ReadOnlyDestTxtName))); }
public void CopyDirectory_NonExistantSourceDir() { var toCopy = Guid.NewGuid() + @"\"; var target = new FileCopier(); target.CopyDirectory(toCopy, TargetDestDir); }
public void CopyDirectory_NonExistantDestDir_CreateFlagNotSet() { var srcDir = TargetSrcDir + @"\" + Guid.NewGuid(); var target = new FileCopier(); target.CopyDirectory(TargetDirToCopy, srcDir); }
private bool CopyToNonExistantDirectory(FileCopier copier) { string destPath = Path.Combine(TargetDestDir, @"newdir\another\out.txt"); return copier.TryCopyFile(SrcFilePath, destPath); }
private bool CopyToReadOnlyFile(FileCopier copier) { if (File.Exists(ReadOnlyDestTxtPath)) { FileInfo info = new FileInfo(ReadOnlyDestTxtPath); // ensure that the file is readonly. if (!info.IsReadOnly) { info.IsReadOnly = true; } return copier.TryCopyFile(SrcFilePath, ReadOnlyDestTxtPath); } else { Assert.Fail("The data for this test case has not been properly deployed! Missing file: " + ReadOnlyDestTxtPath); return false; } }
private bool CopyToDirectory(FileCopier copier) { return copier.TryCopyFile(SrcFilePath, TargetDestDir); }
private bool CopyToExistingFile(FileCopier copier) { if (File.Exists(ExistingDestTxtPath)) { return copier.TryCopyFile(SrcFilePath, ExistingDestTxtPath); } else { Assert.Fail("The data for this test case has not been properly deployed! Missing file: " + ExistingDestTxtPath); return false; } }
private bool CopyFileToNamedTarget(FileCopier copier) { string destPath = Path.Combine(TargetDestDir, @"out.txt"); return copier.TryCopyFile(SrcFilePath, destPath); }
public void TryCopyFile_SourceDir() { var target = new FileCopier(); target.TryCopyFile(TargetDestDir, TargetDestDir); }
public void TryCopyFile_NoFlags() { var target = new FileCopier(); Assert.IsTrue(this.CopyToDirectory(target)); Assert.IsTrue(this.CopyFileToNamedTarget(target)); Assert.IsFalse(this.CopyToExistingFile(target)); Assert.IsFalse(this.CopyToReadOnlyFile(target)); Assert.IsFalse(this.CopyToNonExistantDirectory(target)); }
public void TryCopyFile_CreateDestDirs() { var target = new FileCopier(FileCopierFlags.CreateDestinationDirectories); Assert.IsTrue(this.CopyToDirectory(target)); Assert.IsTrue(this.CopyFileToNamedTarget(target)); Assert.IsFalse(this.CopyToExistingFile(target)); Assert.IsFalse(this.CopyToReadOnlyFile(target)); Assert.IsTrue(this.CopyToNonExistantDirectory(target)); }
public void TryCopyFile_AlwaysOverwriteDestWithReadonly() { var target = new FileCopier(FileCopierFlags.AlwaysOverwriteDestination | FileCopierFlags.AttemptOverwriteReadonlyDest); Assert.IsTrue(this.CopyToDirectory(target)); Assert.IsTrue(this.CopyFileToNamedTarget(target)); Assert.IsTrue(this.CopyToExistingFile(target)); Assert.IsTrue(this.CopyToReadOnlyFile(target)); Assert.IsFalse(this.CopyToNonExistantDirectory(target)); }