Example #1
0
        public void TestAppendUtf8PlainTextFile_Html()
        {
            var fileName = Path.Combine(FileHelper.GetAppPath(), "Resources\\HelpFile.txt");

            var sr = new StructuredText();

            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddDefinitionListLine("Def1", "Value1");
            sr.AddDefinitionListLine("Definition 2", "Value1234");
            sr.AddDefinitionListLine("Defini 3", "Value234556666");

            sr.AppendUtf8PlainTextFile(fileName);


            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);

            var f = new HtmlTextFormatter
            {
                StructuredText    = sr,
                Template          = "<<<Start>>>{0}<<<Ende>>>",
                AddTableOfContent = true
            };
            var result = f.GetFormattedText();

            Debug.Print(result);
            Assert.IsTrue(!string.IsNullOrEmpty(result));
        }
Example #2
0
        public void TestAppendUtf8PlainTextFile_Text()
        {
            var fileName = Path.Combine(FileHelper.GetAppPath(), "Resources\\HelpFile.txt");

            var sr = new StructuredText();

            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddDefinitionListLine("Def1", "Value1");
            sr.AddDefinitionListLine("Definition 2", "Value1234");
            sr.AddDefinitionListLine("Defini 3", "Value234556666");
            sr.AddDefinitionListLine("Defini 4", null);

            sr.AppendUtf8PlainTextFile(fileName);

            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);

            var f = new PlainTextFormatter
            {
                StructuredText = sr,
            };
            var result = f.GetFormattedText();

            Debug.Print(result);
            Assert.IsTrue(!string.IsNullOrEmpty(result));
        }
Example #3
0
        public void TestCreatePdf()
        {
            var fileName = Path.Combine(TestHelper.TempPath, "TextPdf.pdf");

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            FileAssert.DoesNotExist(fileName);

            var st = new StructuredText();

            st.AddHeader1("Überschrift 1");

            st.AddParagraph(TestHelper.Masstext1);

            var code = FileHelper.GetTextResource("code1.txt");

            st.AddCode(code);

            st.AddParagraph(TestHelper.Masstext1);

            st.AddDefinitionListLine("Left1", "Right1");
            st.AddDefinitionListLine("Left2", "Right2");
            st.AddDefinitionListLine("Left3", "Right3");
            st.AddDefinitionListLine("Left4", "Right4");

            st.AddParagraph(TestHelper.Masstext1);

            st.AddTable("Tabelle", TestHelper.GetDataTable());

            st.AddHeader1("Überschrift 2");

            st.AddDefinitionListLine("Left1", "Right1");
            st.AddDefinitionListLine("Left2", "Right2");
            st.AddDefinitionListLine("Left3", "Right3");
            st.AddDefinitionListLine("Left4", "Right4");

            var f = new PdfTextFormatter
            {
                Title          = "Testreport",
                StructuredText = st,
                DateString     = $"Date created: {DateTime.Now:G}",
                Author         = "Testautor"
            };

            f.GetFormattedText();
            f.SaveAsFile(fileName);

            FileAssert.Exists(fileName);

            TestHelper.OpenFile(fileName);
        }
Example #4
0
        public void TestAppendText()
        {
            const string h1 = "T1 Überschrift 1";
            const string h2 = "Ende T2";

            var masterText = new StructuredText();

            masterText.AddHeader1(h1);
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");
            masterText.AddParagraph(MassText);

            masterText.AddCode(MassText);

            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 1");
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 1");
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);


            var toAppendText = new StructuredText();

            toAppendText.AddHeader1("T2 Überschrift 1");
            toAppendText.AddParagraph(MassText);
            toAppendText.AddHeader1("Überschrift 2");
            toAppendText.AddParagraph(MassText);
            toAppendText.AddParagraph(MassText);
            toAppendText.AddHeader1("Überschrift 2");
            toAppendText.AddParagraph(MassText);
            toAppendText.AddHeader1("Überschrift 1");
            toAppendText.AddParagraph(MassText);
            toAppendText.AddParagraph(MassText);
            toAppendText.AddParagraph(MassText);
            toAppendText.AddHeader1("Überschrift 2");
            toAppendText.AddParagraph(MassText);
            toAppendText.AddParagraph(MassText);
            toAppendText.AddParagraph(MassText);
            toAppendText.AddParagraph(MassText);
            toAppendText.AddHeader1("Überschrift 2");
            toAppendText.AddParagraph(MassText);
            toAppendText.AddHeader1("Überschrift 1");
            toAppendText.AddParagraph(MassText);
            toAppendText.AddParagraph(h2);


            var masterCount   = masterText.TextItems.Count;
            var toAppendCount = toAppendText.TextItems.Count;

            masterText.AppendText(toAppendText);

            Assert.IsTrue(masterText.TextItems.Count == masterCount + toAppendCount);
            Assert.IsTrue(masterText.TextItems[0].Content == h1);
            Assert.IsTrue(masterText.TextItems[masterText.TextItems.Count - 1].Content == h2);
        }
