public void ShouldBuildLineBreak()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementParagraph {
                IndentSize = 30
            };
            var result = new TextWriterWrapper();

            var run1 = new PrintElementRun {
                Text = "Before Line Break."
            };
            var run2 = new PrintElementRun {
                Text = "After Line Break."
            };

            element.Inlines.Add(run1);
            element.Inlines.Add(new PrintElementLineBreak());
            element.Inlines.Add(run2);

            //When
            context.Build(element, result.Writer);

            //Then
            Assert.AreEqual(Resources.ResultTestShouldBuildLineBreak, result.GetText());
        }
        public void ShouldBuildParagraphWithSettings()
        {
            // Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementParagraph();
            var result  = new TextWriterWrapper();

            var run = new PrintElementRun();

            run.Text = "Проверка текста. ";
            run.Font = new PrintElementFont
            {
                Family = "Courier New",
                Size   = 30
            };
            run.TextDecoration = PrintElementTextDecoration.Underline;
            run.Foreground     = "Blue";

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

            element.IndentSize = 15;

            // When
            context.Build(element, result.Writer);

            // Then
            Assert.AreEqual(Resources.ResultTestShouldBuildParagraphWithSettings, result.GetText());
        }
Пример #3
0
        private static bool ApplyUppercase(PrintElementRun element)
        {
            if (!string.IsNullOrEmpty(element.Text))
            {
                element.Text = element.Text.ToUpper();
            }

            return(true);
        }
Пример #4
0
        private static bool ApplySentenceCase(PrintElementRun element)
        {
            if (!string.IsNullOrEmpty(element.Text))
            {
                element.Text = char.ToUpper(element.Text[0]) + element.Text.Substring(1);
                return(false);
            }

            return(true);
        }
        public void ShouldAppyText()
        {
            // Given
            dynamic elementMetadata = new DynamicWrapper();

            elementMetadata.Text = "Some Text";

            // When
            PrintElementRun element = BuildTestHelper.BuildRun(elementMetadata);

            // Then
            Assert.IsNotNull(element);
            Assert.AreEqual("Some Text", element.Text);
        }
Пример #6
0
        private static bool ApplyToggleCase(PrintElementRun element)
        {
            if (!string.IsNullOrEmpty(element.Text))
            {
                var text = new StringBuilder(element.Text.Length);

                foreach (var c in element.Text)
                {
                    text.Append(char.IsLower(c) ? char.ToUpper(c) : char.ToLower(c));
                }

                element.Text = text.ToString();
            }

            return(true);
        }
Пример #7
0
        public void ShouldBuildList()
        {
            // Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementList();
            var result  = new TextWriterWrapper();

            var item1 = new PrintElementRun {
                Text = "Item1"
            };
            var item2 = new PrintElementRun {
                Text = "Item2"
            };
            var item3 = new PrintElementRun {
                Text = "Item3"
            };

            var par1 = new PrintElementParagraph();
            var par2 = new PrintElementParagraph();
            var par3 = new PrintElementParagraph();

            par1.Inlines.Add(item1);
            par2.Inlines.Add(item2);
            par3.Inlines.Add(item3);

            var section1 = new PrintElementSection();
            var section2 = new PrintElementSection();
            var section3 = new PrintElementSection();

            section1.Blocks.Add(par1);
            section2.Blocks.Add(par2);
            section3.Blocks.Add(par3);

            element.Items.Add(section1);
            element.Items.Add(section2);
            element.Items.Add(section3);

            element.MarkerStyle = PrintElementListMarkerStyle.LowerLatin;
            element.StartIndex  = 24;

            // When
            context.Build(element, result.Writer);

            // Then
            Assert.AreEqual(Resources.ResultTestShouldBuildList, result.GetText());
        }
        public object Create(PrintElementBuildContext buildContext, dynamic elementMetadata)
        {
            var element = new PrintElementRun();

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

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

            ApplyText(element, buildContext, elementMetadata);

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

            return(element);
        }
        public void ShouldBuildSectioWithProperties()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementSection();
            var result  = new TextWriterWrapper();

            var run = new PrintElementRun();

            run.Text = "Section & Margin & Padding & Border & Background";

            var par = new PrintElementParagraph();

            par.Inlines.Add(run);
            par.TextAlignment = PrintElementTextAlignment.Center;

            var section = new PrintElementSection();

            section.Blocks.Add(par);
            section.Border = new PrintElementBorder
            {
                Color     = "blue",
                Thickness = new PrintElementThickness(5)
            };
            section.Margin     = new PrintElementThickness(20);
            section.Padding    = new PrintElementThickness(20);
            section.Background = "yellow";

            element.Blocks.Add(section);
            element.Border = new PrintElementBorder
            {
                Color     = PrintElementColors.Red,
                Thickness = new PrintElementThickness(5)
            };
            element.Margin     = new PrintElementThickness(20);
            element.Padding    = new PrintElementThickness(20);
            element.Background = PrintElementColors.Green;

            //When
            context.Build(element, result.Writer);

            //Then
            Assert.AreEqual(Resources.ResultTestShouldBuildSectioWithProperties, result.GetText());
        }
