public void SingleItem() { var cmd = new Cmd.DeleteItem(); InitCommand(cmd); _context.CurrentItem = _target; var parent = _target.Parent; var result = cmd.Run(); Assert.That(result.Status, Is.EqualTo(CommandStatus.Success)); Assert.That(result.Message, Contains.Substring("Recycled 1 item")); Assert.That(parent.GetChildren().Count, Is.EqualTo(0)); Assert.That(FindItemInRecycleBin(_target.ID), Is.Not.Null); Assert.That(_context.CurrentItem.ID, Is.EqualTo(parent.ID)); }
public void Tree() { var child1 = _target.Add("child1", _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId]); var child2 = _target.Add("child2", _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId]); var child3 = _target.Add("child3", _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId]); var cmd = new Cmd.DeleteItem(); InitCommand(cmd); var parent = _target.Parent; _context.CurrentItem = _target; var result = cmd.Run(); Assert.That(result.Status, Is.EqualTo(CommandStatus.Success)); Assert.That(result.Message, Contains.Substring("Recycled 4 item")); Assert.That(parent.GetChildren().Count, Is.EqualTo(0)); Assert.That(FindItemInRecycleBin(_target.ID), Is.Not.Null); Assert.That(_context.CurrentItem.ID, Is.EqualTo(parent.ID)); }
public void InvalidItem() { var cmd = new Cmd.DeleteItem(); InitCommand(cmd); _context.CurrentItem = _target; cmd.Path = "blah/blah/blah"; var result = cmd.Run(); Assert.That(result.Status, Is.EqualTo(CommandStatus.Failure)); Assert.That(_context.CurrentItem.ID, Is.EqualTo(_target.ID)); }
public override CommandResult Run() { if (string.IsNullOrEmpty(TargetPath)) return new CommandResult(CommandStatus.Failure, Constants.Messages.MissingRequiredParameter.FormatWith("targetPath")); // Evaulate the target path var evalTargetPath = PathParser.EvaluatePath(Context, TargetPath); Item parent = null; using (var targetSwitcher = new ContextSwitcher(Context, evalTargetPath)) { if (targetSwitcher.Result.Status != CommandStatus.Success) return targetSwitcher.Result; parent = Context.CurrentItem; if (parent == null) return new CommandResult(CommandStatus.Failure, "Failed to find the target path '" + TargetPath + "'"); } int count = 0; Item movedItem = null; using (var sourceSwitcher = new ContextSwitcher(Context, Path)) { if (sourceSwitcher.Result.Status != CommandStatus.Success) return sourceSwitcher.Result; // Now perform the move string sourceName = Context.CurrentItem.Name; if (parent.Database == Context.CurrentItem.Database) Context.CurrentItem.MoveTo(parent); else { string xml = Context.CurrentItem.GetOuterXml(true); parent.Paste(xml, false, PasteMode.Overwrite); // Now the item has been copied, delete the original var deleteCommand = new DeleteItem(); deleteCommand.Initialise(Context, Formatter); deleteCommand.Path = Context.CurrentItem.Paths.FullPath; deleteCommand.Run(); } movedItem = parent.Children[Context.CurrentItem.ID]; if(movedItem == null) movedItem = parent.Children[sourceName]; if (movedItem != null) { var inspector = new ItemInspector(movedItem); count = inspector.CountDescendants(); } } if (movedItem == null) return new CommandResult(CommandStatus.Failure, string.Format("Failed to move item")); if (Context.CurrentItem == null) Context.CurrentItem = movedItem; return new CommandResult(CommandStatus.Success, string.Format("Moved {0} {1}", count, count == 1 ? "item" : "items")); }