GridTests.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using FluentAssertions;
  2. using NUnit.Framework;
  3. using QuestPDF.Elements;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.UnitTests.TestEngine;
  6. namespace QuestPDF.UnitTests
  7. {
  8. [TestFixture]
  9. public class GridTests
  10. {
  11. #region Alignment
  12. [Test]
  13. public void AlignLeft()
  14. {
  15. // arrange
  16. var structure = new Container();
  17. var childA = TestPlan.CreateUniqueElement();
  18. var childB = TestPlan.CreateUniqueElement();
  19. var childC = TestPlan.CreateUniqueElement();
  20. var childD = TestPlan.CreateUniqueElement();
  21. var childE = TestPlan.CreateUniqueElement();
  22. // act
  23. structure
  24. .Grid(grid =>
  25. {
  26. grid.AlignLeft();
  27. grid.Item(6).Element(childA);
  28. grid.Item(4).Element(childB);
  29. grid.Item(4).Element(childC);
  30. grid.Item(2).Element(childD);
  31. grid.Item(8).Element(childE);
  32. });
  33. // assert
  34. var expected = new Container();
  35. expected.Stack(stack =>
  36. {
  37. stack.Item().Row(row =>
  38. {
  39. row.RelativeColumn(6).Element(childA);
  40. row.RelativeColumn(4).Element(childB);
  41. row.RelativeColumn(2);
  42. });
  43. stack.Item().Row(row =>
  44. {
  45. row.RelativeColumn(4).Element(childC);
  46. row.RelativeColumn(2).Element(childD);
  47. row.RelativeColumn(6);
  48. });
  49. stack.Item().Row(row =>
  50. {
  51. row.RelativeColumn(8).Element(childE);
  52. row.RelativeColumn(4);
  53. });
  54. });
  55. TestPlan.CompareOperations(structure, expected);
  56. }
  57. [Test]
  58. public void AlignCenter()
  59. {
  60. // arrange
  61. var structure = new Container();
  62. var childA = TestPlan.CreateUniqueElement();
  63. var childB = TestPlan.CreateUniqueElement();
  64. var childC = TestPlan.CreateUniqueElement();
  65. var childD = TestPlan.CreateUniqueElement();
  66. var childE = TestPlan.CreateUniqueElement();
  67. // act
  68. structure
  69. .Grid(grid =>
  70. {
  71. grid.AlignCenter();
  72. grid.Item(6).Element(childA);
  73. grid.Item(4).Element(childB);
  74. grid.Item(4).Element(childC);
  75. grid.Item(2).Element(childD);
  76. grid.Item(8).Element(childE);
  77. });
  78. // assert
  79. var expected = new Container();
  80. expected.Stack(stack =>
  81. {
  82. stack.Item().Row(row =>
  83. {
  84. row.RelativeColumn(1);
  85. row.RelativeColumn(6).Element(childA);
  86. row.RelativeColumn(4).Element(childB);
  87. row.RelativeColumn(1);
  88. });
  89. stack.Item().Row(row =>
  90. {
  91. row.RelativeColumn(3);
  92. row.RelativeColumn(4).Element(childC);
  93. row.RelativeColumn(2).Element(childD);
  94. row.RelativeColumn(3);
  95. });
  96. stack.Item().Row(row =>
  97. {
  98. row.RelativeColumn(2);
  99. row.RelativeColumn(8).Element(childE);
  100. row.RelativeColumn(2);
  101. });
  102. });
  103. TestPlan.CompareOperations(structure, expected);
  104. }
  105. [Test]
  106. public void AlignRight()
  107. {
  108. // arrange
  109. var structure = new Container();
  110. var childA = TestPlan.CreateUniqueElement();
  111. var childB = TestPlan.CreateUniqueElement();
  112. var childC = TestPlan.CreateUniqueElement();
  113. var childD = TestPlan.CreateUniqueElement();
  114. var childE = TestPlan.CreateUniqueElement();
  115. // act
  116. structure
  117. .Grid(grid =>
  118. {
  119. grid.AlignRight();
  120. grid.Item(6).Element(childA);
  121. grid.Item(4).Element(childB);
  122. grid.Item(4).Element(childC);
  123. grid.Item(2).Element(childD);
  124. grid.Item(8).Element(childE);
  125. });
  126. // assert
  127. var expected = new Container();
  128. expected.Stack(stack =>
  129. {
  130. stack.Item().Row(row =>
  131. {
  132. row.RelativeColumn(2);
  133. row.RelativeColumn(6).Element(childA);
  134. row.RelativeColumn(4).Element(childB);
  135. });
  136. stack.Item().Row(row =>
  137. {
  138. row.RelativeColumn(6);
  139. row.RelativeColumn(4).Element(childC);
  140. row.RelativeColumn(2).Element(childD);
  141. });
  142. stack.Item().Row(row =>
  143. {
  144. row.RelativeColumn(4);
  145. row.RelativeColumn(8).Element(childE);
  146. });
  147. });
  148. TestPlan.CompareOperations(structure, expected);
  149. }
  150. #endregion
  151. #region Spacing
  152. [Test]
  153. public void Spacing()
  154. {
  155. // arrange
  156. var structure = new Container();
  157. var childA = TestPlan.CreateUniqueElement();
  158. var childB = TestPlan.CreateUniqueElement();
  159. var childC = TestPlan.CreateUniqueElement();
  160. var childD = TestPlan.CreateUniqueElement();
  161. // act
  162. structure
  163. .Grid(grid =>
  164. {
  165. grid.Columns(16);
  166. grid.AlignCenter();
  167. grid.VerticalSpacing(20);
  168. grid.HorizontalSpacing(30);
  169. grid.Item(5).Element(childA);
  170. grid.Item(5).Element(childB);
  171. grid.Item(10).Element(childC);
  172. grid.Item(12).Element(childD);
  173. });
  174. // assert
  175. var expected = new Container();
  176. expected.Stack(stack =>
  177. {
  178. stack.Spacing(20);
  179. stack.Item().Row(row =>
  180. {
  181. row.Spacing(30);
  182. row.RelativeColumn(3);
  183. row.RelativeColumn(5).Element(childA);
  184. row.RelativeColumn(5).Element(childB);
  185. row.RelativeColumn(3);
  186. });
  187. stack.Item().Row(row =>
  188. {
  189. row.Spacing(30);
  190. row.RelativeColumn(3);
  191. row.RelativeColumn(10).Element(childC);
  192. row.RelativeColumn(3);
  193. });
  194. stack.Item().Row(row =>
  195. {
  196. row.Spacing(30);
  197. row.RelativeColumn(2);
  198. row.RelativeColumn(12).Element(childD);
  199. row.RelativeColumn(2);
  200. });
  201. });
  202. TestPlan.CompareOperations(structure, expected);
  203. }
  204. #endregion
  205. }
  206. }