AlignmentTests.cs 3.4 KB

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