Ejemplo n.º 1
0
 public void BackupFilesNullBackupRootTest()
 {
     Assert.Throws <ArgumentException>(
         delegate
     {
         BackupUtilities.BackupFiles(null, "123456789", new string[] { "c:\test\test.cs" });
     });
 }
Ejemplo n.º 2
0
 public void BackupFilesNullKeyTest()
 {
     Assert.Throws <ArgumentException>(
         delegate
     {
         BackupUtilities.BackupFiles("c:\temp", null, new string[] { "c:\test\test.cs" });
     });
 }
Ejemplo n.º 3
0
 public void BackupFilesNullKeyTest()
 {
     Assert.Throws(typeof(ArgumentException), () => BackupUtilities.BackupFiles("c:\temp", null, new string[] { "c:\test\test.cs" }));
 }
Ejemplo n.º 4
0
 public void BackupFilesNullBackupRootTest()
 {
     Assert.Throws(typeof(ArgumentException), () => BackupUtilities.BackupFiles(null, "123456789", new string[] { "c:\test\test.cs" }));
 }
Ejemplo n.º 5
0
        public void BackupAndRestoreTest()
        {
            string backupRoot        = BackupUtilities.CreateTempFilePath();
            string sourceFolder      = BackupUtilities.CreateTempFilePath();
            string destinationFolder = BackupUtilities.CreateTempFilePath();

            try
            {
                Directory.CreateDirectory(sourceFolder);

                string file1Text = "This is test file 1.";
                string file2Text = "This is test file 2.";
                string file3Text = "This is test file 3.";

                string file1          = Path.Combine(sourceFolder, "File1.txt");
                string file2Directory = Path.Combine(sourceFolder, "a");
                string file2          = Path.Combine(file2Directory, "File2.txt");
                string file3Directory = Path.Combine(sourceFolder, "b");
                string file3          = Path.Combine(file3Directory, "File3.txt");

                File.WriteAllText(file1, file1Text);
                Directory.CreateDirectory(file2Directory);
                File.WriteAllText(file2, file2Text);
                Directory.CreateDirectory(file3Directory);
                File.WriteAllText(file3, file3Text);

                string key            = BackupUtilities.CreateFileNameKey("Test");
                string backupLocation = BackupUtilities.BackupFiles(
                    backupRoot,
                    key,
                    new string[] { file1, file2, file3 });

                string zipFile = Path.Combine(backupLocation, "files.zip");
                Assert.IsTrue(File.Exists(zipFile), "Expected zip file to exist after backup.");
                TestUtilities.AssertNotEmpty(zipFile);

                //
                // Modify the original files
                //
                File.WriteAllText(file1, "Blah");
                File.WriteAllText(file2, "Blah");
                File.Delete(file3);

                BackupUtilities.RestoreFiles(backupRoot, key);

                Assert.IsTrue(File.Exists(file1), "Restored file was not found.");
                Assert.AreEqual(file1Text, File.ReadAllText(file1), "Unexpected file contents.");
                Assert.IsTrue(File.Exists(file2), "Restored file was not found.");
                Assert.AreEqual(file2Text, File.ReadAllText(file2), "Unexpected file contents.");
                Assert.IsTrue(File.Exists(file3), "Restored file was not found.");
                Assert.AreEqual(file3Text, File.ReadAllText(file3), "Unexpected file contents.");
            }
            finally
            {
                try
                {
                    Directory.Delete(sourceFolder, true);
                    Directory.Delete(destinationFolder, true);
                    Directory.Delete(backupRoot, true);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 6
0
 public void BackupFilesNullBackupRootTest()
 {
     BackupUtilities.BackupFiles(null, "123456789", new string[] { "c:\test\test.cs" });
 }
Ejemplo n.º 7
0
 public void BackupFilesNullKeyTest()
 {
     BackupUtilities.BackupFiles("c:\temp", null, new string[] { "c:\test\test.cs" });
 }