Example #5
0
        public void TestGetFormattedText_WithTemplate()
        {
            var sr = new StructuredText();

            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddDefinitionListLine("Def1", "Value1");
            sr.AddDefinitionListLine("Definition 2", "Value1234");
            sr.AddDefinitionListLine("Defini 3", "Value234556666");
            sr.AddParagraph("");
            sr.AddParagraph(MassText);

            sr.AddListItem("Bahnhof");
            sr.AddListItem("HauptBahnhof");
            sr.AddListItem("SüdBahnhof");
            sr.AddHeader1("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);

            var f = new PlainTextFormatter
            {
                StructuredText = sr,
                Template       = "<<<Start>>>{0}<<<Ende>>>"
            };
            var result = f.GetFormattedText();

            Debug.Print(result);
            Assert.IsTrue(!string.IsNullOrEmpty(result));
        }
Example #6
0
        public void TestGetFormattedText_MoveHeaderlevel1_NoTemplate()
        {
            var sr = new StructuredText();

            sr.AddHeader1("Überschrift 1 '& &&&' ");

            sr.AddParagraph("??pa??Task to take a documentation for all SQL databases on a Microsoft(R) SqlServer with exception of databases Master, Msdb, Model and TempDb.??pe??");

            sr.AddParagraph(MassText);
            sr.AddParagraph("??pa??Test paragraph PaPe 1??pe????pa??Test paragraph PaPe 2??pe??");

            sr.AddParagraph("<para>Task to take a documentation for all SQL databases on a MSSqlServer with exception of databases Master, Msdb, Model and TempDb.</para><para>A database may contain stored procs under the schema dbo and names beginning with spDbDocu_ for adding database specific " +
                            "content to the docmentation.</para><para>For parts of the documentation the user running the job needs certain permissions." +
                            "To give least possible permissions, this user should be part of a user defined server role on the SqlServer with the permissions VIEW ANY DEFINITION and GRANT VIEW SERVER STATE." +
                            "You should avoid making the user a sysadmin for security reasons. User must have access to each database with least possible permissions!</para>");

            sr.AddDefinitionListLine("Test para", "<para>Task to take a documentation for all SQL databases on a MSSqlServer with exception of databases Master, Msdb, Model and TempDb.</para><para>A database may contain stored procs under the schema dbo and names beginning with spDbDocu_ for adding database specific " +
                                     "content to the docmentation.</para><para>For parts of the documentation the user running the job needs certain permissions." +
                                     "To give least possible permissions, this user should be part of a user defined server role on the SqlServer with the permissions VIEW ANY DEFINITION and GRANT VIEW SERVER STATE." +
                                     "You should avoid making the user a sysadmin for security reasons. User must have access to each database with least possible permissions!</para>");
            sr.AddDefinitionListLine("Def1", "Value1");
            sr.AddDefinitionListLine("Definition 2", "Value1234");
            sr.AddDefinitionListLine("Defini 3", "Value234556666");
            sr.AddParagraph("");
            sr.AddParagraph(MassText);

            sr.AddListItem("Bahnhof");
            sr.AddListItem("HauptBahnhof");
            sr.AddListItem("SüdBahnhof");
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);

            var f = new HtmlTextFormatter {
                StructuredText = sr, MoveHeaderLevel = 1
            };
            var result = f.GetFormattedText();


            Debug.Print(result);
            Assert.IsTrue(!string.IsNullOrEmpty(result));
            Assert.IsFalse(result.Contains("<h1"));
            Assert.IsTrue(result.Contains("<h2"));
            Assert.IsTrue(result.Contains("<h3"));
        }
Example #7
0
        public void TestGetFormattedText_NoTemplate()
        {
            var sr = new StructuredText();

            sr.AddHeader1("Überschrift 1 '& &&&' ");
            sr.AddParagraph(MassText, "CssTestFixture");
            sr.AddDefinitionListLine("Def1", "Value1");
            sr.AddDefinitionListLine("Definition 2", "Value1234");
            sr.AddDefinitionListLine("Defini 3", "Value234556666");
            sr.AddParagraph("");

            sr.AddParagraph(FormattedMasstext,
                            "CssTestFixture");

            sr.AddCode(MassText, "CssTestFixture");

            sr.AddParagraph(MassText);

            sr.AddListItem("Bahnhof");
            sr.AddListItem("HauptBahnhof");
            sr.AddListItem("SüdBahnhof");
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);
            sr.AddHeader2("Überschrift 2");
            sr.AddParagraph(MassText);
            sr.AddHeader1("Überschrift 1");
            sr.AddParagraph(MassText);
            sr.AddParagraph(MassText);

            var f = new HtmlTextFormatter {
                StructuredText = sr
            };
            var result = f.GetFormattedText();


            Debug.Print(result);
            Assert.IsTrue(!string.IsNullOrEmpty(result));
            Assert.IsTrue(result.Contains("<h1"));
            Assert.IsTrue(result.Contains("<h2"));
        }
        public void TestDataTable()
        {
            const string h1 = "T1 Überschrift 1";

            var masterText = new StructuredText();

            masterText.AddHeader1(h1);
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 1");
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");


            masterText.AddTable("Tabellentitel", DataHelper.GetData());

            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 2");
            masterText.AddParagraph(MassText);
            masterText.AddHeader1("Überschrift 1");
            masterText.AddParagraph(MassText);
            masterText.AddParagraph(MassText);

            var fileName = @"D:\temp\datatable.json";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            JsonHelper.SaveAsFile(fileName, masterText);

            var sr = JsonHelper.LoadJsonFile <StructuredText>(fileName);

            var sourceItem =
                (TableTextItem)masterText.TextItems.FirstOrDefault(x => x.LogicalType == TextItemType.Table);
            var item = (TableTextItem)sr.TextItems.FirstOrDefault(x => x.LogicalType == TextItemType.Table);

            Assert.IsTrue(File.Exists(fileName));
            Assert.IsTrue(masterText.TextItems.Count == sr.TextItems.Count);
            Assert.IsTrue(item.DataTableXml != null);
            Assert.IsTrue(item.DataTableXml == sourceItem.DataTableXml);
        }