| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- using NUnit.Framework;
- using QuestPDF.Drawing;
- using QuestPDF.Elements;
- using QuestPDF.Fluent;
- using QuestPDF.Infrastructure;
- using QuestPDF.UnitTests.TestEngine;
- namespace QuestPDF.UnitTests
- {
- [TestFixture]
- public class RowTests
- {
- #region Measure
-
- [Test]
- public void Measure_ReturnsWrap_WhenLeftChildReturnsWrap()
- {
- TestPlan
- .For(x => new BinaryRow
- {
- Left = x.CreateChild("left"),
- Right = x.CreateChild("right")
- })
- .MeasureElement(new Size(400, 300))
- .ExpectChildMeasure("left", new Size(400, 300), SpacePlan.Wrap())
- .CheckMeasureResult(SpacePlan.Wrap());
- }
-
- [Test]
- public void Measure_ReturnsWrap_WhenRightChildReturnsWrap()
- {
- TestPlan
- .For(x => new BinaryRow
- {
- Left = x.CreateChild("left"),
- Right = x.CreateChild("right")
- })
- .MeasureElement(new Size(400, 300))
- .ExpectChildMeasure("left", new Size(400, 300), SpacePlan.FullRender(250, 150))
- .ExpectChildMeasure("right", new Size(150, 300), SpacePlan.Wrap())
- .CheckMeasureResult(SpacePlan.Wrap());
- }
-
- [Test]
- public void Measure_ReturnsPartialRender_WhenLeftChildReturnsPartialRender()
- {
- TestPlan
- .For(x => new BinaryRow
- {
- Left = x.CreateChild("left"),
- Right = x.CreateChild("right")
- })
- .MeasureElement(new Size(400, 300))
- .ExpectChildMeasure("left", new Size(400, 300), SpacePlan.PartialRender(250, 150))
- .ExpectChildMeasure("right", new Size(150, 300), SpacePlan.FullRender(100, 100))
- .CheckMeasureResult(SpacePlan.PartialRender(350, 150));
- }
-
- [Test]
- public void Measure_ReturnsPartialRender_WhenRightChildReturnsPartialRender()
- {
- TestPlan
- .For(x => new BinaryRow
- {
- Left = x.CreateChild("left"),
- Right = x.CreateChild("right")
- })
- .MeasureElement(new Size(400, 300))
- .ExpectChildMeasure("left", new Size(400, 300), SpacePlan.FullRender(250, 150))
- .ExpectChildMeasure("right", new Size(150, 300), SpacePlan.PartialRender(100, 100))
- .CheckMeasureResult(SpacePlan.PartialRender(350, 150));
- }
-
- [Test]
- public void Measure_ReturnsFullRender_WhenBothChildrenReturnFullRender()
- {
- TestPlan
- .For(x => new BinaryRow
- {
- Left = x.CreateChild("left"),
- Right = x.CreateChild("right")
- })
- .MeasureElement(new Size(400, 300))
- .ExpectChildMeasure("left", new Size(400, 300), SpacePlan.FullRender(200, 150))
- .ExpectChildMeasure("right", new Size(200, 300), SpacePlan.FullRender(100, 100))
- .CheckMeasureResult(SpacePlan.FullRender(300, 150));
- }
-
- #endregion
- #region Draw
- [Test]
- public void Draw()
- {
- TestPlan
- .For(x => new BinaryRow
- {
- Left = x.CreateChild("left"),
- Right = x.CreateChild("right")
- })
- .DrawElement(new Size(400, 300))
- .ExpectChildMeasure("left", new Size(400, 300), SpacePlan.FullRender(250, 150))
- .ExpectChildDraw("left", new Size(250, 300))
- .ExpectCanvasTranslate(250, 0)
- .ExpectChildDraw("right", new Size(150, 300))
- .ExpectCanvasTranslate(-250, 0)
- .CheckDrawResult();
- }
- #endregion
-
- #region Structure
-
- [Test]
- public void Structure_RelativeColumnsHandling()
- {
- // arrange
- var childA = TestPlan.CreateUniqueElement();
- var childB = TestPlan.CreateUniqueElement();
- var childC = TestPlan.CreateUniqueElement();
- var childD = TestPlan.CreateUniqueElement();
- var childE = TestPlan.CreateUniqueElement();
- const int spacing = 25;
- var availableSpace = new Size(1100, 400);
-
- // act
- var value = new Container();
- value.Row(row =>
- {
- row.Spacing(spacing);
-
- row.ConstantColumn(150).Element(childA);
- row.ConstantColumn(250).Element(childB);
- row.RelativeColumn(1).Element(childC);
- row.RelativeColumn(2).Element(childD);
- row.RelativeColumn(3).Element(childE);
- });
-
- // assert
- var expected = new Container();
- expected.Row(row =>
- {
- row.Spacing(spacing);
-
- row.ConstantColumn(150).Element(childA);
- row.ConstantColumn(250).Element(childB);
- row.ConstantColumn(100).Element(childC);
- row.ConstantColumn(200).Element(childD);
- row.ConstantColumn(300).Element(childE);
- });
-
- TestPlan.CompareOperations(value, expected, availableSpace);
- }
-
- [Test]
- public void Structure_Tree()
- {
- // arrange
- var childA = TestPlan.CreateUniqueElement();
- var childB = TestPlan.CreateUniqueElement();
- var childC = TestPlan.CreateUniqueElement();
- var childD = TestPlan.CreateUniqueElement();
- var childE = TestPlan.CreateUniqueElement();
- const int spacing = 25;
- var availableSpace = new Size(1200, 400);
-
- // act
- var value = new Container();
- value.Row(row =>
- {
- row.Spacing(spacing);
-
- row.ConstantColumn(150).Element(childA);
- row.ConstantColumn(200).Element(childB);
- row.ConstantColumn(250).Element(childC);
- row.RelativeColumn(2).Element(childD);
- row.RelativeColumn(3).Element(childE);
- });
-
- // assert
- var expected = new BinaryRow
- {
- Left = new BinaryRow
- {
- Left = new BinaryRow
- {
- Left = new Constrained
- {
- MinWidth = 150,
- MaxWidth = 150,
- Child = childA
- },
- Right = new Constrained
- {
- MinWidth = 25,
- MaxWidth = 25
- }
- },
- Right = new BinaryRow
- {
- Left = new Constrained
- {
- MinWidth = 200,
- MaxWidth = 200,
- Child = childB
- },
- Right = new Constrained
- {
- MinWidth = 25,
- MaxWidth = 25
- }
- }
- },
- Right = new BinaryRow
- {
- Left = new BinaryRow
- {
- Left = new Constrained
- {
- MinWidth = 250,
- MaxWidth = 250,
- Child = childC
- },
- Right = new Constrained
- {
- MinWidth = 25,
- MaxWidth = 25
- }
- },
- Right = new BinaryRow
- {
- Left = new Constrained
- {
- MinWidth = 200,
- MaxWidth = 200,
- Child = childD
- },
- Right = new BinaryRow
- {
- Left = new Constrained
- {
- MinWidth = 25,
- MaxWidth = 25
- },
- Right = new Constrained
- {
- MinWidth = 300,
- MaxWidth = 300,
- Child = childE
- }
- }
- }
- }
- };
-
- TestPlan.CompareOperations(value, expected, availableSpace);
- }
-
- #endregion
- }
- }
|