Пример #10
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());
        }
        public void ShouldBuildRun()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementRun
            {
                Text = "Здесь много текста",
                Font = new PrintElementFont
                {
                    Family = "Tahoma",
                    Size   = 30
                }
            };
            var result = new TextWriterWrapper();

            //When
            context.Build(element, result.Writer);

            //Then
            Assert.AreEqual(Resources.ResultTestShouldBuildRun, result.GetText());
        }
Пример #12
0
        public void ShouldBuildHyperlink()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementHyperlink();
            var result  = new TextWriterWrapper();

            element.Reference = new Uri("http://google.com");

            var run = new PrintElementRun {
                Text = "Hyperlink Google"
            };

            element.Inlines.Add(run);

            //When
            context.Build(element, result.Writer);

            //Then
            Assert.AreEqual(Resources.ResultTestShouldBuildHyperlink, result.GetText());
        }
        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());
        }
 private static void ApplyText(PrintElementRun element, PrintElementBuildContext buildContext, dynamic elementMetadata)
 {
     element.Text = BuildHelper.FormatValue(buildContext, elementMetadata.Text, elementMetadata.SourceFormat);
 }
        public void ShouldBuildDocumentWithContents()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintViewDocument();
            var result  = new TextWriterWrapper();

            var image0   = new PrintElementImage(_getStream(Resources.ImageRotate0));
            var image90  = new PrintElementImage(_getStream(Resources.ImageRotate90));
            var image180 = new PrintElementImage(_getStream(Resources.ImageRotate180));
            var image270 = new PrintElementImage(_getStream(Resources.ImageRotate270));

            image0.Size = new PrintElementSize {
                Height = 50, Width = 150
            };
            image90.Size = new PrintElementSize {
                Height = 150, Width = 50
            };
            image180.Size = new PrintElementSize {
                Height = 50, Width = 150
            };
            image270.Size = new PrintElementSize {
                Height = 150, Width = 50
            };

            var par1 = new PrintElementParagraph();

            par1.Inlines.Add(image0);
            par1.Inlines.Add(image90);
            par1.Inlines.Add(image180);
            par1.Inlines.Add(image270);

            var runNormal = new PrintElementRun {
                Text = "Normal"
            };
            var runSubscript = new PrintElementRun
            {
                Text = "Subscript",
                Font = new PrintElementFont {
                    Variant = PrintElementFontVariant.Subscript
                }
            };
            var runSuperscript = new PrintElementRun
            {
                Text = "Superscript",
                Font = new PrintElementFont {
                    Variant = PrintElementFontVariant.Superscript
                }
            };

            var par2 = new PrintElementParagraph();

            par2.Inlines.Add(runNormal);
            par2.Inlines.Add(runSubscript);
            par2.Inlines.Add(runSuperscript);

            var run = new PrintElementRun {
                Text = "White Foreground & Black Background"
            };

            var par3 = new PrintElementParagraph();

            par3.Foreground = "white";
            par3.Background = "black";

            par3.Inlines.Add(run);

            element.Blocks.Add(par1);
            element.Blocks.Add(par2);
            element.Blocks.Add(new PrintElementPageBreak());
            element.Blocks.Add(par3);

            element.PagePadding = new PrintElementThickness(100);

            //When
            context.Build(element, result.Writer);

            //Then
            Assert.AreEqual(Resources.ResultTestShouldBuildDocumentWithContents, result.GetText());
        }
Пример #16
0
        public void ShouldBuildTable()
        {
            //Given
            var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext();
            var element = new PrintElementTable();
            var result  = new TextWriterWrapper();

            var text1 = new PrintElementRun {
                Text = "Text11, colspan = 2"
            };
            var cell1 = new PrintElementTableCell
            {
                ColumnSpan = 2,
                Border     = new PrintElementBorder
                {
                    Thickness = new PrintElementThickness(1),
                    Color     = "black"
                }
            };
            var par1 = new PrintElementParagraph();

            par1.Inlines.Add(text1);
            cell1.Block = par1;
            var row1 = new PrintElementTableRow();

            row1.Cells.Add(cell1);

            var text21 = new PrintElementRun {
                Text = "Text21"
            };
            var cell21 = new PrintElementTableCell
            {
                Border = new PrintElementBorder
                {
                    Thickness = new PrintElementThickness(1),
                    Color     = "black"
                }
            };
            var par21 = new PrintElementParagraph();

            par21.Inlines.Add(text21);
            cell21.Block = par21;
            var row2 = new PrintElementTableRow();

            row2.Cells.Add(cell21);

            var text22 = new PrintElementRun {
                Text = "Text22"
            };
            var cell22 = new PrintElementTableCell
            {
                Border = new PrintElementBorder
                {
                    Thickness = new PrintElementThickness(1),
                    Color     = "black"
                }
            };
            var par22 = new PrintElementParagraph();

            par22.Inlines.Add(text22);
            cell22.Block = par22;
            row2.Cells.Add(cell22);

            var column1 = new PrintElementTableColumn {
                Size = 100
            };
            var column2 = new PrintElementTableColumn {
                Size = 200
            };

            element.Columns.Add(column1);
            element.Columns.Add(column2);

            element.Rows.Add(row1);
            element.Rows.Add(row2);

            //When
            context.Build(element, result.Writer);

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