public void GivenValidXml_ThenNumberOfChildNodesMatch(string path) { var xml = File.ReadAllText(path); NppXmlNode nppXmlNode = null; NppXmlNode.TryParse(xml, new LoggerStub(), out nppXmlNode); nppXmlNode.Should().BeNull(because: "the XML is invalid"); }
public void GivenValidXml_ThenTryParseIsValid(string path) { var xml = File.ReadAllText(path); NppXmlNode nppXmlNode; var result = NppXmlNode.TryParse(xml, new LoggerStub(), out nppXmlNode); result.Should().BeFalse(because: "the XML is invalid"); }
public void GivenValidXml_ThenNumberOfChildNodesMatch(string path, int nodeCount) { var xml = File.ReadAllText(path); NppXmlNode nppXmlNode; NppXmlNode.TryParse(xml, new LoggerStub(), out nppXmlNode); nppXmlNode.ChildNodes.Count.Should().Be(nodeCount, because: $"the number of child nodes is {nodeCount}"); }
/// <summary> /// Method to generate a treenode from a npp tree node. /// </summary> /// <param name="node">The npp tree node.</param> /// <returns>The tree node.</returns> private static TreeNode GenerateTreeNode(NppXmlNode node) { return(new TreeNode { ToolTipText = $"{node.Name}", Tag = new TextBoundary(node.StartPosition, node.EndPosition, node.Id), Text = node.Name, // The name is the key. Name = node.Id.ToString() }); }
/// <summary> /// Method to add a npp xml node to a tree node. /// </summary> /// <param name="inXmlNode">The npp xml node.</param> /// <param name="inTreeNode">The tree node.</param> private void AddNode(NppXmlNode inXmlNode, TreeNode inTreeNode) { if (!inXmlNode.HasChildNodes) { return; } for (var i = 0; i < inXmlNode.ChildNodes.Count; i++) { var xNode = inXmlNode.ChildNodes.ElementAt(i); if (this.treeView.InvokeRequired) { this.treeView.Invoke(new AddNodeToNodeDelegate(AddNodeToNode), GenerateTreeNode(xNode), inTreeNode); } else { AddNodeToNode(GenerateTreeNode(xNode), inTreeNode); } AddNode(xNode, inTreeNode.Nodes[i]); } }
/// <summary> /// Background worker method to do the user interface updated. /// </summary> /// <param name="sender">The background worker object.</param> /// <param name="e">The event arguments.</param> private void BackgroundWorker_UpdateUserInterfaceDoWork(object sender, DoWorkEventArgs e) { this._rootNode = null; if (this.ButtonToggle.InvokeRequired) { this.ButtonToggle.Invoke(new EnableToggleButtonDelegate(EnableToggleButton), false); } else { EnableToggleButton(false); } if (this.treeView.InvokeRequired) { this.treeView.Invoke(new SetTreeviewVisibilityDelegate(SetTreeviewVisibility), false); } else { SetTreeviewVisibility(false); } if (this.LabelStatus.InvokeRequired) { this.LabelStatus.Invoke(new SetStatusLabelTextDelegate(SetStatusLabelText), "Parsing the document"); } else { SetStatusLabelText("Parsing the document"); } string attributeName = attributeNameTextBox.Enabled ? attributeNameTextBox.Text : null; // Do validations. if (!NppXmlNode.TryParse(GetDocumentText(PluginBase.GetCurrentScintilla()), attributeName, _logger, out this._rootNode)) { if (this.LabelStatus.InvokeRequired) { this.LabelStatus.Invoke(new SetStatusLabelTextDelegate(SetStatusLabelText), "Document is not valid."); } else { SetStatusLabelText("Document is not valid."); } this._workerIsRunning = false; return; } if (this.treeView.InvokeRequired) { this.treeView.Invoke(new ClearNodesDelegate(ClearNodes)); } else { ClearNodes(); } if (this.treeView.InvokeRequired) { this.treeView.Invoke(new AddNodeToTreeViewDelegate(AddNodeToTreeView), GenerateTreeNode(this._rootNode)); } else { this.treeView.Nodes.Add(GenerateTreeNode(this._rootNode)); } // Add the rest of the nodes. var treeNode = this.treeView.Nodes[0]; AddNode(this._rootNode, treeNode); // Finish up the operation. if (this.treeView.InvokeRequired) { this.treeView.Invoke(new ExpandTreeViewDelegate(ExpandTreeView)); } else { ExpandTreeView(); } if (this.LabelStatus.InvokeRequired) { this.LabelStatus.Invoke(new SetStatusLabelTextDelegate(SetStatusLabelText), string.Empty); } else { SetStatusLabelText(string.Empty); } if (this.ButtonToggle.InvokeRequired) { this.ButtonToggle.Invoke(new EnableToggleButtonDelegate(EnableToggleButton), true); } else { EnableToggleButton(true); } this._workerIsRunning = false; }