예제 #1
0
        public object Create(PrintElementBuildContext buildContext, dynamic elementMetadata)
        {
            var element = new PrintElementItalic();

            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);
        }
        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
            PrintElementItalic element = BuildTestHelper.BuildItalic(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 ShouldBuildItalic()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementItalic();
            var result  = new TextWriterWrapper();

            var run = new PrintElementRun {
                Text = "Italic Text."
            };

            //When
            element.Inlines.Add(run);

            context.Build(element, result.Writer);

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