コード例 #1
0
        public object Create(PrintElementBuildContext buildContext, dynamic elementMetadata)
        {
            var element = new PrintElementSpan();

            BuildHelper.ApplyTextProperties(element, buildContext.ElementStyle);
            BuildHelper.ApplyTextProperties(element, elementMetadata);

            BuildHelper.ApplyInlineProperties(element, buildContext.ElementStyle);
            BuildHelper.ApplyInlineProperties(element, elementMetadata);

            // Генерация содержимого элемента

            var inlines = buildContext.ElementBuilder.BuildElements(buildContext, elementMetadata.Inlines);

            if (inlines != null)
            {
                foreach (var inline in inlines)
                {
                    element.Inlines.Add(inline);
                }
            }

            BuildHelper.PostApplyTextProperties(element, buildContext.ElementStyle);
            BuildHelper.PostApplyTextProperties(element, elementMetadata);

            return(element);
        }
コード例 #2
0
        public void ShouldBuildInlines()
        {
            // Given

            dynamic inline1 = new DynamicWrapper();

            inline1.Run      = new DynamicWrapper();
            inline1.Run.Text = "Inline1";

            dynamic inline2 = new DynamicWrapper();

            inline2.Run      = new DynamicWrapper();
            inline2.Run.Text = "Inline2";

            dynamic elementMetadata = new DynamicWrapper();

            elementMetadata.Inlines = new[] { inline1, inline2 };

            // When
            PrintElementSpan element = BuildTestHelper.BuildSpan(elementMetadata);

            // Then
            Assert.IsNotNull(element);
            Assert.IsNotNull(element.Inlines);
            Assert.AreEqual(2, element.Inlines.Count);
            Assert.IsInstanceOf <PrintElementRun>(element.Inlines.First());
            Assert.IsInstanceOf <PrintElementRun>(element.Inlines.Last());
            Assert.AreEqual("Inline1", ((PrintElementRun)element.Inlines.First()).Text);
            Assert.AreEqual("Inline2", ((PrintElementRun)element.Inlines.Last()).Text);
        }
コード例 #3
0
        public void ShouldBuildSpan()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementSpan();
            var result  = new TextWriterWrapper();

            var inline1 = new PrintElementRun {
                Text = "Inline1. "
            };
            var inline2 = new PrintElementRun {
                Text = "Inline2. "
            };

            //When
            element.Inlines.Add(inline1);
            element.Inlines.Add(inline2);

            context.Build(element, result.Writer);

            //Then
            Assert.AreEqual(Resources.ResultTestShouldBuildSpan, result.GetText());
        }