GridTests.cs 7.6 KB

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