Example #1
0
        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)));
        }
Example #2
0
 public void CopyDirectory_NonExistantSourceDir()
 {
     var toCopy = Guid.NewGuid() + @"\";
     var target = new FileCopier();
     target.CopyDirectory(toCopy, TargetDestDir);
 }
Example #3
0
 public void CopyDirectory_NonExistantDestDir_CreateFlagNotSet()
 {
     var srcDir = TargetSrcDir + @"\" + Guid.NewGuid();
     var target = new FileCopier();
     target.CopyDirectory(TargetDirToCopy, srcDir);
 }
Example #4
0
 private bool CopyToNonExistantDirectory(FileCopier copier)
 {
     string destPath = Path.Combine(TargetDestDir, @"newdir\another\out.txt");
     return copier.TryCopyFile(SrcFilePath, destPath);
 }
Example #5
0
        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;
            }
        }
Example #6
0
 private bool CopyToDirectory(FileCopier copier)
 {
     return copier.TryCopyFile(SrcFilePath, TargetDestDir);
 }
Example #7
0
 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;
     }
 }
Example #8
0
 private bool CopyFileToNamedTarget(FileCopier copier)
 {
     string destPath = Path.Combine(TargetDestDir, @"out.txt");
     return copier.TryCopyFile(SrcFilePath, destPath);
 }
Example #9
0
 public void TryCopyFile_SourceDir()
 {
     var target = new FileCopier();
     target.TryCopyFile(TargetDestDir, TargetDestDir);
 }
Example #10
0
        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));
        }
Example #11
0
        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));
        }
Example #12
0
        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));
        }