| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- using NUnit.Framework;
- using QuestPDF.Drawing;
- using QuestPDF.Elements;
- using QuestPDF.Infrastructure;
- using QuestPDF.UnitTests.TestEngine;
- namespace QuestPDF.UnitTests
- {
- [TestFixture]
- public class AspectRatioTests
- {
- [Test]
- public void Measure_FitWidth_EnoughSpace_FullRender()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f
- })
- .MeasureElement(new Size(400, 201))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .ExpectChildMeasure(new Size(400, 200), SpacePlan.FullRender(100, 50))
- .CheckMeasureResult(SpacePlan.FullRender(400, 200));
- }
-
- [Test]
- public void Measure_FitWidth_EnoughSpace_PartialRender()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f
- })
- .MeasureElement(new Size(400, 201))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .ExpectChildMeasure(new Size(400, 200), SpacePlan.PartialRender(100, 50))
- .CheckMeasureResult(SpacePlan.PartialRender(400, 200));
- }
-
- [Test]
- public void Measure_FitWidth_EnoughSpace_Wrap()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f
- })
- .MeasureElement(new Size(400, 201))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .ExpectChildMeasure(new Size(400, 200), SpacePlan.Wrap("Mock"))
- .CheckMeasureResult(SpacePlan.Wrap("Forwarded from child"));
- }
-
- [Test]
- public void Measure_FitWidth_EnoughSpace()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitWidth,
- Ratio = 2f
- })
- .MeasureElement(new Size(400, 201))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .ExpectChildMeasure(new Size(400, 200), SpacePlan.FullRender(100, 50))
- .CheckMeasureResult(SpacePlan.FullRender(400, 200));
- }
- [Test]
- public void Measure_FitWidth_NotEnoughSpace()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitWidth,
- Ratio = 2f
- })
- .MeasureElement(new Size(400, 199))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .CheckMeasureResult(SpacePlan.Wrap("To preserve the target aspect ratio, the content requires more vertical space than available."));
- }
-
- [Test]
- public void Measure_FitHeight_EnoughSpace()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitHeight,
- Ratio = 2f
- })
- .MeasureElement(new Size(401, 200))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .ExpectChildMeasure(new Size(400, 200), SpacePlan.FullRender(100, 50))
- .CheckMeasureResult(SpacePlan.FullRender(400, 200));
- }
-
- [Test]
- public void Measure_FitHeight_NotEnoughSpace()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitHeight,
- Ratio = 2f
- })
- .MeasureElement(new Size(399, 200))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .CheckMeasureResult(SpacePlan.Wrap("To preserve the target aspect ratio, the content requires more horizontal space than available."));
- }
-
- [Test]
- public void Measure_FitArea_ToWidth()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f
- })
- .MeasureElement(new Size(400, 300))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .ExpectChildMeasure(new Size(400, 200), SpacePlan.FullRender(100, 50))
- .CheckMeasureResult(SpacePlan.FullRender(400, 200));
- }
-
- [Test]
- public void Measure_FitArea_ToHeight()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f
- })
- .MeasureElement(new Size(500, 200))
- .ExpectChildMeasure(Size.Zero, SpacePlan.PartialRender(Size.Zero))
- .ExpectChildMeasure(new Size(400, 200), SpacePlan.FullRender(100, 50))
- .CheckMeasureResult(SpacePlan.FullRender(400, 200));
- }
-
- [Test]
- public void DrawChild_PerWidth()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f
- })
- .DrawElement(new Size(500, 200))
- .ExpectCanvasTranslate(0, 0)
- .ExpectChildDraw(new Size(400, 200))
- .ExpectCanvasTranslate(0, 0)
- .CheckDrawResult();
- }
-
- [Test]
- public void DrawChild_PerHeight()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f
- })
- .DrawElement(new Size(400, 300))
- .ExpectCanvasTranslate(0, 0)
- .ExpectChildDraw(new Size(400, 200))
- .ExpectCanvasTranslate(0, 0)
- .CheckDrawResult();
- }
-
- [Test]
- public void DrawChild_PerWidth_RightToLeft()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f,
- ContentDirection = ContentDirection.RightToLeft
- })
- .DrawElement(new Size(500, 200))
- .ExpectCanvasTranslate(100, 0)
- .ExpectChildDraw(new Size(400, 200))
- .ExpectCanvasTranslate(-100, 0)
- .CheckDrawResult();
- }
-
- [Test]
- public void DrawChild_PerHeight_RightToLeft()
- {
- TestPlan
- .For(x => new AspectRatio
- {
- Child = x.CreateChild(),
- Option = AspectRatioOption.FitArea,
- Ratio = 2f,
- ContentDirection = ContentDirection.RightToLeft
- })
- .DrawElement(new Size(400, 300))
- .ExpectCanvasTranslate(0, 0)
- .ExpectChildDraw(new Size(400, 200))
- .ExpectCanvasTranslate(0, 0)
- .CheckDrawResult();
- }
- }
- }
|