Пример #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());
            }
        }
Пример #2
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();
 }
Пример #3
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);
        }