public void RestoreFilesNullKeyTest() { Assert.Throws <ArgumentException>( delegate { BackupUtilities.RestoreFiles("c:\temp", null); }); }
public void RestoreFilesNullBackupRootTest() { Assert.Throws <ArgumentException>( delegate { BackupUtilities.RestoreFiles(null, "123456789"); }); }
/// <summary> /// Runs NArrange using the specified arguments. /// </summary> /// <param name="logger">Logger for messages.</param> /// <param name="commandArgs">Command arguments.</param> /// <returns>True if succesful, otherwise false.</returns> public static bool Run(ILogger logger, CommandArguments commandArgs) { bool success = true; if (logger == null) { throw new ArgumentNullException("logger"); } else if (commandArgs == null) { throw new ArgumentNullException("commandArgs"); } if (commandArgs.Restore) { logger.LogMessage(LogLevel.Verbose, "Restoring {0}...", commandArgs.Input); string key = BackupUtilities.CreateFileNameKey(commandArgs.Input); try { success = BackupUtilities.RestoreFiles(BackupUtilities.BackupRoot, key); } catch (Exception ex) { logger.LogMessage(LogLevel.Warning, ex.Message); success = false; } if (success) { logger.LogMessage(LogLevel.Info, "Restored"); } else { logger.LogMessage(LogLevel.Error, "Restore failed"); } } else { // // Arrange the source code file // FileArranger fileArranger = new FileArranger(commandArgs.Configuration, logger); success = fileArranger.Arrange(commandArgs.Input, commandArgs.Output, commandArgs.Backup); if (!success) { logger.LogMessage(LogLevel.Error, "Unable to arrange {0}.", commandArgs.Input); } else { logger.LogMessage(LogLevel.Info, "Arrange successful."); } } return(success); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); ((Logger)logger).EmitHeader(); //! Get Active Document Path. DTE dte = (DTE)ServiceProvider.GetServiceAsync(typeof(DTE))?.Result; if (dte == null) { logger.LogMessage(LogLevel.Error, "NArrange Could not obtain DTE.", new object[] { }); return; } string document = dte?.ActiveDocument?.FullName; if (String.IsNullOrEmpty(document)) { logger.LogMessage(LogLevel.Error, "NArrange Could not obtain the Path of the ActiveDocument.", new object[] { }); return; } //! No CommandArguments (i.e. null). FileArranger fileArranger = new FileArranger(null, logger); string key = BackupUtilities.CreateFileNameKey(document); if (Directory.Exists(Path.Combine(BackupUtilities.BackupRoot, key))) { logger.LogMessage(LogLevel.Info, $"Restoring backup from {Path.Combine(BackupUtilities.BackupRoot, key)}..."); //! Try to Undo NArrange of the Active File. Boolean success = BackupUtilities.RestoreFiles(BackupUtilities.BackupRoot, key); switch (success) { case true: logger.LogMessage(LogLevel.Info, "Undo NArrange Successful.", new object[] { }); break; case false: logger.LogMessage(LogLevel.Error, "Undo NArrange Failure.", new object[] { }); break; } } else { logger.LogMessage(LogLevel.Warning, "NArrange backup folder not found.", new object[] { }); } }
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 { } } }
public void RestoreFilesNullKeyTest() { Assert.Throws(typeof(ArgumentException), () => BackupUtilities.RestoreFiles("c:\temp", null)); }
public void RestoreFilesNullBackupRootTest() { Assert.Throws(typeof(ArgumentException), () => BackupUtilities.RestoreFiles(null, "123456789")); }
public void RestoreFilesNullKeyTest() { BackupUtilities.RestoreFiles("c:\temp", null); }
public void RestoreFilesNullBackupRootTest() { BackupUtilities.RestoreFiles(null, "123456789"); }