public void TestCopy() { var tempLongPathFilename = new StringBuilder(uncDirectory).Append(@"\").Append("file22.ext").ToString(); var tempDestLongPathFilename = new StringBuilder(uncDirectory).Append(@"\").Append("file22-1.ext").ToString(); Assert.IsFalse(File.Exists(tempLongPathFilename)); File.Copy(filePath, tempLongPathFilename); try { Assert.IsTrue(File.Exists(tempLongPathFilename)); File.Move(tempLongPathFilename, tempDestLongPathFilename); try { Assert.IsFalse(File.Exists(tempLongPathFilename)); Assert.IsTrue(File.Exists(tempDestLongPathFilename)); } finally { File.Delete(tempDestLongPathFilename); } } finally { if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } } }
public void TestMoveTo() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file21.ext").ToString(); var tempDestLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file21-1.ext").ToString(); Assert.IsFalse(File.Exists(tempLongPathFilename)); File.Copy(longPathFilename, tempLongPathFilename); try { Assert.IsTrue(File.Exists(tempLongPathFilename)); var fi = new FileInfo(tempLongPathFilename); fi.MoveTo(tempDestLongPathFilename); try { Assert.IsFalse(File.Exists(tempLongPathFilename)); Assert.IsTrue(File.Exists(tempDestLongPathFilename)); } finally { File.Delete(tempDestLongPathFilename); } } finally { if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } } }
public void TestCopyWithoutOverwriteAndExistingFile() { var destLongPathFilename = new StringBuilder(uncDirectory).Append(@"\").Append("filename (Copy).ext").ToString(); File.Copy(filePath, destLongPathFilename); try { Assert.IsTrue(File.Exists(destLongPathFilename)); Assert.Throws <IOException>(() => File.Copy(filePath, destLongPathFilename)); } finally { File.Delete(destLongPathFilename); } }
public void TestCopyWithOverwrite() { var destLongPathFilename = new StringBuilder(uncDirectory).Append(@"\").Append("filename (Copy).ext").ToString(); File.Copy(filePath, destLongPathFilename); try { Assert.IsTrue(File.Exists(destLongPathFilename)); File.Copy(filePath, destLongPathFilename, true); Assert.AreEqual(File.ReadAllText(filePath), File.ReadAllText(destLongPathFilename)); } finally { File.Delete(destLongPathFilename); } }