示例#1
0
        public void FileChangeRestoreMissing()
        {
            FileChange f;
            String     filePath;


            //
            // Make sure the original file does not exist.
            //
            filePath = Path.GetTempFileName();
            new FileInfo(filePath).Delete();
            f = new FileChange(new FileInfo(filePath));

            //
            // Update the content.
            //
            using (FileStream writer = new FileInfo(filePath).OpenWrite())
            {
                byte[] data = new System.Text.UTF8Encoding().GetBytes("Some new content to replace the old.");

                writer.Write(data, 0, data.Length);
            }

            //
            // Verify the file now exists.
            //
            Assert.IsTrue(new FileInfo(filePath).Exists, "Failed to create a new file.");

            //
            // Restore the file and verify it no longer exists.
            //
            f.Restore();
            Assert.IsTrue((new FileInfo(filePath).Exists == false), "Restore operation failed.");
        }
示例#2
0
        public void FileChangeRestoreOriginal()
        {
            FileChange f;
            String     filePath;
            String     origMD5;


            //
            // Put some original content in.
            //
            filePath = Path.GetTempFileName();
            using (FileStream writer = new FileInfo(filePath).OpenWrite())
            {
                byte[] data = new System.Text.UTF8Encoding().GetBytes("This is a test message.");

                writer.Write(data, 0, data.Length);
            }
            origMD5 = InstallTest.MD5FromPath(filePath);
            f       = new FileChange(new FileInfo(filePath));

            //
            // Update the content.
            //
            using (FileStream writer = new FileInfo(filePath).OpenWrite())
            {
                byte[] data = new System.Text.UTF8Encoding().GetBytes("Some new content to replace the old.");

                writer.Write(data, 0, data.Length);
            }

            //
            // Verify the changed data.
            //
            Assert.IsTrue((origMD5.Equals(InstallTest.MD5FromPath(filePath)) == false), "Failed to update the file contents.");

            //
            // Restore the file and verify original contents.
            //
            f.Restore();
            Assert.IsTrue(origMD5.Equals(InstallTest.MD5FromPath(filePath)), "Restore operation failed.");

            new FileInfo(filePath).Delete();
        }