Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void TestReplaceWithNulls()
        {
            string filename = Util.CreateNewFile(longPathDirectory);

            try
            {
                Assert.Throws <ArgumentNullException>(() => File.Replace(null, null, null));
            }
            finally
            {
                File.Delete(filename);
            }
        }
Exemplo n.º 3
0
        public void TestReplaceWithNulls()
        {
            string filename = Util.CreateNewFile(longPathDirectory);

            try
            {
                File.Replace(null, null, null);
            }
            finally
            {
                File.Delete(filename);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        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);
                }
            });
        }
Exemplo n.º 7
0
 public static void Replace(string sourcePath, string destinationPath, string destinationBackupPath, bool ignoreMetadataErrors)
 {
     File.Replace(sourcePath, destinationPath, destinationBackupPath, ignoreMetadataErrors);
 }
Exemplo n.º 8
0
 public static void Replace(string sourcePath, string destinationPath, string destinationBackupPath)
 {
     File.Replace(sourcePath, destinationPath, destinationBackupPath);
 }
Exemplo n.º 9
0
        public void TestReplaceIgnoreMergeNulls()
        {
            const bool ignoreMetadataErrors = true;

            Assert.Throws <ArgumentNullException>(() => File.Replace(null, null, null, ignoreMetadataErrors));
        }
Exemplo n.º 10
0
 public void TestReplaceWithNullDestination()
 {
     Assert.Throws <ArgumentNullException>(() => File.Replace(longPathFilename, null, null));
 }
Exemplo n.º 11
0
        public void TestReplaceIgnoreMergeNulls()
        {
            const bool ignoreMetadataErrors = true;

            File.Replace(null, null, null, ignoreMetadataErrors);
        }
Exemplo n.º 12
0
 public void TestReplaceWithNullDestination()
 {
     File.Replace(longPathFilename, null, null);
 }