GridTests.cs 8.4 KB

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