Beispiel #1
0
        public void TestCanConfigureOutputOfCollectionsUsingExtensionMethod()
        {
            var bart = new Person { Name = "Bart Simpson", Age = 10 };
            var lisa = new Person { Name = "Lisa Simpson", Age = 8 };
            var maggie = new Person { Name = "Maggie Simpson", Age = 1 };
            var homer = new Person { Name = "Homer Simpson", Age = 36, Children = new[] { bart, lisa, maggie } };
            var marge = new Person { Name = "Marge Simpson", Age = 35, Children = new[] { bart, lisa, maggie } };
            var milhouse = new Person { Name = "Milhouse Van Houten ", Age = 10 };

            var simpsons = new[] { homer, marge, bart, lisa, maggie, milhouse };

            var md = new MarkdownContainer();
            md.Append("Table built with no options".ToMarkdownHeader());
            md.Append(simpsons.ToMarkdownTable());

            md.Append("Table built with Default options".ToMarkdownHeader());
            md.Append(simpsons.ToMarkdownTable(TableOptions.Default));

            md.Append("Table built with ExcludeCollectionProperties options".ToMarkdownHeader());
            md.Append(simpsons.ToMarkdownTable(TableOptions.ExcludeCollectionProperties));

            Console.WriteLine(md);
        }
        public void TableExample()
        {
            var data = new[]
            {
                new {Year = 1991, Album = "Out of Time", Songs = 11, Rating = "* * * *"},
                new {Year = 1992, Album = "Automatic for the People", Songs = 12, Rating = "* * * * *"},
                new {Year = 1994, Album = "Monster", Songs = 12, Rating = "* * *"}
            };

            Console.Write(data.ToMarkdownTable());

            // Produces:
            //
            //     Year | Album                    | Songs | Rating   
            //     ---- | ------------------------ | ----- | --------- 
            //     1991 | Out of Time              | 11    | * * * *  
            //     1992 | Automatic for the People | 12    | * * * * *
            //     1994 | Monster                  | 12    | * * *   
        }
        public void TestTableCanBeBuiltAutomaticallyFromEnumerable()
        {
            var data = new[]
            {
                new{Name = "Meryl Streep", Nominations = 18, Awards=3},
                new{Name = "Katharine Hepburn", Nominations = 12, Awards=4},
                new{Name = "Jack Nicholson", Nominations = 12, Awards=3},
                new{Name = "Bette Davis", Nominations = 10, Awards=2},
                new{Name = "Laurence Olivier", Nominations = 10, Awards=1},
                new{Name = "Spencer Tracy", Nominations = 9, Awards=2}

            };

            data.ToMarkdownTable().AssertOutputEquals(
                "     Name              | Nominations | Awards\r\n" +
                "     ----------------- | -----------:| ------:\r\n" +
                "     Meryl Streep      |          18 |      3\r\n" +
                "     Katharine Hepburn |          12 |      4\r\n" +
                "     Jack Nicholson    |          12 |      3\r\n" +
                "     Bette Davis       |          10 |      2\r\n" +
                "     Laurence Olivier  |          10 |      1\r\n" +
                "     Spencer Tracy     |           9 |      2\r\n");
        }
        public void TestLineBreaksTabsAndSpecialCharactersAreEncodedInTableCells()
        {
            var books = new[]
            {
                new
                {
                    Type = "Unix style Line Break",
                    Content = "First Line\nSecond Line",
                },
                new
                {
                    Type = "ZX Spectrum style Line Break",
                    Content = "First Line\rSecond Line",
                },
                new
                {
                    Type = "Acorn BBC Spooled output Line Break",
                    Content = "First Line\n\rSecond Line",
                },
                new
                {
                    Type = "Windows style output Line Break",
                    Content = "First Line\r\nSecond Line",
                },
                new
                {
                    Type = "Tab characters",
                    Content = "Column1\tColumn2",
                },
                new
                {
                    Type = "Backslash characters",
                    Content = @"\\myserver\path\to\file.txt",
                }
            };

            books.ToMarkdownTable().WriteToTrace();
        }
Beispiel #5
0
        public void TestTableCanIgnoreCollections()
        {
            var data = new[]
            {
                new{Name = "Meryl Streep", Nominations = 18, Awards=3, activeYears = new List<int>()},
                new{Name = "Katharine Hepburn", Nominations = 12, Awards=4, activeYears = new List<int>()},
                new{Name = "Jack Nicholson", Nominations = 12, Awards=3, activeYears = new List<int>()},
                new{Name = "Bette Davis", Nominations = 10, Awards=2, activeYears = new List<int>()},
                new{Name = "Laurence Olivier", Nominations = 10, Awards=1, activeYears = new List<int>()},
                new{Name = "Spencer Tracy", Nominations = 9, Awards=2, activeYears = new List<int>()}
                
            };

            data.ToMarkdownTable(false).AssertOutputEquals(
                "     Name              | Nominations | Awards\r\n" +
                "     ----------------- | -----------:| ------:\r\n" +
                "     Meryl Streep      |          18 |      3\r\n" +
                "     Katharine Hepburn |          12 |      4\r\n" +
                "     Jack Nicholson    |          12 |      3\r\n" +
                "     Bette Davis       |          10 |      2\r\n" +
                "     Laurence Olivier  |          10 |      1\r\n" +
                "     Spencer Tracy     |           9 |      2\r\n");
        }
        public void TableExample2()
        {
            var data = new[]
            {
                new {Name = "Meryl Streep", Nominations = 18, Awards = 3},
                new {Name = "Katharine Hepburn", Nominations = 12, Awards = 4},
                new {Name = "Jack Nicholson", Nominations = 12, Awards = 3}
            };

            Console.Write(data.ToMarkdownTable());

            var tableWithHeaders = data
                .ToMarkdownTable(i => i.Name, i => i.Nominations + i.Awards)
                .WithHeaders("Name", "Total");

            Console.Write(tableWithHeaders);
        }