AlignmentTests.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using NUnit.Framework;
  2. using QuestPDF.Drawing;
  3. using QuestPDF.Elements;
  4. using QuestPDF.Infrastructure;
  5. using QuestPDF.UnitTests.TestEngine;
  6. namespace QuestPDF.UnitTests
  7. {
  8. [TestFixture]
  9. public class AlignmentTests
  10. {
  11. [Test]
  12. public void Measure() => SimpleContainerTests.Measure<Alignment>();
  13. [Test]
  14. public void Draw_HorizontalCenter_VerticalCenter()
  15. {
  16. TestPlan
  17. .For(x => new Alignment
  18. {
  19. Horizontal = HorizontalAlignment.Center,
  20. Vertical = VerticalAlignment.Middle,
  21. Child = x.CreateChild()
  22. })
  23. .DrawElement(new Size(1000, 500))
  24. .ExpectChildMeasure(expectedInput: new Size(1000, 500), returns: SpacePlan.PartialRender(new Size(400, 200)))
  25. .ExpectCanvasTranslate(new Position(300, 150))
  26. .ExpectChildDraw(new Size(400, 200))
  27. .ExpectCanvasTranslate(new Position(-300, -150))
  28. .CheckDrawResult();
  29. }
  30. [Test]
  31. public void Draw_HorizontalLeft_VerticalCenter()
  32. {
  33. TestPlan
  34. .For(x => new Alignment
  35. {
  36. Horizontal = HorizontalAlignment.Left,
  37. Vertical = VerticalAlignment.Middle,
  38. Child = x.CreateChild()
  39. })
  40. .DrawElement(new Size(400, 300))
  41. .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.FullRender(new Size(100, 50)))
  42. .ExpectCanvasTranslate(new Position(0, 125))
  43. .ExpectChildDraw(new Size(100, 50))
  44. .ExpectCanvasTranslate(new Position(0, -125))
  45. .CheckDrawResult();
  46. }
  47. [Test]
  48. public void Draw_HorizontalCenter_VerticalBottom()
  49. {
  50. TestPlan
  51. .For(x => new Alignment
  52. {
  53. Horizontal = HorizontalAlignment.Center,
  54. Vertical = VerticalAlignment.Bottom,
  55. Child = x.CreateChild()
  56. })
  57. .DrawElement(new Size(400, 300))
  58. .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.FullRender(new Size(100, 50)))
  59. .ExpectCanvasTranslate(new Position(150, 250))
  60. .ExpectChildDraw(new Size(100, 50))
  61. .ExpectCanvasTranslate(new Position(-150, -250))
  62. .CheckDrawResult();
  63. }
  64. [Test]
  65. public void Draw_HorizontalRight_VerticalTop()
  66. {
  67. TestPlan
  68. .For(x => new Alignment
  69. {
  70. Horizontal = HorizontalAlignment.Right,
  71. Vertical = VerticalAlignment.Top,
  72. Child = x.CreateChild()
  73. })
  74. .DrawElement(new Size(400, 300))
  75. .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.FullRender(new Size(100, 50)))
  76. .ExpectCanvasTranslate(new Position(300, 0))
  77. .ExpectChildDraw(new Size(100, 50))
  78. .ExpectCanvasTranslate(new Position(-300, 0))
  79. .CheckDrawResult();
  80. }
  81. }
  82. }