ListTests.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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;
  7. internal class ListTests : 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. .PaddingVertical(30)
  19. .SemanticSection()
  20. .Column(column =>
  21. {
  22. column.Spacing(15);
  23. column.Item()
  24. .SemanticHeader1()
  25. .Text("Conformance Test: Lists")
  26. .FontSize(36)
  27. .Bold()
  28. .FontColor(Colors.Blue.Darken2);
  29. column.Item()
  30. .SemanticList()
  31. .Column(listColumn =>
  32. {
  33. listColumn.Spacing(10);
  34. listColumn.Item()
  35. .SemanticListItem()
  36. .Row(row =>
  37. {
  38. row.ConstantItem(20).SemanticListLabel().Text("1.");
  39. row.RelativeItem()
  40. .SemanticListItemBody()
  41. .Column(bodyColumn =>
  42. {
  43. bodyColumn.Spacing(8);
  44. bodyColumn.Item().Text(Placeholders.Sentence());
  45. bodyColumn.Item()
  46. .SemanticList()
  47. .Column(nestedColumn =>
  48. {
  49. nestedColumn.Spacing(10);
  50. foreach (var i in Enumerable.Range(1, 4))
  51. {
  52. nestedColumn.Item()
  53. .SemanticListItem()
  54. .Row(nestedRow =>
  55. {
  56. nestedRow.ConstantItem(10)
  57. .SemanticListLabel()
  58. .Text("-");
  59. nestedRow.RelativeItem()
  60. .SemanticListItemBody()
  61. .Text(Placeholders.Sentence());
  62. });
  63. }
  64. });
  65. });
  66. });
  67. foreach (var i in Enumerable.Range(2, 5))
  68. {
  69. listColumn.Item()
  70. .SemanticListItem()
  71. .Row(row =>
  72. {
  73. row.ConstantItem(20)
  74. .SemanticListLabel()
  75. .Text($"{i}.");
  76. row.RelativeItem()
  77. .SemanticListItemBody()
  78. .Text(Placeholders.Sentence());
  79. });
  80. }
  81. });
  82. });
  83. });
  84. });
  85. }
  86. protected override SemanticTreeNode? GetExpectedSemanticTree()
  87. {
  88. return ExpectedSemanticTree.DocumentRoot(root =>
  89. {
  90. root.Child("Sect", sect =>
  91. {
  92. sect.Child("H1", h1 => h1.Alt("Conformance Test: Lists"));
  93. sect.Child("L", list =>
  94. {
  95. list.Child("LI", listItem =>
  96. {
  97. listItem.Child("Lbl");
  98. listItem.Child("LBody", lBody =>
  99. {
  100. lBody.Child("P");
  101. lBody.Child("L", nestedList =>
  102. {
  103. foreach (var i in Enumerable.Range(1, 4))
  104. {
  105. nestedList.Child("LI", nestedItem =>
  106. {
  107. nestedItem.Child("Lbl");
  108. nestedItem.Child("LBody", listBody => listBody.Child("P"));
  109. });
  110. }
  111. });
  112. });
  113. });
  114. foreach (var i in Enumerable.Range(2, 5))
  115. {
  116. list.Child("LI", listItem =>
  117. {
  118. listItem.Child("Lbl");
  119. listItem.Child("LBody", listBody => listBody.Child("P"));
  120. });
  121. }
  122. });
  123. });
  124. });
  125. }
  126. }