public WorkspaceEditDocumentChange(RenameFile renameFile) { TextDocumentEdit = null; CreateFile = null; RenameFile = renameFile; DeleteFile = null; }
private void CheckIfCancelIsPressed(RenameFileBindingModel renameFileBindingModel) { //Uses RenameFileBindingModel to set its properties if (renameFileBindingModel.IsPressed == false) { //Uses the Rename method from the RenamerFile service renameFileService.Rename(renameFileBindingModel); //Checks if file is renamed successfully if (renameFileBindingModel.IsRenamed == true) { //If it is renamed successfully it sets the variables and returns them. string oldFile = renameFileBindingModel.FileName.Split('\\').Last(); oldName = $"File {oldFile} renamed to:"; newName = renameFileBindingModel.NewName + Path.GetExtension(renameFileBindingModel.FileName); } else { //If it is not renamed successfully it returns this. oldName = "File was not renamed"; } } RenameFileForm.Dispose(); RenameFileForm = new RenameFile(); }
} // end SortByFilename #endregion #endregion #region Renaming #region Rename public bool Rename(string sRenameProperty, string sPrefix, string sMask, bool bTestRun) { RenameFile RenameFileMethod = ChooseRenamingMethod(sRenameProperty); Mask mask = new Mask(sMask); string sPrevious = ""; string sNewName; int iCounter = 0; foreach (PowerFile powerFile in List) { sNewName = RenameFileMethod(powerFile, sRenameProperty); if (sNewName == sPrevious) { iCounter++; } // end if else { sPrevious = sNewName; iCounter = 1; } // end else FileRenamed(this, powerFile.Rename(sNewName, sPrefix, mask.FormatSuffix(iCounter), bTestRun)); } // end foreach return(true); } // end Rename
public void ShouldFailOnError() { var buildArtifact = new File("c:\\nonexistant.txt"); var fileSystemWrapper = MockRepository.GenerateStub<IFileSystemWrapper>(); var subject = new RenameFile(fileSystemWrapper, buildArtifact); fileSystemWrapper.Stub(x => x.MoveFile("", "")).IgnoreArguments().Throw(new IOException("Could not do that")); subject.FailOnError.To("nonexistant2.txt"); }
public static void CheckIfUserPressesEnterNonAsync(string textBoxText, RenameFile RenameFileForm, KeyPressEventArgs e, RenameFileBindingModel bindingModel) { //uses string textBoxText to get user input for a new name of a file //uses RenameFile Form, KeyPressEventArgs to check if user has done everything properly on that form. //uses RenameFileBindingModel to set its properties. if (e.KeyChar == (char)Keys.Enter) { //checks if user has pressed Enter in RenameFile Form CheckIfTextBoxIsEmpty(textBoxText, RenameFileForm, bindingModel); } }
/// <summary> /// /// </summary> private void RenameFile(string oldPath, string newPath) { try { RenameFile command = new RenameFile(oldPath, newPath); command.Execute(); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
public void ShouldCallWrapperMoveFile() { string origin = "c:\\nonexistant.txt"; string destination = "nonexistant2.txt"; var buildArtifact = new File(origin); var fileSystemWrapper = MockRepository.GenerateMock<IFileSystemWrapper>(); var subject = new RenameFile(fileSystemWrapper, buildArtifact); subject.To(destination); fileSystemWrapper.AssertWasCalled(x=>x.MoveFile(origin, "c:\\\\" + destination)); }
public void PathShouldBeChangedAfterRename() { string origin = "c:\\nonexistant.txt"; string destination = "nonexistant2.txt"; var buildArtifact = new File(origin); var fileSystemWrapper = MockRepository.GenerateMock<IFileSystemWrapper>(); var subject = new RenameFile(fileSystemWrapper, buildArtifact); var destinationWithFolder = @"c:\\" + destination; fileSystemWrapper.Stub(x => x.MoveFile(origin, destinationWithFolder)); subject.To(destination); Assert.That(buildArtifact.ToString(), Is.EqualTo(destinationWithFolder)); }
public void ShouldThrowExceptionWhenSourceDoesntExist() { var mockBounce = new Mock<IBounce>(); var from = Path.GetTempFileName(); //GetTempFileName() creates the file var to = Path.GetTempFileName(); File.Delete(from); File.Delete(to); Assert.That(File.Exists(from), Is.False, "File " + from + " should not exist"); Assert.That(File.Exists(to), Is.False, "File " + to + " should not exist"); var rename = new RenameFile { From = from, To = to }; Assert.Throws<ArgumentException>(() => rename.Build(mockBounce.Object)); }
private static void CheckIfTextBoxIsEmpty(string textBoxText, RenameFile RenameFileForm, RenameFileBindingModel bindingModel) { //uses string textBoxText to get user input for a name of a file //uses RenameFile Form to check if user has done everything properly on that form. //uses RenameFileBindingModel to set its properties. if (textBoxText != "") { SetRenameFileBindingModelNewName(textBoxText, bindingModel); RenameFileForm.Close(); } else { ShowMessageBox(); } }
public static async void CheckIfTextBoxIsEmptyAsync(string textBoxText, RenameFile RenameFileForm, RenameFileBindingModel bindingModel) { //uses string textBoxText to get user input for a name of a file //uses RenameFile Form to check if user has done everything properly on that form. //uses RenameFileBindingModel to set its properties. if (textBoxText != "") { await Task.Run(() => SetRenameFileBindingModelNewName(textBoxText, bindingModel)); RenameFileForm.Close(); } else { await Task.Run(() => ShowMessageBox()); } }
public void ShouldRenameFile() { var mockBounce = new Mock<IBounce>(); var from = Path.GetTempFileName(); var to = Path.GetTempFileName(); File.Delete(to); //GetTempFileName() creates the file Assert.That(File.Exists(from), Is.True, "File " + from + " should exist"); Assert.That(File.Exists(to), Is.False, "File " + to + " should not exist"); var rename = new RenameFile {From = from, To = to}; rename.Build(mockBounce.Object); Assert.That(File.Exists(from), Is.False, "File " + from + " should not exist"); Assert.That(File.Exists(to), Is.True, "File " + to + " should exist"); File.Delete(to); }
public void ShouldThrowExceptionWhenSourceDoesntExist() { var mockBounce = new Mock <IBounce>(); var from = Path.GetTempFileName(); //GetTempFileName() creates the file var to = Path.GetTempFileName(); File.Delete(from); File.Delete(to); Assert.That(File.Exists(from), Is.False, "File " + from + " should not exist"); Assert.That(File.Exists(to), Is.False, "File " + to + " should not exist"); var rename = new RenameFile { From = from, To = to }; Assert.Throws <ArgumentException>(() => rename.Build(mockBounce.Object)); }
public void ShouldRenameFile() { var mockBounce = new Mock <IBounce>(); var from = Path.GetTempFileName(); var to = Path.GetTempFileName(); File.Delete(to); //GetTempFileName() creates the file Assert.That(File.Exists(from), Is.True, "File " + from + " should exist"); Assert.That(File.Exists(to), Is.False, "File " + to + " should not exist"); var rename = new RenameFile { From = from, To = to }; rename.Build(mockBounce.Object); Assert.That(File.Exists(from), Is.False, "File " + from + " should not exist"); Assert.That(File.Exists(to), Is.True, "File " + to + " should exist"); File.Delete(to); }
private void Item_RenameFile(object sender, EventArgs e) { RenameFile?.Invoke(sender, e); }
private void RenameItem_Click(object sender, RoutedEventArgs e) { RenameFile?.Invoke(this, EventArgs.Empty); }