From 6d333da84c6eb7a4b2024c6310c270b15c887f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zi=C4=85bek?= Date: Sat, 18 Sep 2021 01:21:48 +0200 Subject: [PATCH] Added tests to check simple, container-like constraints for some elements --- QuestPDF.UnitTests/AlignmentTests.cs | 2 + QuestPDF.UnitTests/BackgroundTests.cs | 3 + QuestPDF.UnitTests/BorderTests.cs | 3 + QuestPDF.UnitTests/BoxTests.cs | 3 + QuestPDF.UnitTests/EnsureSpaceTests.cs | 3 + QuestPDF.UnitTests/ExtendTests.cs | 3 + QuestPDF.UnitTests/QuestPDF.UnitTests.csproj | 2 +- QuestPDF.UnitTests/RotateTests.cs | 3 + QuestPDF.UnitTests/ShowEntireTests.cs | 3 + QuestPDF.UnitTests/ShowOnceTest.cs | 22 +----- .../TestEngine/SimpleContainerTests.cs | 68 +++++++++++++++++++ QuestPDF.UnitTests/TranslateTests.cs | 3 + 12 files changed, 96 insertions(+), 22 deletions(-) create mode 100644 QuestPDF.UnitTests/TestEngine/SimpleContainerTests.cs diff --git a/QuestPDF.UnitTests/AlignmentTests.cs b/QuestPDF.UnitTests/AlignmentTests.cs index 9e2d796..5b19f53 100644 --- a/QuestPDF.UnitTests/AlignmentTests.cs +++ b/QuestPDF.UnitTests/AlignmentTests.cs @@ -9,6 +9,8 @@ namespace QuestPDF.UnitTests [TestFixture] public class AlignmentTests { + [Test] + public void Measure() => SimpleContainerTests.Measure(); [Test] public void Draw_HorizontalCenter_VerticalCenter() { diff --git a/QuestPDF.UnitTests/BackgroundTests.cs b/QuestPDF.UnitTests/BackgroundTests.cs index 9d237d2..f68282c 100644 --- a/QuestPDF.UnitTests/BackgroundTests.cs +++ b/QuestPDF.UnitTests/BackgroundTests.cs @@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests [TestFixture] public class BackgroundTests { + [Test] + public void Measure() => SimpleContainerTests.Measure(); + [Test] public void Draw_ShouldHandleNullChild() { diff --git a/QuestPDF.UnitTests/BorderTests.cs b/QuestPDF.UnitTests/BorderTests.cs index 5fca17b..a2d943f 100644 --- a/QuestPDF.UnitTests/BorderTests.cs +++ b/QuestPDF.UnitTests/BorderTests.cs @@ -10,6 +10,9 @@ namespace QuestPDF.UnitTests [TestFixture] public class BorderTests { + [Test] + public void Measure() => SimpleContainerTests.Measure(); + [Test] public void ComponentShouldNotAffectLayout() { diff --git a/QuestPDF.UnitTests/BoxTests.cs b/QuestPDF.UnitTests/BoxTests.cs index 8f7c782..c7153d1 100644 --- a/QuestPDF.UnitTests/BoxTests.cs +++ b/QuestPDF.UnitTests/BoxTests.cs @@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests [TestFixture] public class BoxTests { + [Test] + public void Measure() => SimpleContainerTests.Measure(); + [Test] public void Draw_Wrap() { diff --git a/QuestPDF.UnitTests/EnsureSpaceTests.cs b/QuestPDF.UnitTests/EnsureSpaceTests.cs index 67ac3cb..ab7e979 100644 --- a/QuestPDF.UnitTests/EnsureSpaceTests.cs +++ b/QuestPDF.UnitTests/EnsureSpaceTests.cs @@ -78,5 +78,8 @@ namespace QuestPDF.UnitTests .ExpectChildMeasure(new Size(400, 300), new FullRender(300, 250)) .CheckMeasureResult(new FullRender(300, 250)); } + + [Test] + public void Draw() => SimpleContainerTests.Draw(); } } \ No newline at end of file diff --git a/QuestPDF.UnitTests/ExtendTests.cs b/QuestPDF.UnitTests/ExtendTests.cs index 9c2618a..db83e23 100644 --- a/QuestPDF.UnitTests/ExtendTests.cs +++ b/QuestPDF.UnitTests/ExtendTests.cs @@ -81,5 +81,8 @@ namespace QuestPDF.UnitTests .ExpectChildMeasure(new Size(400, 200), new FullRender(100, 100)) .CheckMeasureResult(new FullRender(100, 200)); } + + [Test] + public void Draw() => SimpleContainerTests.Draw(); } } \ No newline at end of file diff --git a/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj b/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj index 5497f7f..f9cbd86 100644 --- a/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj +++ b/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj @@ -6,7 +6,7 @@ - + diff --git a/QuestPDF.UnitTests/RotateTests.cs b/QuestPDF.UnitTests/RotateTests.cs index ee30546..9ed94cc 100644 --- a/QuestPDF.UnitTests/RotateTests.cs +++ b/QuestPDF.UnitTests/RotateTests.cs @@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests [TestFixture] public class RotateTests { + [Test] + public void Measure() => SimpleContainerTests.Measure(); + [Test] public void Draw() { diff --git a/QuestPDF.UnitTests/ShowEntireTests.cs b/QuestPDF.UnitTests/ShowEntireTests.cs index e31e6af..3553880 100644 --- a/QuestPDF.UnitTests/ShowEntireTests.cs +++ b/QuestPDF.UnitTests/ShowEntireTests.cs @@ -47,5 +47,8 @@ namespace QuestPDF.UnitTests .ExpectChildMeasure(new Size(400, 300), new FullRender(300, 200)) .CheckMeasureResult(new FullRender(300, 200)); } + + [Test] + public void Draw() => SimpleContainerTests.Draw(); } } \ No newline at end of file diff --git a/QuestPDF.UnitTests/ShowOnceTest.cs b/QuestPDF.UnitTests/ShowOnceTest.cs index 4a75c57..fd2dff2 100644 --- a/QuestPDF.UnitTests/ShowOnceTest.cs +++ b/QuestPDF.UnitTests/ShowOnceTest.cs @@ -11,27 +11,7 @@ namespace QuestPDF.UnitTests public class ShowOnceTest { [Test] - public void ShouldRenderOnce_WhenRenderingCalledMultipleTimes() - { - var child = new Mock(); - - child - .Setup(x => x.Measure(It.IsAny())) - .Returns(() => new FullRender(Size.Zero)); - - var element = new ShowOnce() - { - Child = child.Object - }; - - element.Draw(Size.Zero); - element.Draw(Size.Zero); - - child.Verify(x => x.Draw(It.IsAny()), Times.Once); - } - - [Test] - public void Draw_HorizontalRight_VerticalTop() + public void Draw() { TestPlan .For(x => new ShowOnce() diff --git a/QuestPDF.UnitTests/TestEngine/SimpleContainerTests.cs b/QuestPDF.UnitTests/TestEngine/SimpleContainerTests.cs new file mode 100644 index 0000000..542be2f --- /dev/null +++ b/QuestPDF.UnitTests/TestEngine/SimpleContainerTests.cs @@ -0,0 +1,68 @@ +using QuestPDF.Drawing.SpacePlan; +using QuestPDF.Elements; +using QuestPDF.Infrastructure; + +namespace QuestPDF.UnitTests.TestEngine +{ + internal static class SimpleContainerTests + { + #region measure + + public static void Measure() where TElement : Element, IContainer, new() + { + Measure_Wrap(); + Measure_PartialRender(); + Measure_FullRender(); + } + + private static void Measure_Wrap() where TElement : Element, IContainer, new() + { + TestPlan + .For(x => new TElement + { + Child = x.CreateChild() + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure(new Size(400, 300), new Wrap()) + .CheckMeasureResult(new Wrap()); + } + + private static void Measure_PartialRender() where TElement : Element, IContainer, new() + { + TestPlan + .For(x => new TElement + { + Child = x.CreateChild() + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure(new Size(400, 300), new PartialRender(200, 100)) + .CheckMeasureResult(new PartialRender(200, 100)); + } + + private static void Measure_FullRender() where TElement : Element, IContainer, new() + { + TestPlan + .For(x => new TElement + { + Child = x.CreateChild() + }) + .MeasureElement(new Size(400, 300)) + .ExpectChildMeasure(new Size(400, 300), new FullRender(250, 150)) + .CheckMeasureResult(new FullRender(250, 150)); + } + + #endregion + + public static void Draw() where TElement : Element, IContainer, new() + { + TestPlan + .For(x => new TElement + { + Child = x.CreateChild() + }) + .DrawElement(new Size(1200, 900)) + .ExpectChildDraw(new Size(1200, 900)) + .CheckDrawResult(); + } + } +} \ No newline at end of file diff --git a/QuestPDF.UnitTests/TranslateTests.cs b/QuestPDF.UnitTests/TranslateTests.cs index 9d4bb70..f035346 100644 --- a/QuestPDF.UnitTests/TranslateTests.cs +++ b/QuestPDF.UnitTests/TranslateTests.cs @@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests [TestFixture] public class TranslateTests { + [Test] + public void Measure() => SimpleContainerTests.Measure(); + [Test] public void Draw() {