public void ImplicitCast_ValidIndexer_SameReference()
        {
            SafeExecuteTest(
                StandardDocPath,
                (doc) =>
                {
                    var expected = doc.MainDocumentPart.Document.Body.Elements<Paragraph>().FirstOrDefault();
                    var indexer = new ParagraphIndexer(expected);
                    var target = (Paragraph)indexer;

                    Assert.AreSame(expected, target);
                });
        }
        public void Constructor_FamousOneLiner_ValidElements()
        {
            SafeExecuteTest(
                FamousOneLinerDocPath,
                (doc) =>
                {
                    var expected = doc.MainDocumentPart.Document.Body.Elements<Paragraph>().FirstOrDefault();
                    var target = new ParagraphIndexer(expected);

                    Assert.IsNotNull(target.Paragraph);
                    Assert.AreSame(expected, target.Paragraph);
                    Assert.AreEqual("The quick fox jumped over the lazy dog.", target.Text);
                    Assert.IsTrue(target.Runs.Count() > 0);
                });
        }
        public void Constructor_StandardDoc_ValidElements()
        {
            SafeExecuteTest(
                StandardDocPath,
                (doc) =>
                {
                    var expected = doc.MainDocumentPart.Document.Body.Elements<Paragraph>().FirstOrDefault();
                    var target = new ParagraphIndexer(expected);

                    // Check to see if references match up and are valid.
                    Assert.IsNotNull(target.Paragraph);
                    Assert.AreSame(expected, target.Paragraph);
                    Assert.IsNotNull(target.Properties);
                    Assert.AreSame(expected.Elements<ParagraphProperties>().FirstOrDefault(), target.Properties);
                });
        }
Exemple #4
0
        public BodyIndexer(Body toIndex)
        {
            if (toIndex == null)
            {
                throw new ArgumentNullException("toIndex");
            }

            this.Body = toIndex;
            this.paragraphs = new List<ParagraphIndexer>();
            this.tables = new List<TableIndexer>();

            // This is uglier than Linq, but way more efficient. For large documents, we only
            // wish to go throught the entire list fo elements ONCE, not multiple times.
            foreach (var element in toIndex.Elements())
            {
                if (element != null)
                {
                    if (element is Paragraph)
                    {
                        var indexer = new ParagraphIndexer(element as Paragraph);
                        this.paragraphs.Add(indexer);
                    }
                    else if (element is Table)
                    {
                        var indexer = new TableIndexer(element as Table);
                        this.tables.Add(indexer);
                    }
                    else if (element is SectionProperties)
                    {
                        this.FinalSectionProperties = element as SectionProperties;
                    }
                }
            }

            // This element should always exist.
            this.FinalSectionProperties = toIndex.Elements<SectionProperties>().FirstOrDefault();
        }
 public void Constructor_NullArgument_ThrowsException()
 {
     var target = new ParagraphIndexer(null);
 }