MultiColumnTests.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using QuestPDF.Elements;
  2. using QuestPDF.Helpers;
  3. namespace QuestPDF.LayoutTests;
  4. public class MultiColumnTests
  5. {
  6. [Test]
  7. public void DynamicComponent()
  8. {
  9. LayoutTest
  10. .HavingSpaceOfSize(400, 200)
  11. .ForContent(content =>
  12. {
  13. content
  14. .Shrink()
  15. .MultiColumn(column =>
  16. {
  17. column.Content()
  18. .Mock("dynamic")
  19. .Dynamic(new CounterComponent());
  20. });
  21. })
  22. .ExpectDrawResult(document =>
  23. {
  24. document
  25. .Page()
  26. .RequiredAreaSize(400, 50)
  27. .Content(page =>
  28. {
  29. page.Mock("dynamic")
  30. .Position(0, 0)
  31. .Size(200, 50)
  32. .State(new DynamicHost.DynamicState()
  33. {
  34. IsRendered = false,
  35. RenderCount = 1,
  36. ChildState = 2
  37. });
  38. page.Mock("dynamic")
  39. .Position(200, 0)
  40. .Size(200, 50)
  41. .State(new DynamicHost.DynamicState()
  42. {
  43. IsRendered = false,
  44. RenderCount = 2,
  45. ChildState = 3
  46. });
  47. });
  48. document
  49. .Page()
  50. .RequiredAreaSize(400, 50)
  51. .Content(page =>
  52. {
  53. page.Mock("dynamic")
  54. .Position(0, 0)
  55. .Size(200, 50)
  56. .State(new DynamicHost.DynamicState()
  57. {
  58. IsRendered = false,
  59. RenderCount = 3,
  60. ChildState = 4
  61. });
  62. page.Mock("dynamic")
  63. .Position(200, 0)
  64. .Size(200, 50)
  65. .State(new DynamicHost.DynamicState()
  66. {
  67. IsRendered = false,
  68. RenderCount = 4,
  69. ChildState = 5
  70. });
  71. });
  72. document
  73. .Page()
  74. .RequiredAreaSize(400, 50)
  75. .Content(page =>
  76. {
  77. page.Mock("dynamic")
  78. .Position(0, 0)
  79. .Size(200, 50)
  80. .State(new DynamicHost.DynamicState()
  81. {
  82. IsRendered = true,
  83. RenderCount = 5,
  84. ChildState = 6
  85. });
  86. });
  87. });
  88. }
  89. public class CounterComponent : IDynamicComponent<int>
  90. {
  91. public int State { get; set; } = 1;
  92. public DynamicComponentComposeResult Compose(DynamicContext context)
  93. {
  94. var content = context.CreateElement(element =>
  95. {
  96. element
  97. .Width(100)
  98. .Height(50)
  99. .Background(Colors.Grey.Lighten2)
  100. .AlignCenter()
  101. .AlignMiddle()
  102. .Text($"Item {State}")
  103. .SemiBold();
  104. });
  105. State++;
  106. return new DynamicComponentComposeResult
  107. {
  108. Content = content,
  109. HasMoreContent = State <= 5
  110. };
  111. }
  112. }
  113. }