Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a new Bookmark.
        /// </summary>
        public BookmarkField AddBookmark(string name)
        {
            BookmarkField fieldBookmark = new BookmarkField();

            fieldBookmark.Name = name;
            Add(fieldBookmark);
            return(fieldBookmark);
        }
Ejemplo n.º 3
0
        public void EnsureBookmarkIsWritten()
        {
            string name = "citation_name";

            AddCitation(name, "full citation text");
            builder.AppendReference(name, TextStyle.Normal);
            builder.WriteBibliography();
            Paragraph paragraph = (Paragraph)doc.LastSection.Elements[2];

            Assert.AreEqual(typeof(BookmarkField), paragraph.Elements[1].GetType());
            BookmarkField bookmark = (BookmarkField)paragraph.Elements[1];

            Assert.AreEqual(name, bookmark.Name);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a new Bookmark.
        /// </summary>
        /// <param name="name">The name of the bookmark.</param>
        /// <param name="prepend">True, if the bookmark shall be inserted at the beginning of the paragraph.</param>
        public BookmarkField AddBookmark(string name, bool prepend = true)
        {
            BookmarkField fieldBookmark = new BookmarkField();

            fieldBookmark.Name = name;
            if (prepend)
            {
                InsertObject(0, fieldBookmark);
            }
            else
            {
                Add(fieldBookmark);
            }
            return(fieldBookmark);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds a new Bookmark
 /// </summary>
 public void Add(BookmarkField bookmark)
 {
     this.Elements.Add(bookmark);
 }