public void TestReplaceIgnoreMerge() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString(); using (var fileStream = File.Create(tempLongPathFilename)) { fileStream.WriteByte(42); } var tempLongPathFilename2 = new StringBuilder(longPathDirectory).Append(@"\").Append("filename2.ext").ToString(); using (var fileStream = File.Create(tempLongPathFilename2)) { fileStream.WriteByte(52); } try { const bool ignoreMetadataErrors = true; File.Replace(tempLongPathFilename, tempLongPathFilename2, null, ignoreMetadataErrors); using (var fileStream = File.OpenRead(tempLongPathFilename2)) { Assert.AreEqual(42, fileStream.ReadByte()); } Assert.IsFalse(File.Exists(tempLongPathFilename)); } finally { if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } File.Delete(tempLongPathFilename2); } }
public void TestReplaceWithNulls() { string filename = Util.CreateNewFile(longPathDirectory); try { Assert.Throws <ArgumentNullException>(() => File.Replace(null, null, null)); } finally { File.Delete(filename); } }
public void TestReplaceWithNulls() { string filename = Util.CreateNewFile(longPathDirectory); try { File.Replace(null, null, null); } finally { File.Delete(filename); } }
public void TestReplaceIgnoreMergeNullDestination() { const bool ignoreMetadataErrors = true; string filename = Util.CreateNewFile(longPathDirectory); try { Assert.Throws <ArgumentNullException>(() => File.Replace(longPathFilename, null, null, ignoreMetadataErrors)); } finally { File.Delete(filename); } }
public void TestReplaceIgnoreMergeWithReadonlyBackupPath() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString(); var tempBackupPathName = new StringBuilder(longPathDirectory).Append(@"\readonly").ToString(); var di = new DirectoryInfo(tempBackupPathName); di.Create(); var attr = di.Attributes; di.Attributes = attr | FileAttributes.ReadOnly; var tempBackupLongPathFilename = new StringBuilder(tempBackupPathName).Append(@"\").Append("backup").ToString(); using (var fileStream = File.Create(tempLongPathFilename)) { fileStream.WriteByte(42); } var tempLongPathFilename2 = new StringBuilder(longPathDirectory).Append(@"\").Append("filename2.ext").ToString(); using (var fileStream = File.Create(tempLongPathFilename2)) { fileStream.WriteByte(52); } try { const bool ignoreMetadataErrors = true; File.Replace(tempLongPathFilename, tempLongPathFilename2, tempBackupLongPathFilename, ignoreMetadataErrors); using (var fileStream = File.OpenRead(tempLongPathFilename2)) { Assert.AreEqual(42, fileStream.ReadByte()); } Assert.IsFalse(File.Exists(tempLongPathFilename)); Assert.IsTrue(File.Exists(tempBackupLongPathFilename)); } finally { di.Attributes = attr; if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } File.Delete(tempLongPathFilename2); File.Delete(tempBackupLongPathFilename); if (Directory.Exists(tempBackupPathName)) { Directory.Delete(tempBackupPathName); } } }
public void TestReplaceIgnoreMergeWithInvalidBackupPath() { Assert.Throws <DirectoryNotFoundException>(() => { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString(); var tempBackupLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\gibberish\").Append("backup").ToString(); using (var fileStream = File.Create(tempLongPathFilename)) { fileStream.WriteByte(42); } var tempLongPathFilename2 = new StringBuilder(longPathDirectory).Append(@"\").Append("filename2.ext").ToString(); using (var fileStream = File.Create(tempLongPathFilename2)) { fileStream.WriteByte(52); } try { const bool ignoreMetadataErrors = true; File.Replace(tempLongPathFilename, tempLongPathFilename2, tempBackupLongPathFilename, ignoreMetadataErrors); using (var fileStream = File.OpenRead(tempLongPathFilename2)) { Assert.AreEqual(42, fileStream.ReadByte()); } Assert.IsFalse(File.Exists(tempLongPathFilename)); Assert.IsTrue(File.Exists(tempBackupLongPathFilename)); } finally { if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } File.Delete(tempLongPathFilename2); File.Delete(tempBackupLongPathFilename); } }); }
public static void Replace(string sourcePath, string destinationPath, string destinationBackupPath, bool ignoreMetadataErrors) { File.Replace(sourcePath, destinationPath, destinationBackupPath, ignoreMetadataErrors); }
public static void Replace(string sourcePath, string destinationPath, string destinationBackupPath) { File.Replace(sourcePath, destinationPath, destinationBackupPath); }
public void TestReplaceIgnoreMergeNulls() { const bool ignoreMetadataErrors = true; Assert.Throws <ArgumentNullException>(() => File.Replace(null, null, null, ignoreMetadataErrors)); }
public void TestReplaceWithNullDestination() { Assert.Throws <ArgumentNullException>(() => File.Replace(longPathFilename, null, null)); }
public void TestReplaceIgnoreMergeNulls() { const bool ignoreMetadataErrors = true; File.Replace(null, null, null, ignoreMetadataErrors); }
public void TestReplaceWithNullDestination() { File.Replace(longPathFilename, null, null); }