| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- using FluentAssertions;
- using NUnit.Framework;
- using QuestPDF.Elements;
- using QuestPDF.Fluent;
- using QuestPDF.UnitTests.TestEngine;
- namespace QuestPDF.UnitTests
- {
- [TestFixture]
- public class GridTests
- {
- #region Alignment
-
- [Test]
- public void AlignLeft()
- {
- // arrange
- var structure = new Container();
- var childA = TestPlan.CreateUniqueElement();
- var childB = TestPlan.CreateUniqueElement();
- var childC = TestPlan.CreateUniqueElement();
- var childD = TestPlan.CreateUniqueElement();
- var childE = TestPlan.CreateUniqueElement();
- // act
- structure
- .Grid(grid =>
- {
- grid.AlignLeft();
-
- grid.Item(6).Element(childA);
- grid.Item(4).Element(childB);
- grid.Item(4).Element(childC);
- grid.Item(2).Element(childD);
- grid.Item(8).Element(childE);
- });
-
- // assert
- var expected = new Container();
-
- expected.Column(column =>
- {
- column.Item().Row(row =>
- {
- row.RelativeItem(6).Element(childA);
- row.RelativeItem(4).Element(childB);
- row.RelativeItem(2);
- });
-
- column.Item().Row(row =>
- {
- row.RelativeItem(4).Element(childC);
- row.RelativeItem(2).Element(childD);
- row.RelativeItem(6);
- });
-
- column.Item().Row(row =>
- {
- row.RelativeItem(8).Element(childE);
- row.RelativeItem(4);
- });
- });
-
- TestPlan.CompareOperations(structure, expected);
- }
-
- [Test]
- public void AlignCenter()
- {
- // arrange
- var structure = new Container();
- var childA = TestPlan.CreateUniqueElement();
- var childB = TestPlan.CreateUniqueElement();
- var childC = TestPlan.CreateUniqueElement();
- var childD = TestPlan.CreateUniqueElement();
- var childE = TestPlan.CreateUniqueElement();
- // act
- structure
- .Grid(grid =>
- {
- grid.AlignCenter();
-
- grid.Item(6).Element(childA);
- grid.Item(4).Element(childB);
- grid.Item(4).Element(childC);
- grid.Item(2).Element(childD);
- grid.Item(8).Element(childE);
- });
-
- // assert
- var expected = new Container();
-
- expected.Column(column =>
- {
- column.Item().Row(row =>
- {
- row.RelativeItem(1);
- row.RelativeItem(6).Element(childA);
- row.RelativeItem(4).Element(childB);
- row.RelativeItem(1);
- });
-
- column.Item().Row(row =>
- {
- row.RelativeItem(3);
- row.RelativeItem(4).Element(childC);
- row.RelativeItem(2).Element(childD);
- row.RelativeItem(3);
- });
-
- column.Item().Row(row =>
- {
- row.RelativeItem(2);
- row.RelativeItem(8).Element(childE);
- row.RelativeItem(2);
- });
- });
- TestPlan.CompareOperations(structure, expected);
- }
-
- [Test]
- public void AlignRight()
- {
- // arrange
- var structure = new Container();
- var childA = TestPlan.CreateUniqueElement();
- var childB = TestPlan.CreateUniqueElement();
- var childC = TestPlan.CreateUniqueElement();
- var childD = TestPlan.CreateUniqueElement();
- var childE = TestPlan.CreateUniqueElement();
- // act
- structure
- .Grid(grid =>
- {
- grid.AlignRight();
-
- grid.Item(6).Element(childA);
- grid.Item(4).Element(childB);
- grid.Item(4).Element(childC);
- grid.Item(2).Element(childD);
- grid.Item(8).Element(childE);
- });
-
- // assert
- var expected = new Container();
-
- expected.Column(column =>
- {
- column.Item().Row(row =>
- {
- row.RelativeItem(2);
- row.RelativeItem(6).Element(childA);
- row.RelativeItem(4).Element(childB);
- });
-
- column.Item().Row(row =>
- {
- row.RelativeItem(6);
- row.RelativeItem(4).Element(childC);
- row.RelativeItem(2).Element(childD);
- });
-
- column.Item().Row(row =>
- {
- row.RelativeItem(4);
- row.RelativeItem(8).Element(childE);
- });
- });
-
- TestPlan.CompareOperations(structure, expected);
- }
-
- #endregion
-
- #region Spacing
-
- [Test]
- public void Spacing()
- {
- // arrange
- var structure = new Container();
- var childA = TestPlan.CreateUniqueElement();
- var childB = TestPlan.CreateUniqueElement();
- var childC = TestPlan.CreateUniqueElement();
- var childD = TestPlan.CreateUniqueElement();
- // act
- structure
- .Grid(grid =>
- {
- grid.Columns(16);
- grid.AlignCenter();
-
- grid.VerticalSpacing(20);
- grid.HorizontalSpacing(30);
- grid.Item(5).Element(childA);
- grid.Item(5).Element(childB);
- grid.Item(10).Element(childC);
- grid.Item(12).Element(childD);
- });
-
- // assert
- var expected = new Container();
-
- expected.Column(column =>
- {
- column.Spacing(20);
-
- column.Item().Row(row =>
- {
- row.Spacing(30);
-
- row.RelativeItem(3);
- row.RelativeItem(5).Element(childA);
- row.RelativeItem(5).Element(childB);
- row.RelativeItem(3);
- });
-
- column.Item().Row(row =>
- {
- row.Spacing(30);
-
- row.RelativeItem(3);
- row.RelativeItem(10).Element(childC);
- row.RelativeItem(3);
- });
-
- column.Item().Row(row =>
- {
- row.Spacing(30);
-
- row.RelativeItem(2);
- row.RelativeItem(12).Element(childD);
- row.RelativeItem(2);
- });
- });
-
- TestPlan.CompareOperations(structure, expected);
- }
-
- #endregion
- }
- }
|