DecorationTests.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 DecorationTests
  10. {
  11. #region Measure
  12. [Test]
  13. public void Measure_ReturnsWrap_WhenDecorationReturnsWrap()
  14. {
  15. TestPlan
  16. .For(x => new BinaryDecoration
  17. {
  18. Type = DecorationType.Append,
  19. DecorationElement = x.CreateChild("decoration"),
  20. ContentElement = x.CreateChild("content")
  21. })
  22. .MeasureElement(new Size(400, 300))
  23. .ExpectChildMeasure("decoration", new Size(400, 300), SpacePlan.Wrap())
  24. .CheckMeasureResult(SpacePlan.Wrap());
  25. }
  26. [Test]
  27. public void Measure_ReturnsWrap_WhenDecorationReturnsPartialRender()
  28. {
  29. TestPlan
  30. .For(x => new BinaryDecoration
  31. {
  32. Type = DecorationType.Append,
  33. DecorationElement = x.CreateChild("decoration"),
  34. ContentElement = x.CreateChild("content")
  35. })
  36. .MeasureElement(new Size(400, 300))
  37. .ExpectChildMeasure("decoration", new Size(400, 300), SpacePlan.PartialRender(300, 200))
  38. .CheckMeasureResult(SpacePlan.Wrap());
  39. }
  40. [Test]
  41. public void Measure_ReturnsWrap_WhenContentReturnsWrap()
  42. {
  43. TestPlan
  44. .For(x => new BinaryDecoration
  45. {
  46. Type = DecorationType.Append,
  47. DecorationElement = x.CreateChild("decoration"),
  48. ContentElement = x.CreateChild("content")
  49. })
  50. .MeasureElement(new Size(400, 300))
  51. .ExpectChildMeasure("decoration", new Size(400, 300), SpacePlan.FullRender(300, 100))
  52. .ExpectChildMeasure("content", new Size(400, 200), SpacePlan.Wrap())
  53. .CheckMeasureResult(SpacePlan.Wrap());
  54. }
  55. [Test]
  56. public void Measure_ReturnsPartialRender_WhenContentReturnsPartialRender()
  57. {
  58. TestPlan
  59. .For(x => new BinaryDecoration
  60. {
  61. Type = DecorationType.Append,
  62. DecorationElement = x.CreateChild("decoration"),
  63. ContentElement = x.CreateChild("content")
  64. })
  65. .MeasureElement(new Size(400, 300))
  66. .ExpectChildMeasure("decoration", new Size(400, 300), SpacePlan.FullRender(300, 100))
  67. .ExpectChildMeasure("content", new Size(400, 200), SpacePlan.PartialRender(200, 150))
  68. .CheckMeasureResult(SpacePlan.PartialRender(400, 250));
  69. }
  70. [Test]
  71. public void Measure_ReturnsFullRender_WhenContentReturnsFullRender()
  72. {
  73. TestPlan
  74. .For(x => new BinaryDecoration
  75. {
  76. Type = DecorationType.Append,
  77. DecorationElement = x.CreateChild("decoration"),
  78. ContentElement = x.CreateChild("content")
  79. })
  80. .MeasureElement(new Size(400, 300))
  81. .ExpectChildMeasure("decoration", new Size(400, 300), SpacePlan.FullRender(300, 100))
  82. .ExpectChildMeasure("content", new Size(400, 200), SpacePlan.FullRender(200, 150))
  83. .CheckMeasureResult(SpacePlan.FullRender(400, 250));
  84. }
  85. #endregion
  86. #region Draw
  87. [Test]
  88. public void Draw_Prepend()
  89. {
  90. TestPlan
  91. .For(x => new BinaryDecoration
  92. {
  93. Type = DecorationType.Prepend,
  94. DecorationElement = x.CreateChild("decoration"),
  95. ContentElement = x.CreateChild("content")
  96. })
  97. .DrawElement(new Size(400, 300))
  98. .ExpectChildMeasure("decoration", new Size(400, 300), SpacePlan.FullRender(300, 100))
  99. .ExpectChildDraw("decoration", new Size(400, 100))
  100. .ExpectCanvasTranslate(0, 100)
  101. .ExpectChildDraw("content", new Size(400, 200))
  102. .ExpectCanvasTranslate(0, -100)
  103. .CheckDrawResult();
  104. }
  105. [Test]
  106. public void Draw_Append()
  107. {
  108. TestPlan
  109. .For(x => new BinaryDecoration
  110. {
  111. Type = DecorationType.Append,
  112. DecorationElement = x.CreateChild("decoration"),
  113. ContentElement = x.CreateChild("content")
  114. })
  115. .DrawElement(new Size(400, 300))
  116. .ExpectChildMeasure("decoration", new Size(400, 300), SpacePlan.FullRender(300, 100))
  117. .ExpectChildDraw("content", new Size(400, 200))
  118. .ExpectCanvasTranslate(0, 200)
  119. .ExpectChildDraw("decoration", new Size(400, 100))
  120. .ExpectCanvasTranslate(0, -200)
  121. .CheckDrawResult();
  122. }
  123. #endregion
  124. }
  125. }