public void TestIsValid_ReturnsFalseForNonValidDocument() { OxmlDocument target = new OxmlDocument(this.nonValidOXML); bool expected = false; bool actual = target.IsValid(); Assert.AreEqual(expected, actual); }
public void TestIsValid_ReturnsTrueForValidDocument() { OxmlDocument target = new OxmlDocument(this.oxml); bool expected = true; bool actual = target.IsValid(); Assert.AreEqual(expected , actual); }
public void TestGetNextOxmlBlock_ReturnsNullAfterLastBlock() { OxmlDocument target = new OxmlDocument(this.oxml); OxmlBlock actual; // Two paragraphs actual = target.GetNextOxmlBlock(); actual = target.GetNextOxmlBlock(); // No more paragraphs actual = target.GetNextOxmlBlock(); Assert.AreEqual(null, actual); }
public void TestGetNumberOfBlocks_ReturnsNumberOfBlocks() { OxmlDocument target = new OxmlDocument(this.oxml); int expected = 2; var actual = target.GetNumberOfBlocks(); Assert.AreEqual(expected, actual); }
public void TestGetNextOxmlBlock_ReturnsBlockWithNextBlockText() { OxmlDocument target = new OxmlDocument(this.oxml); OxmlBlock actual; // First paragraph actual = target.GetNextOxmlBlock(); Assert.AreEqual(this.paragraphText_1, actual.Text); // Second paragraph actual = target.GetNextOxmlBlock(); Assert.AreEqual(this.paragraphText_2, actual.Text); }
public void TestGetNextOxmlBlock_ReturnsBlockWithUniqueId() { OxmlDocument target = new OxmlDocument(this.oxml); // First paragraph var block1 = target.GetNextOxmlBlock(); // Second paragraph var block2 = target.GetNextOxmlBlock(); Assert.AreNotEqual(block1.Id, block2.Id); }
public void TestDocumentIsValidAfterCallingBookmarkRange() { OxmlDocument target = new OxmlDocument(this.oxmlWithBookmarks); target.BookmarkRange(new OxmlRange(0,1,2), "testbookmark"); bool expected = true; bool actual = target.IsValid(); Assert.AreEqual(expected, actual); }
/// <summary> /// Remove highlights from oxml /// </summary> private void PurgeShadingAndBookmarks() { this._highlightedConflictRoot = null; this._highlightedConflictIndex = -1; OxmlDocument doc = new OxmlDocument(this.GetOXML()); doc.PurgeShading(); doc.PurgeBookmarks(); // Update OXML only if it is valid string oxml = doc.ToOxml(); if (oxml != null) { this.SetOXML(doc.ToOxml()); } else { MessageBox.Show("Unable to remove highlights.", "Eagle Add-In"); } }
public void TestBookmarkRange_HandlesNestedRuns() { OxmlDocument doc = new OxmlDocument(this.oxml); doc._paragraphs[0] = new Paragraph(); Run run1 = new Run(); Run run2 = new Run(); Hyperlink hyp = new Hyperlink(); hyp.AppendChild<Run>(run2); doc._paragraphs[0].AppendChild<Run>(run1); doc._paragraphs[0].AppendChild<Hyperlink>(hyp); run1.AppendChild<Text>(new Text("This is a ")); run2.AppendChild<Text>(new Text("test string.")); doc.BookmarkRange(new OxmlRange_Accessor(0, 4, 15), "testbookmark"); Assert.AreEqual(4, doc._paragraphs[0].Descendants<Run>().ToArray().Length); Assert.AreEqual(1, doc._paragraphs[0].Descendants<BookmarkStart>().ToArray().Length); Assert.AreEqual(1, doc._paragraphs[0].Descendants<BookmarkEnd>().ToArray().Length); }
public void TestCountBookmarks_ReturnsNumberOfBookmarks() { OxmlDocument target = new OxmlDocument(this.oxmlWithBookmarks); int expected = this.numberOfBookmarks; int actual = target.CountBookmarks(); Assert.AreEqual(expected, actual); }
public void TestBookmarkRange_AddsBookmarkToDocument() { OxmlDocument target = new OxmlDocument(this.oxmlWithBookmarks); target.BookmarkRange(new OxmlRange(0, 1, 2), "testbookmark"); int expected = this.numberOfBookmarks + 1; int actual = target.CountBookmarks(); Assert.AreEqual(expected, actual); }
public void TestBookmarkRange_AddsBookmarkStartBeforeRangeStart_StartIsFirstIndex() { OxmlDocument doc = new OxmlDocument(this.oxml); doc._paragraphs[0] = new Paragraph(); Run run1 = new Run(); Run run2 = new Run(); doc._paragraphs[0].AppendChild<Run>(run1); doc._paragraphs[0].AppendChild<Run>(run2); run1.AppendChild<Text>(new Text("This is a ")); run2.AppendChild<Text>(new Text("test string.")); doc.BookmarkRange(new OxmlRange_Accessor(0, 10, 15), "testbookmark"); string expected = "This is a "; string actual = doc._paragraphs[0].GetFirstChild<BookmarkStart>() .PreviousSibling<Run>().InnerText; Assert.AreEqual(expected, actual); }
public void TestBookmarkRange_AddsBookmarkEndAfterRangeEnd_StartEndInSameRun() { OxmlDocument doc = new OxmlDocument(this.oxml); doc._paragraphs[0] = new Paragraph(); Run run1 = new Run(); doc._paragraphs[0].AppendChild<Run>(run1); run1.AppendChild<Text>(new Text("This is a test string.")); doc.BookmarkRange(new OxmlRange_Accessor(0, 4, 15), "testbookmark"); string expected = "string."; string actual = doc._paragraphs[0].GetFirstChild<BookmarkEnd>() .NextSibling<Run>().InnerText; Assert.AreEqual(expected, actual); }
public void TestToOxml_ReturnsNullIfNotValid() { OxmlDocument target = new OxmlDocument(this.nonValidOXML); Assert.IsNull(target.ToOxml()); }
public void TestGetMaxBookmarkID_ReturnsLargestBookmarkID() { OxmlDocument target = new OxmlDocument(this.oxmlWithBookmarks); int actual = target.GetMaxBookmarkID(); Assert.AreEqual(this.maxBookmarkID, actual); }
public void TesBookmarkRange_DoesNotModifyInnerText() { OxmlDocument target = new OxmlDocument(this.oxml); target.BookmarkRange(new OxmlRange(0, 5, 7), "1"); target.BookmarkRange(new OxmlRange(0, 9, 11), "2"); target.BookmarkRange(new OxmlRange(0, 12, 15), "3"); string expected = this.paragraphText_1; string actual = target.GetNextOxmlBlock().Text; Assert.AreEqual(expected, actual); }
/*-----------------------------------------------------------------------------------------*/ /* Background worker */ /*-----------------------------------------------------------------------------------------*/ private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; OxmlDocument doc = new OxmlDocument(this.GetOXML()); Scope scope = new Scope(Properties.Settings.Default.ScopeSize); scope.MinimumTokenLength = Properties.Settings.Default.MinimumTokenLength; doc.PurgeShading(); doc.PurgeBookmarks(); // Load ignore list if (!String.IsNullOrEmpty(_ignoreListName)) { IgnoreList IgnoreList = new IgnoreList(GetListPath(_ignoreListName)); scope.IgnoreWords(IgnoreList.LoadWords(_language)); } // Analyse document int blockCount = 0; float numberOfBlocks = (float)doc.GetNumberOfBlocks(); var block = doc.GetNextOxmlBlock(); while (block != null) { var tokens = block.GenerateOxmlTokens(); foreach (var token in tokens) { scope.FeedToken(token); } block = doc.GetNextOxmlBlock(); if (worker.CancellationPending == true) { e.Cancel = true; break; } int progress = (int)(++blockCount / numberOfBlocks * 100); worker.ReportProgress(progress); } // Add bookmarks to document var conflicts = scope.GetConflicts(); foreach (var root in conflicts.Keys) { foreach (var conflict in conflicts[root]) { foreach (var token in conflict) { Debug.WriteLine(String.Format("Adding bookmark {0} for root '{1}' with text '{2}' and range {3}", token.BookmarkName, token.Root, token.Text, token.Range.ToString())); doc.BookmarkRange(token.Range, token.BookmarkName); } } } // Update OXML only if it is valid string oxml = doc.ToOxml(); if (oxml != null) { this._conflicts = conflicts; this.SetOXML(doc.ToOxml()); } else { MessageBox.Show("An error occured while processing this document.", "Eagle Add-In"); } }