Exemplo n.º 1
0
        public void CreateCache_Test()
        {
            var body     = DocumentSample1.GenerateBody();
            var instance = new ParagraphStateCacheFactory(
                DocumentSample1.GenerateStyles(),
                body
                );

            var cache = instance.Create();

            var ps1 = body.Elements <Paragraph>().Take(3);

            for (int i = 0; i < ps1.Count(); i++)
            {
                var p = ps1.ElementAt(i);
                var r = cache.Get(p);
                Assert.AreEqual(1, r.NumberingInstanceId);
                Assert.AreEqual(i, r.Indentations.Single());
            }

            var ps2 = body.Elements <Paragraph>().Skip(6);

            for (int i = 0; i < ps2.Count(); i++)
            {
                var p = ps2.ElementAt(i);
                var r = cache.Get(p);
                Assert.AreEqual(2, r.NumberingInstanceId);
                Assert.AreEqual(i, r.Indentations.Single());
            }
        }
Exemplo n.º 2
0
        public void FindPNumberingLevel_ILvlPPprTest()
        {
            var instance = new NumberItemFactory
            {
                Styles = DocumentSample1.GenerateStyles()
            };
            var p = DocumentSample1.GenerateParagraph2(1);

            var result = instance.FindAssociatedNumberingLevel(p);

            Assert.AreEqual(1, result);
        }
Exemplo n.º 3
0
        public void FindPNumberingId_StyleIDBaseOnStyleTest()
        {
            var instance = new NumberItemFactory
            {
                Styles = DocumentSample1.GenerateStyles()
            };
            var p = DocumentSample1.GenerateParagraph3();

            var result = instance.FindAssociatedNumberingInstance(p);

            Assert.AreEqual(1, result.Value);
        }
Exemplo n.º 4
0
        public void FindPNumberingLevel_BasedOnStyleTest()
        {
            var instance = new ParagraphStateCacheFactory(
                DocumentSample1.GenerateStyles(),
                null
                );
            var p = DocumentSample1.GenerateParagraph3();

            var result = instance.FindAssociatedNumberingLevel(p);

            Assert.AreEqual(0, result);
        }
Exemplo n.º 5
0
        public void FindPNumbringStyleID_BaseOnStyleTest()
        {
            var instance = new ParagraphStateCacheFactory(
                DocumentSample1.GenerateStyles(),
                null
                );
            var p = DocumentSample1.GenerateParagraph3();

            var result = instance.FindAssociatedNumberingInstance(p);

            Assert.AreEqual(1, result.Value);
        }
Exemplo n.º 6
0
 private void MockDocument()
 {
     _wpDoc = WordprocessingDocument.Create(
         new MemoryStream(),
         DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
     _wpDoc.AddMainDocumentPart();
     _wpDoc.MainDocumentPart.AddNewPart <NumberingDefinitionsPart>();
     _wpDoc.MainDocumentPart.AddNewPart <StyleDefinitionsPart>();
     _wpDoc.MainDocumentPart.Document =
         new Document(
             DocumentSample1.GenerateBody());
     _wpDoc.MainDocumentPart.NumberingDefinitionsPart.Numbering =
         DocumentSample1.GenerateNumbering();
     _wpDoc.MainDocumentPart.StyleDefinitionsPart.Styles =
         DocumentSample1.GenerateStyles();
 }
Exemplo n.º 7
0
        public void FindPNumberingLevel_StyleTest()
        {
            var instance = new NumberItemFactory
            {
                Styles = DocumentSample1.GenerateStyles()
            };
            var p = DocumentSample1.GenerateParagraph2();

            foreach (var lvl in p.Descendants <NumberingLevelReference>())
            {
                lvl.Remove();
            }

            var result = instance.FindAssociatedNumberingLevel(p);

            Assert.AreEqual(0, result);
        }
Exemplo n.º 8
0
        public void CreateCache_Test()
        {
            var body     = DocumentSample1.GenerateBody();
            var instance = new ParagraphStateCacheFactory
            {
                Styles    = DocumentSample1.GenerateStyles(),
                Body      = body,
                Numbering = DocumentSample1.GenerateNumbering()
            };

            var cache = instance.Create();

            var ps1 = body.Elements <Paragraph>().Take(3).ToArray();

            AssertNumbering(cache.Get(ps1[0]), 1, 1);
            AssertNumbering(cache.Get(ps1[1]), 2, 1);
            AssertNumbering(cache.Get(ps1[2]), 1, 2);

            var ps2 = body.Elements <Paragraph>().Skip(6).ToArray();

            AssertNumbering(cache.Get(ps2[0]), 2, 2);
            AssertNumbering(cache.Get(ps2[1]), 2, 3);
            AssertNumbering(cache.Get(ps2[2]), 2, 4);
        }