public void ValueSetExport_NoMembers() { HyperlinkTracker hyperlinkTracker = new HyperlinkTracker(); TableCollection tables = new TableCollection(this.body, hyperlinkTracker); ValueSetsExport vse = new ValueSetsExport(null, mainPart, hyperlinkTracker, tables, false, 2, null); vse.AddValueSet(this.vs3, DateTime.Now); Assert.AreEqual(0, this.body.ChildElements.Count); }
public void ValueSetExport_Inline() { HyperlinkTracker hyperlinkTracker = new HyperlinkTracker(); TableCollection tables = new TableCollection(this.body, hyperlinkTracker); ValueSetsExport vse = new ValueSetsExport(null, mainPart, hyperlinkTracker, tables, false, 2, null); vse.AddValueSet(this.vs1, DateTime.Now); Assert.AreEqual(3, this.body.ChildElements.Count); Paragraph p1 = this.body.ChildElements[0] as Paragraph; Assert.IsNotNull(p1); Table t1 = this.body.ChildElements[1] as Table; Assert.IsNotNull(t1); Assert.AreEqual(7, t1.ChildElements.Count); AssertWordXpath(t1, "w:tr[last()][count(w:tc[w:tcPr/w:gridSpan/@w:val='4'])=1]", "Expected to find one column with a gridspan of 4 in the last row"); AssertWordXpath(t1, "w:tr[last()]/w:tc/w:p/w:r/w:t[text() = '...']", "Expected to find a text block with ..."); vse.AddValueSet(this.vs2, DateTime.Now); Assert.AreEqual(6, this.body.ChildElements.Count); Table t2 = this.body.ChildElements[4] as Table; Assert.IsNotNull(t2); Assert.AreEqual(6, t2.ChildElements.Count); AssertWordXpath(t2, "w:tr[last()][not(w:tc/w:p/w:r/w:t[text() = '...'])]", "Shouldn't have found an elipsis in the last row."); vse.AddValueSetsAppendix(); Assert.AreEqual(10, this.body.ChildElements.Count); Table t3 = this.body.ChildElements[8] as Table; Assert.IsNotNull(t3); AssertWordXpath(t3, "w:tr[1]/w:trPr/w:tblHeader", "Expected first row to be table header in appendix table."); AssertWordXpath(t3, "w:tr[2]/w:tc[1]//w:t[text() = 'ValueSet 1']", "Expected to find ValueSet 2 in second row"); AssertWordXpath(t3, "w:tr[3]/w:tc[1]//w:t[text() = 'ValueSet 2']", "Expected to find ValueSet 3 in third row"); }
public void ValueSetExport_Appendix() { HyperlinkTracker hyperlinkTracker = new HyperlinkTracker(); TableCollection tables = new TableCollection(this.body, hyperlinkTracker); ValueSetsExport vse = new ValueSetsExport(null, mainPart, hyperlinkTracker, tables, true, 2, null); vse.AddValueSet(this.vs1, DateTime.Now); Assert.AreEqual(0, this.body.ChildElements.Count); vse.AddValueSet(this.vs2, DateTime.Now); Assert.AreEqual(0, this.body.ChildElements.Count); vse.AddValueSetsAppendix(); Assert.AreEqual(7, this.body.ChildElements.Count); Table t1 = this.body.ChildElements[2] as Table; Assert.IsNotNull(t1); Table t2 = this.body.ChildElements[5] as Table; Assert.IsNotNull(t2); }
public void PrimitiveTextFormattingTest1() { var repo = new MockObjectRepository(); TemplateConstraint newConstraint = new TemplateConstraint() { Number = 1234, IsPrimitive = true, PrimitiveText = "This entry SHALL contain X which SHALL NOT contain Y" }; IGSettingsManager igSettings = new IGSettingsManager(repo); HyperlinkTracker hyperlinkTracker = new HyperlinkTracker(); var formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(repo, igSettings, null, newConstraint); using (MemoryStream ms = new MemoryStream()) { var doc = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document); var mainPart = doc.AddMainDocumentPart(); mainPart.Document = new Document(); formattedConstraint.AddToDocParagraph(mainPart, hyperlinkTracker, mainPart.Document, 1, 1, ""); } }
public Paragraph AddToDocParagraph(MainDocumentPart mainPart, HyperlinkTracker hyperlinkTracker, OpenXmlElement parent, int level, int id, string headingStyle) { // Add the heading if (this.IsHeading && !string.IsNullOrEmpty(this.Context)) { string headingTitle = this.Context; if (!string.IsNullOrEmpty(this.Category)) { headingTitle += " for " + this.Category; } Paragraph pHeading = new Paragraph( new ParagraphProperties( new ParagraphStyleId() { Val = headingStyle }), DocHelper.CreateRun(headingTitle)); parent.Append(pHeading); if (!string.IsNullOrEmpty(this.HeadingDescription)) { OpenXmlElement parsedHeadingDescription = this.HeadingDescription.MarkdownToOpenXml(this.tdb, mainPart); if (parsedHeadingDescription != null) { foreach (OpenXmlElement cParsedChild in parsedHeadingDescription.ChildElements) { OpenXmlElement cClonedParsedChild = cParsedChild.CloneNode(true); this.ApplyStyleToElement(cClonedParsedChild); parent.Append(cClonedParsedChild); } } } } // Add the description above the constraint definition if (!string.IsNullOrEmpty(this.Description)) { OpenXmlElement parsedDescription = this.Description.MarkdownToOpenXml(this.tdb, mainPart); if (parsedDescription != null) { foreach (OpenXmlElement cParsedChild in parsedDescription.ChildElements) { OpenXmlElement cClonedParsedChild = cParsedChild.CloneNode(true); this.ApplyStyleToElement(cClonedParsedChild); parent.Append(cClonedParsedChild); } } } // Add the constraint definition Paragraph para = new Paragraph( new ParagraphProperties( new NumberingProperties( new NumberingLevelReference() { Val = level }, new NumberingId() { Val = id }))); foreach (ConstraintPart cPart in this.parts) { switch (cPart.PartType) { case ConstraintPart.PartTypes.Keyword: para.Append( DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.ConformanceVerbStyle)); break; case ConstraintPart.PartTypes.Context: para.Append( DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.ConstraintContextStyle)); break; case ConstraintPart.PartTypes.Template: para.Append( DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.TemplateOidStyle)); break; case ConstraintPart.PartTypes.Vocabulary: para.Append( DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.VocabularyConstraintStyle)); break; case ConstraintPart.PartTypes.Link: hyperlinkTracker.AddHyperlink(para, cPart.Text, cPart.LinkDestination, Properties.Settings.Default.LinkStyle); break; case ConstraintPart.PartTypes.Constraint: var newRun = DocHelper.CreateRun(cPart.Text); if (cPart.IsAnchor) { hyperlinkTracker.AddAnchorAround(para, "C_" + this.Number, newRun); } else { para.Append(newRun); } break; case ConstraintPart.PartTypes.PrimitiveText: var element = cPart.Text.MarkdownToOpenXml(this.tdb, mainPart, styleKeywords: true); OpenXmlHelper.Append(element, para); break; default: para.Append( DocHelper.CreateRun(cPart.Text)); break; } } // Add the label after a line break on the run to the paragraph if (!string.IsNullOrEmpty(this.Label)) { string additionalLabel = string.Format("Note: {0}", this.Label); para.AppendChild( new Run( new Break())); para.AppendChild( DocHelper.CreateRun(additionalLabel)); } parent.Append(para); return(para); }