Пример #1
0
        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");
        }
Пример #2
0
        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}");
        }
Пример #3
0
        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");
        }
Пример #4
0
        /// <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;
        }