BoxTests.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 BoxTests
  10. {
  11. [Test]
  12. public void Measure() => SimpleContainerTests.Measure<MinimalBox>();
  13. [Test]
  14. public void Draw_Wrap()
  15. {
  16. TestPlan
  17. .For(x => new MinimalBox
  18. {
  19. Child = x.CreateChild()
  20. })
  21. .DrawElement(new Size(400, 300))
  22. .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.Wrap())
  23. .CheckDrawResult();
  24. }
  25. [Test]
  26. public void Measure_PartialRender()
  27. {
  28. TestPlan
  29. .For(x => new MinimalBox
  30. {
  31. Child = x.CreateChild()
  32. })
  33. .MeasureElement(new Size(400, 300))
  34. .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.PartialRender(200, 100))
  35. .ExpectCanvasTranslate(0, 0)
  36. .ExpectChildDraw(new Size(200, 100))
  37. .ExpectCanvasTranslate(0, 0)
  38. .CheckDrawResult();
  39. }
  40. [Test]
  41. public void Measure_FullRender()
  42. {
  43. TestPlan
  44. .For(x => new MinimalBox
  45. {
  46. Child = x.CreateChild()
  47. })
  48. .MeasureElement(new Size(500, 400))
  49. .ExpectChildMeasure(expectedInput: new Size(500, 400), returns: SpacePlan.FullRender(300, 200))
  50. .ExpectCanvasTranslate(0, 0)
  51. .ExpectChildDraw(new Size(300, 200))
  52. .ExpectCanvasTranslate(0, 0)
  53. .CheckDrawResult();
  54. }
  55. [Test]
  56. public void Measure_PartialRender_RightToLeft()
  57. {
  58. TestPlan
  59. .For(x => new MinimalBox
  60. {
  61. Child = x.CreateChild(),
  62. ContentDirection = ContentDirection.RightToLeft
  63. })
  64. .MeasureElement(new Size(400, 300))
  65. .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.PartialRender(200, 100))
  66. .ExpectCanvasTranslate(200, 0)
  67. .ExpectChildDraw(new Size(200, 100))
  68. .ExpectCanvasTranslate(-200, 0)
  69. .CheckDrawResult();
  70. }
  71. [Test]
  72. public void Measure_FullRender_RightToLeft()
  73. {
  74. TestPlan
  75. .For(x => new MinimalBox
  76. {
  77. Child = x.CreateChild(),
  78. ContentDirection = ContentDirection.RightToLeft
  79. })
  80. .MeasureElement(new Size(500, 400))
  81. .ExpectChildMeasure(expectedInput: new Size(500, 400), returns: SpacePlan.FullRender(350, 200))
  82. .ExpectCanvasTranslate(150, 0)
  83. .ExpectChildDraw(new Size(350, 200))
  84. .ExpectCanvasTranslate(-150, 0)
  85. .CheckDrawResult();
  86. }
  87. }
  88. }