diff --git a/QuestPDF.UnitTests/DecorationTests.cs b/QuestPDF.UnitTests/DecorationTests.cs new file mode 100644 index 0000000..f64cd4b --- /dev/null +++ b/QuestPDF.UnitTests/DecorationTests.cs @@ -0,0 +1,136 @@ +using NUnit.Framework; +using QuestPDF.Drawing.SpacePlan; +using QuestPDF.Elements; +using QuestPDF.Infrastructure; +using QuestPDF.UnitTests.TestEngine; + +namespace QuestPDF.UnitTests +{ + [TestFixture] + public class DecorationTests + { + #region Measure + + [Test] + public void Measure_ReturnsWrap_WhenDecorationReturnsWrap() + { + TestPlan + .For(x => new Decoration + { + Type = DecorationType.Append, + DecorationElement = x.CreateChild("decoration"), + ContentElement = x.CreateChild("content") + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure("decoration", new Size(400, 300), new Wrap()) + .CheckMeasureResult(new Wrap()); + } + + [Test] + public void Measure_ReturnsWrap_WhenDecorationReturnsPartialRender() + { + TestPlan + .For(x => new Decoration + { + Type = DecorationType.Append, + DecorationElement = x.CreateChild("decoration"), + ContentElement = x.CreateChild("content") + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure("decoration", new Size(400, 300), new PartialRender(300, 200)) + .CheckMeasureResult(new Wrap()); + } + + [Test] + public void Measure_ReturnsWrap_WhenContentReturnsWrap() + { + TestPlan + .For(x => new Decoration + { + Type = DecorationType.Append, + DecorationElement = x.CreateChild("decoration"), + ContentElement = x.CreateChild("content") + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure("decoration", new Size(400, 300), new FullRender(300, 100)) + .ExpectChildMeasure("content", new Size(400, 200), new Wrap()) + .CheckMeasureResult(new Wrap()); + } + + [Test] + public void Measure_ReturnsPartialRender_WhenContentReturnsPartialRender() + { + TestPlan + .For(x => new Decoration + { + Type = DecorationType.Append, + DecorationElement = x.CreateChild("decoration"), + ContentElement = x.CreateChild("content") + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure("decoration", new Size(400, 300), new FullRender(300, 100)) + .ExpectChildMeasure("content", new Size(400, 200), new PartialRender(200, 150)) + .CheckMeasureResult(new PartialRender(400, 250)); + } + + [Test] + public void Measure_ReturnsFullRender_WhenContentReturnsFullRender() + { + TestPlan + .For(x => new Decoration + { + Type = DecorationType.Append, + DecorationElement = x.CreateChild("decoration"), + ContentElement = x.CreateChild("content") + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure("decoration", new Size(400, 300), new FullRender(300, 100)) + .ExpectChildMeasure("content", new Size(400, 200), new FullRender(200, 150)) + .CheckMeasureResult(new FullRender(400, 250)); + } + + #endregion + + #region Draw + + [Test] + public void Draw_Prepend() + { + TestPlan + .For(x => new Decoration + { + Type = DecorationType.Prepend, + DecorationElement = x.CreateChild("decoration"), + ContentElement = x.CreateChild("content") + }) + .DrawElement(new Size(400, 300)) + .ExpectChildMeasure("decoration", new Size(400, 300), new FullRender(300, 100)) + .ExpectChildDraw("decoration", new Size(400, 100)) + .ExpectCanvasTranslate(0, 100) + .ExpectChildDraw("content", new Size(400, 200)) + .ExpectCanvasTranslate(0, -100) + .CheckDrawResult(); + } + + [Test] + public void Draw_Append() + { + TestPlan + .For(x => new Decoration + { + Type = DecorationType.Append, + DecorationElement = x.CreateChild("decoration"), + ContentElement = x.CreateChild("content") + }) + .DrawElement(new Size(400, 300)) + .ExpectChildMeasure("decoration", new Size(400, 300), new FullRender(300, 100)) + .ExpectChildDraw("content", new Size(400, 200)) + .ExpectCanvasTranslate(0, 200) + .ExpectChildDraw("decoration", new Size(400, 100)) + .ExpectCanvasTranslate(0, -200) + .CheckDrawResult(); + } + + #endregion + } +} \ No newline at end of file diff --git a/QuestPDF/Elements/Decoration.cs b/QuestPDF/Elements/Decoration.cs index 52a0562..b45b515 100644 --- a/QuestPDF/Elements/Decoration.cs +++ b/QuestPDF/Elements/Decoration.cs @@ -13,8 +13,8 @@ namespace QuestPDF.Elements internal class Decoration : Element { - public Element? DecorationElement { get; set; } - public Element? ContentElement { get; set; } + public Element DecorationElement { get; set; } = new Empty(); + public Element ContentElement { get; set; } = new Empty(); public DecorationType Type { get; set; } internal override ISpacePlan Measure(Size availableSpace)