/// <summary> /// Ensure that the given paragraph contains only a heading, with /// the specified heading indices and text. This does not verify /// the heading text's style (bold/font size/heading level/etc). /// </summary> /// <param name="paragraph">The paragraph. An appropriate error will be given if this is null.</param> /// <param name="expectedIndices">The expected heading indices. E.g. "1.3.2 "</param> /// <param name="expectedHeadingText">The actual heading text not including the indices.</param> private void ValidateHeading(Paragraph paragraph, string expectedIndices, string expectedHeadingText) { Assert.NotNull(paragraph, "Heading was not written to a paragraph object"); Assert.AreEqual(3, paragraph.Elements.Count); FormattedText indices = paragraph.Elements[0] as FormattedText; FormattedText heading = paragraph.Elements[1] as FormattedText; BookmarkField bookmark = paragraph.Elements[2] as BookmarkField; Assert.NotNull(indices, "Heading indices were not written to document"); Assert.NotNull(heading, "Heading text was not written to document"); Assert.NotNull(bookmark, "Heading text was not written as a bookmark"); Assert.AreEqual(1, indices.Elements.Count, "Heading indices should be a single text element"); Assert.AreEqual(1, heading.Elements.Count, "Heading text should be a single text element"); Text indicesText = indices.Elements.LastObject as Text; Text headingText = heading.Elements.LastObject as Text; Assert.NotNull(indices, "Heading indices were not written"); Assert.NotNull(heading, "Heading text was not written"); Assert.AreEqual(expectedIndices, indicesText.Content, "Heading index is incorrect"); Assert.AreEqual(expectedHeadingText, headingText.Content, "Heading text is incorrect"); Assert.AreEqual($"#{expectedHeadingText}", bookmark.Name); }
public void CheckFormatting() { renderer.Write(pdfBuilder, block); Paragraph paragraph = (Paragraph)document.LastSection.Elements[0]; FormattedText text = (FormattedText)paragraph.Elements[0]; // todo: need to check if this is really the best way. Assert.AreEqual("courier", document.Styles[text.Style].Font.Name); }
public void EnsureHeadingStyleNotAppliedToSubsequentInsertions() { renderer.Write(pdfBuilder, CreateHeading("sample heading")); pdfBuilder.AppendText("a new paragraph", TextStyle.Normal); Paragraph headingParagraph = (Paragraph)document.LastSection.Elements[0]; FormattedText headingText = (FormattedText)headingParagraph.Elements[0]; double headingTextSize = document.Styles[headingText.Style].Font.Size.Point; Paragraph plainParagraph = (Paragraph)document.LastSection.Elements[1]; FormattedText plainText = (FormattedText)plainParagraph.Elements[0]; double plainTextSize = document.Styles[plainText.Style].Font.Size.Point; Assert.Greater(headingTextSize, plainTextSize); }
public void CheckFormattingOfSubsequentContent() { // Write a code block, and then some plain text. renderer.Write(pdfBuilder, block); pdfBuilder.AppendText("a new paragraph after the code block", TextStyle.Normal); // Ensure that the contents of the two paragraphs have different fonts. Paragraph codeParagraph = (Paragraph)document.LastSection.Elements[0]; FormattedText codeText = (FormattedText)codeParagraph.Elements[0]; Paragraph plainParagraph = (Paragraph)document.LastSection.Elements[1]; FormattedText plainText = (FormattedText)plainParagraph.Elements[0]; string codeFont = document.Styles[codeText.Style].Font.Name; string plainFont = document.Styles[plainText.Style].Font.Name; Assert.AreNotEqual(codeFont, plainFont); }
public void EnsureHeadingLevelIsRespected() { renderer.Write(pdfBuilder, CreateHeading("heading level 1", 1)); renderer.Write(pdfBuilder, CreateHeading("heading level 2", 2)); Assert.AreEqual(2, document.LastSection.Elements.Count); Paragraph paragraph0 = (Paragraph)document.LastSection.Elements[0]; Paragraph paragraph1 = (Paragraph)document.LastSection.Elements[1]; FormattedText text0 = (FormattedText)paragraph0.Elements[0]; FormattedText text1 = (FormattedText)paragraph1.Elements[0]; double fontSize0 = document.Styles[text0.Style].Font.Size.Point; double fontSize1 = document.Styles[text1.Style].Font.Size.Point; // heading0 is heading level 1, so should haved larger font size than // heading1, which is a level 2 heading. Assert.Greater(fontSize0, fontSize1); }