Пример #1
0
        public void CreateCache_StairsTest2()
        {
            var body     = DocumentSample3.GenerateBody();
            var instance = new ParagraphStateCacheFactory
            {
                Body      = body,
                Numbering = DocumentSample3.GenerateNumbering(),
                Styles    = DocumentSample3.GenerateStyles()
            };
            var cache = instance.Create();

            var ps      = body.Elements <Paragraph>().ToArray();
            var results = ps.Select(cache.Get).ToArray();

            CollectionAssert.AreEquivalent(
                new int[] { 1, 1, },
                results[0].Indentations.ToArray()
                );
            CollectionAssert.AreEquivalent(
                new int[] { 1, 1, 1 },
                results[1].Indentations.ToArray()
                );
            CollectionAssert.AreEquivalent(
                new int[] { 1, 2, },
                results[2].Indentations.ToArray()
                );
        }
Пример #2
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());
            }
        }
Пример #3
0
        private void SetupEmptyAbstractNum()
        {
            body = NumberingAbstractEmpty.GenerateBody();
            ps   = body.Elements <Paragraph>().ToArray();
            var instance = new ParagraphStateCacheFactory()
            {
                Numbering = NumberingAbstractEmpty.GenerateNumbering(),
                Body      = body,
                Styles    = NumberingAbstractEmpty.GenerateStyles()
            };

            cache = instance.Create();
        }
Пример #4
0
        private void SetupStartOverride()
        {
            body = NumberingStartOverride.GenerateBody();
            ps   = body.Elements <Paragraph>().ToArray();
            var instance = new ParagraphStateCacheFactory()
            {
                Numbering = NumberingStartOverride.GenerateNumbering(),
                Body      = body,
                Styles    = NumberingStartOverride.GenerateStyles()
            };

            cache = instance.Create();
        }
Пример #5
0
        public void CreateCache_NumberingCappedByAbstactConfigTest()
        {
            var body     = NumberingCappedByAbstractConfig.GenerateBody();
            var ps       = body.Elements <Paragraph>().ToArray();
            var instance = new ParagraphStateCacheFactory()
            {
                Numbering = NumberingCappedByAbstractConfig.GenerateNumbering(),
                Body      = body,
                Styles    = NumberingCappedByAbstractConfig.GenerateStyles()
            };
            var cache = instance.Create();

            var n = cache.Get(ps[2]);

            Assert.AreEqual(1, n.Indentations.Count());
        }
Пример #6
0
        public void CreateCache_FirstValueComposedTest()
        {
            var body     = NumberingSample4.GenerateBody();
            var instance = new ParagraphStateCacheFactory
            {
                Body      = body,
                Numbering = NumberingSample4.GenerateNumbering(),
                Styles    = NumberingSample4.GenerateStyles()
            };
            var cache = instance.Create();

            var ps      = body.Elements <Paragraph>().ToArray();
            var results = ps.Select(cache.Get).ToArray();

            CollectionAssert.AreEquivalent(
                new int[] { 1, 1, },
                results.Single().Indentations.ToArray()
                );
        }
Пример #7
0
        public void CreateCache_StairsTest()
        {
            var body     = DocumentSample2.GenerateBody();
            var instance = new ParagraphStateCacheFactory(null, body);
            var cache    = instance.Create();

            var ps      = body.Elements <Paragraph>().ToArray();
            var results = ps.Select(cache.Get).ToArray();

            var mm = results.Select(x => (x.Indentations.Count(), x.Indentations.Last())).ToArray();

            for (int i = 0; i < results.Length; i++)
            {
                var textSplits      = ps[i].InnerText.Split(' ').Select(int.Parse).ToArray();
                var expectedLevel   = textSplits[0];
                var expectedLastVal = textSplits[1];

                Assert.AreEqual(expectedLevel, results[i].Indentations.Count());
                Assert.AreEqual(expectedLastVal, results[i].Indentations.Last());
            }
        }
Пример #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);
        }