示例#1
0
        public void Replace3()
        {
            string tempFile   = Path.Combine(Path.GetTempPath(), "OriginalFile.txt");
            string tempFile2  = Path.Combine(Path.GetTempPath(), "NewFile.txt");
            string backupFile = Path.Combine(Path.GetTempPath(), "OriginalFileBackup.txt");
            string expected   = "This is a test.";

            File.Delete(tempFile);
            File.Delete(tempFile2);
            File.Delete(backupFile);

            File.AppendAllText(tempFile, expected);
            File.AppendAllText(tempFile2, String.Empty);

            // Move the contents of tempFile into tempFile2
            ExtendedFileInfo efi = new ExtendedFileInfo(tempFile);

            efi.Replace(tempFile2, backupFile, true);

            Assert.IsTrue(File.Exists(backupFile));
            Assert.IsTrue(File.Exists(tempFile2));

            string actual = File.ReadAllText(tempFile2);

            Assert.AreEqual(expected, actual);
        }