TableWithoutHeadersTests.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using QuestPDF.ConformanceTests.TestEngine;
  2. using QuestPDF.Drawing;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.ConformanceTests.Table;
  7. internal class TableWithoutHeadersTests : ConformanceTestBase
  8. {
  9. protected override Document GetDocumentUnderTest()
  10. {
  11. return Document
  12. .Create(document =>
  13. {
  14. document.Page(page =>
  15. {
  16. page.Margin(60);
  17. page.Content()
  18. .Border(1)
  19. .BorderColor(Colors.Grey.Darken1)
  20. .SemanticTable()
  21. .Table(table =>
  22. {
  23. table.ColumnsDefinition(columns =>
  24. {
  25. columns.RelativeColumn();
  26. columns.RelativeColumn();
  27. columns.RelativeColumn();
  28. });
  29. // Row 1
  30. table.Cell().Element(CellStyle).Text("11");
  31. table.Cell().Element(CellStyle).Text("12");
  32. table.Cell().Element(CellStyle).Text("13");
  33. // Row 2
  34. table.Cell().Element(CellStyle).Text("21");
  35. table.Cell().Element(CellStyle).Text("22");
  36. table.Cell().Element(CellStyle).Text("23");
  37. // Row 3
  38. table.Cell().Element(CellStyle).Text("31");
  39. table.Cell().Element(CellStyle).Text("32");
  40. table.Cell().Element(CellStyle).Text("33");
  41. // Row 4
  42. table.Cell().Element(CellStyle).Text("41");
  43. table.Cell().Element(CellStyle).Text("42");
  44. table.Cell().Element(CellStyle).Text("43");
  45. IContainer CellStyle(IContainer container) =>
  46. container
  47. .Border(1)
  48. .BorderColor(Colors.Grey.Lighten2)
  49. .Padding(8);
  50. });
  51. });
  52. });
  53. }
  54. protected override SemanticTreeNode? GetExpectedSemanticTree()
  55. {
  56. return ExpectedSemanticTree.DocumentRoot(root =>
  57. {
  58. root.Child("Table", table =>
  59. {
  60. table.Child("TBody", tbody =>
  61. {
  62. tbody.Child("TR", row =>
  63. {
  64. row.Child("TD", th => th.Child("P"));
  65. row.Child("TD", td => td.Child("P"));
  66. row.Child("TD", td => td.Child("P"));
  67. });
  68. tbody.Child("TR", row =>
  69. {
  70. row.Child("TD", th => th.Child("P"));
  71. row.Child("TD", td => td.Child("P"));
  72. row.Child("TD", td => td.Child("P"));
  73. });
  74. tbody.Child("TR", row =>
  75. {
  76. row.Child("TD", th => th.Child("P"));
  77. row.Child("TD", td => td.Child("P"));
  78. row.Child("TD", td => td.Child("P"));
  79. });
  80. tbody.Child("TR", row =>
  81. {
  82. row.Child("TD", th => th.Child("P"));
  83. row.Child("TD", td => td.Child("P"));
  84. row.Child("TD", td => td.Child("P"));
  85. });
  86. });
  87. });
  88. });
  89. }
  90. }