ColumnExamples.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Linq;
  3. using NUnit.Framework;
  4. using QuestPDF.Examples.Engine;
  5. using QuestPDF.Fluent;
  6. using QuestPDF.Helpers;
  7. using QuestPDF.Infrastructure;
  8. namespace QuestPDF.Examples
  9. {
  10. public class ColumnExamples
  11. {
  12. [Test]
  13. public void Column()
  14. {
  15. RenderingTest
  16. .Create()
  17. .PageSize(PageSizes.A4)
  18. .ShowResults()
  19. .ProducePdf()
  20. .Render(container =>
  21. {
  22. container.Column(column =>
  23. {
  24. foreach (var i in Enumerable.Range(0, 10))
  25. column.Item().Element(Block);
  26. static void Block(IContainer container)
  27. {
  28. container
  29. .Width(72)
  30. .Height(3.5f, Unit.Inch)
  31. .Height(1.5f, Unit.Inch)
  32. .Background(Placeholders.BackgroundColor());
  33. }
  34. });
  35. });
  36. }
  37. [Test]
  38. public void ColumnDoesNotPutDoubleSpacingWhenChildIsEmpty()
  39. {
  40. RenderingTest
  41. .Create()
  42. .PageSize(PageSizes.A4)
  43. .ShowResults()
  44. .ProducePdf()
  45. .Render(container =>
  46. {
  47. container.Padding(50).Shrink().Border(1).Background(Colors.Grey.Lighten3).Column(column =>
  48. {
  49. column.Spacing(30);
  50. column.Item();
  51. column.Item();
  52. column.Item();
  53. foreach (var i in Enumerable.Range(0, 5))
  54. {
  55. column.Item().Element(Block);
  56. column.Item().Element(Block);
  57. column.Item().Element(Block);
  58. column.Item();
  59. column.Item().Element(Block);
  60. column.Item().Element(Block);
  61. column.Item().Element(Block);
  62. column.Item().Element(Block);
  63. column.Item();
  64. column.Item();
  65. column.Item().Element(Block);
  66. column.Item().Element(Block);
  67. column.Item();
  68. column.Item();
  69. }
  70. static void Block(IContainer container)
  71. {
  72. container
  73. .Width(100)
  74. .Height(30)
  75. .Background(Placeholders.Color());
  76. }
  77. });
  78. });
  79. }
  80. [Test]
  81. public void Stability_NoItems()
  82. {
  83. RenderingTest
  84. .Create()
  85. .ProducePdf()
  86. .MaxPages(100)
  87. .PageSize(250, 150)
  88. .Render(container =>
  89. {
  90. container
  91. .Padding(25)
  92. .Column(column => { });
  93. });
  94. }
  95. }
  96. }