PaddingTests.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. namespace QuestPDF.LayoutTests;
  2. [TestFixture]
  3. public class PaddingTests
  4. {
  5. [Test]
  6. public void PaddingModifiesPositioningAndMinimumSize()
  7. {
  8. LayoutTest
  9. .HavingSpaceOfSize(100, 100)
  10. .ForContent(content =>
  11. {
  12. content
  13. .Shrink()
  14. .PaddingLeft(5)
  15. .PaddingTop(10)
  16. .PaddingRight(15)
  17. .PaddingBottom(20)
  18. .Mock("a")
  19. .SolidBlock(20, 30);
  20. })
  21. .ExpectDrawResult(document =>
  22. {
  23. document
  24. .Page()
  25. .RequiredAreaSize(40, 60)
  26. .Content(page =>
  27. {
  28. page.Mock("a").Position(5, 10).Size(20, 30);
  29. });
  30. });
  31. }
  32. [Test]
  33. public void NegativePaddingIsAllowed()
  34. {
  35. LayoutTest
  36. .HavingSpaceOfSize(100, 100)
  37. .ForContent(content =>
  38. {
  39. content
  40. .Shrink()
  41. .Padding(-10)
  42. .Mock("a")
  43. .SolidBlock(50, 70);
  44. })
  45. .ExpectDrawResult(document =>
  46. {
  47. document
  48. .Page()
  49. .RequiredAreaSize(30, 50)
  50. .Content(page =>
  51. {
  52. page.Mock("a").Position(-10, -10).Size(50, 70);
  53. });
  54. });
  55. }
  56. [Test]
  57. public void PaddingSupportsPaging()
  58. {
  59. LayoutTest
  60. .HavingSpaceOfSize(100, 100)
  61. .ForContent(content =>
  62. {
  63. content
  64. .Shrink()
  65. .Padding(15)
  66. .Mock("a")
  67. .ContinuousBlock(50, 90);
  68. })
  69. .ExpectDrawResult(document =>
  70. {
  71. document
  72. .Page()
  73. .RequiredAreaSize(80, 100)
  74. .Content(page =>
  75. {
  76. page.Mock("a").Position(15, 15).Size(50, 70);
  77. });
  78. document
  79. .Page()
  80. .RequiredAreaSize(80, 50)
  81. .Content(page =>
  82. {
  83. page.Mock("a").Position(15, 15).Size(50, 20);
  84. });
  85. });
  86. }
  87. [Test]
  88. public void MultipleItemsWithAppliedPadding()
  89. {
  90. LayoutTest
  91. .HavingSpaceOfSize(100, 150)
  92. .ForContent(content =>
  93. {
  94. content.Shrink().Column(column =>
  95. {
  96. column.Item().PaddingVertical(5).Mock("a").SolidBlock(15, 25);
  97. column.Item().PaddingHorizontal(10).Mock("b").SolidBlock(20, 30);
  98. column.Item().Padding(15).Mock("c").SolidBlock(25, 35);
  99. });
  100. })
  101. .ExpectDrawResult(document =>
  102. {
  103. document
  104. .Page()
  105. .RequiredAreaSize(55, 130)
  106. .Content(page =>
  107. {
  108. page.Mock("a").Position(0, 5).Size(55, 25);
  109. page.Mock("b").Position(10, 35).Size(35, 30);
  110. page.Mock("c").Position(15, 80).Size(25, 35);
  111. });
  112. });
  113. }
  114. [Test]
  115. public void PaddingProducesAvailableSpaceOfNegativeSize()
  116. {
  117. LayoutTest
  118. .HavingSpaceOfSize(100, 150)
  119. .ForContent(content =>
  120. {
  121. content.Shrink().Padding(60).SolidBlock(20, 25);
  122. })
  123. .ExpectLayoutException("The available space is negative.");
  124. }
  125. [Test]
  126. public void PaddingWithEmptyChild()
  127. {
  128. LayoutTest
  129. .HavingSpaceOfSize(100, 150)
  130. .ForContent(content =>
  131. {
  132. content.Shrink().Padding(30);
  133. })
  134. .ExpectDrawResult(document =>
  135. {
  136. document
  137. .Page()
  138. .RequiredAreaSize(60, 60);
  139. });
  140. }
  141. [Test]
  142. public void PaddingOnEmptyElementProducesAvailableSpaceOfNegativeSize()
  143. {
  144. LayoutTest
  145. .HavingSpaceOfSize(100, 150)
  146. .ForContent(content =>
  147. {
  148. content.Shrink().Padding(60);
  149. })
  150. .ExpectLayoutException("The available space is negative.");
  151. }
  152. [Test]
  153. public void PaddingOnEmptyElementProducesAvailableSpaceOfNegativeSize2()
  154. {
  155. LayoutTest
  156. .HavingSpaceOfSize(100, 150)
  157. .ForContent(content =>
  158. {
  159. content.Shrink().Padding(60).Column(column => { });
  160. })
  161. .ExpectDrawResult(document =>
  162. {
  163. document
  164. .Page()
  165. .RequiredAreaSize(0, 0);
  166. });
  167. }
  168. [Test]
  169. public void NegativePaddingProducesMeasurementOfNegativeSize()
  170. {
  171. LayoutTest
  172. .HavingSpaceOfSize(100, 150)
  173. .ForContent(content =>
  174. {
  175. content.Shrink().Padding(-15).Mock("a").SolidBlock(20, 40);
  176. })
  177. .ExpectDrawResult(document =>
  178. {
  179. document
  180. .Page()
  181. .RequiredAreaSize(0, 10)
  182. .Content(page =>
  183. {
  184. page.Mock("a").Position(-15, -15).Size(30, 40);
  185. });
  186. });
  187. }
  188. }