|
|
@@ -1,7 +1,9 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text.Json;
|
|
|
+using FluentAssertions;
|
|
|
using NUnit.Framework;
|
|
|
+using QuestPDF.Drawing;
|
|
|
using QuestPDF.Drawing.SpacePlan;
|
|
|
using QuestPDF.Elements;
|
|
|
using QuestPDF.Helpers;
|
|
|
@@ -13,6 +15,8 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
internal class TestPlan
|
|
|
{
|
|
|
private const string DefaultChildName = "child";
|
|
|
+
|
|
|
+ private static Random Random { get; } = new Random();
|
|
|
|
|
|
private Element Element { get; set; }
|
|
|
private ICanvas Canvas { get; }
|
|
|
@@ -45,20 +49,31 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
|
|
|
private ICanvas CreateCanvas()
|
|
|
{
|
|
|
- return new CanvasMock
|
|
|
+ return new MockCanvas
|
|
|
{
|
|
|
TranslateFunc = position =>
|
|
|
{
|
|
|
- var expected = GetExpected<CanvasTranslateOperationBase>();
|
|
|
+ var expected = GetExpected<CanvasTranslateOperation>();
|
|
|
|
|
|
Assert.AreEqual(expected.Position.X, position.X, "Translate X");
|
|
|
Assert.AreEqual(expected.Position.Y, position.Y, "Translate Y");
|
|
|
-
|
|
|
- //position.Should().BeEquivalentTo(expected.Position);
|
|
|
+ },
|
|
|
+ RotateFunc = angle =>
|
|
|
+ {
|
|
|
+ var expected = GetExpected<CanvasRotateOperation>();
|
|
|
+
|
|
|
+ Assert.AreEqual(expected.Angle, angle, "Rotate angle");
|
|
|
+ },
|
|
|
+ ScaleFunc = (scaleX, scaleY) =>
|
|
|
+ {
|
|
|
+ var expected = GetExpected<CanvasScaleOperation>();
|
|
|
+
|
|
|
+ Assert.AreEqual(expected.ScaleX, scaleX, "Scale X");
|
|
|
+ Assert.AreEqual(expected.ScaleY, scaleY, "Scale Y");
|
|
|
},
|
|
|
DrawRectFunc = (position, size, color) =>
|
|
|
{
|
|
|
- var expected = GetExpected<CanvasDrawRectangleOperationBase>();
|
|
|
+ var expected = GetExpected<CanvasDrawRectangleOperation>();
|
|
|
|
|
|
Assert.AreEqual(expected.Position.X, position.X, "Draw rectangle: X");
|
|
|
Assert.AreEqual(expected.Position.Y, position.Y, "Draw rectangle: Y");
|
|
|
@@ -67,14 +82,10 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
Assert.AreEqual(expected.Size.Height, size.Height, "Draw rectangle: height");
|
|
|
|
|
|
Assert.AreEqual(expected.Color, color, "Draw rectangle: color");
|
|
|
-
|
|
|
- /*position.Should().BeEquivalentTo(expected.Position);
|
|
|
- size.Should().BeEquivalentTo(expected.Size);
|
|
|
- color.Should().Be(expected.Color);*/
|
|
|
},
|
|
|
DrawTextFunc = (text, position, style) =>
|
|
|
{
|
|
|
- var expected = GetExpected<CanvasDrawTextOperationBase>();
|
|
|
+ var expected = GetExpected<CanvasDrawTextOperation>();
|
|
|
|
|
|
Assert.AreEqual(expected.Text, text);
|
|
|
|
|
|
@@ -84,23 +95,16 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
Assert.AreEqual(expected.Style.Color, style.Color, "Draw text: color");
|
|
|
Assert.AreEqual(expected.Style.FontType, style.FontType, "Draw text: font");
|
|
|
Assert.AreEqual(expected.Style.Size, style.Size, "Draw text: size");
|
|
|
-
|
|
|
- /*text.Should().Be(expected.Text);
|
|
|
- position.Should().BeEquivalentTo(expected.Position);
|
|
|
- style.Should().BeEquivalentTo(expected.Style);*/
|
|
|
},
|
|
|
DrawImageFunc = (image, position, size) =>
|
|
|
{
|
|
|
- var expected = GetExpected<CanvasDrawImageOperationBase>();
|
|
|
+ var expected = GetExpected<CanvasDrawImageOperation>();
|
|
|
|
|
|
Assert.AreEqual(expected.Position.X, position.X, "Draw image: X");
|
|
|
Assert.AreEqual(expected.Position.Y, position.Y, "Draw image: Y");
|
|
|
|
|
|
Assert.AreEqual(expected.Size.Width, size.Width, "Draw image: width");
|
|
|
Assert.AreEqual(expected.Size.Height, size.Height, "Draw image: height");
|
|
|
-
|
|
|
- /*position.Should().BeEquivalentTo(expected.Position);
|
|
|
- size.Should().BeEquivalentTo(expected.Size);*/
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
@@ -114,29 +118,23 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
Id = id,
|
|
|
MeasureFunc = availableSpace =>
|
|
|
{
|
|
|
- var expected = GetExpected<ChildMeasureOperationBase>();
|
|
|
+ var expected = GetExpected<ChildMeasureOperation>();
|
|
|
|
|
|
Assert.AreEqual(expected.ChildId, id);
|
|
|
|
|
|
Assert.AreEqual(expected.Input.Width, availableSpace.Width, $"Measure: width of child '{expected.ChildId}'");
|
|
|
Assert.AreEqual(expected.Input.Height, availableSpace.Height, $"Measure: height of child '{expected.ChildId}'");
|
|
|
|
|
|
- // id.Should().Be(expected.ChildId);
|
|
|
- // availableSpace.Should().Be(expected.Input);
|
|
|
-
|
|
|
return expected.Output;
|
|
|
},
|
|
|
DrawFunc = availableSpace =>
|
|
|
{
|
|
|
- var expected = GetExpected<ChildDrawOperationBase>();
|
|
|
+ var expected = GetExpected<ChildDrawOperation>();
|
|
|
|
|
|
Assert.AreEqual(expected.ChildId, id);
|
|
|
|
|
|
Assert.AreEqual(expected.Input.Width, availableSpace.Width, $"Draw: width of child '{expected.ChildId}'");
|
|
|
Assert.AreEqual(expected.Input.Height, availableSpace.Height, $"Draw: width of child '{expected.ChildId}'");
|
|
|
-
|
|
|
- /*id.Should().Be(expected.ChildId);
|
|
|
- availableSpace.Should().Be(expected.Input);*/
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
@@ -166,7 +164,7 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
|
|
|
public TestPlan ExpectChildMeasure(string child, Size expectedInput, ISpacePlan returns)
|
|
|
{
|
|
|
- return AddOperation(new ChildMeasureOperationBase(child, expectedInput, returns));
|
|
|
+ return AddOperation(new ChildMeasureOperation(child, expectedInput, returns));
|
|
|
}
|
|
|
|
|
|
public TestPlan ExpectChildDraw(Size expectedInput)
|
|
|
@@ -176,32 +174,42 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
|
|
|
public TestPlan ExpectChildDraw(string child, Size expectedInput)
|
|
|
{
|
|
|
- return AddOperation(new ChildDrawOperationBase(child, expectedInput));
|
|
|
+ return AddOperation(new ChildDrawOperation(child, expectedInput));
|
|
|
}
|
|
|
|
|
|
public TestPlan ExpectCanvasTranslate(Position position)
|
|
|
{
|
|
|
- return AddOperation(new CanvasTranslateOperationBase(position));
|
|
|
+ return AddOperation(new CanvasTranslateOperation(position));
|
|
|
}
|
|
|
|
|
|
public TestPlan ExpectCanvasTranslate(float left, float top)
|
|
|
{
|
|
|
- return AddOperation(new CanvasTranslateOperationBase(new Position(left, top)));
|
|
|
+ return AddOperation(new CanvasTranslateOperation(new Position(left, top)));
|
|
|
}
|
|
|
|
|
|
+ public TestPlan ExpectCanvasScale(float scaleX, float scaleY)
|
|
|
+ {
|
|
|
+ return AddOperation(new CanvasScaleOperation(scaleX, scaleY));
|
|
|
+ }
|
|
|
+
|
|
|
+ public TestPlan ExpectCanvasRotate(float angle)
|
|
|
+ {
|
|
|
+ return AddOperation(new CanvasRotateOperation(angle));
|
|
|
+ }
|
|
|
+
|
|
|
public TestPlan ExpectCanvasDrawRectangle(Position position, Size size, string color)
|
|
|
{
|
|
|
- return AddOperation(new CanvasDrawRectangleOperationBase(position, size, color));
|
|
|
+ return AddOperation(new CanvasDrawRectangleOperation(position, size, color));
|
|
|
}
|
|
|
|
|
|
public TestPlan ExpectCanvasDrawText(string text, Position position, TextStyle style)
|
|
|
{
|
|
|
- return AddOperation(new CanvasDrawTextOperationBase(text, position, style));
|
|
|
+ return AddOperation(new CanvasDrawTextOperation(text, position, style));
|
|
|
}
|
|
|
|
|
|
public TestPlan ExpectCanvasDrawImage(Position position, Size size)
|
|
|
{
|
|
|
- return AddOperation(new CanvasDrawImageOperationBase(position, size));
|
|
|
+ return AddOperation(new CanvasDrawImageOperation(position, size));
|
|
|
}
|
|
|
|
|
|
public TestPlan CheckMeasureResult(ISpacePlan expected)
|
|
|
@@ -251,5 +259,40 @@ namespace QuestPDF.UnitTests.TestEngine
|
|
|
Source = Placeholders.Image
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ public static void CompareOperations(Element value, Element expected, Size? availableSpace = null)
|
|
|
+ {
|
|
|
+ CompareMeasureOperations(value, expected, availableSpace);
|
|
|
+ CompareDrawOperations(value, expected, availableSpace);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void CompareMeasureOperations(Element value, Element expected, Size? availableSpace = null)
|
|
|
+ {
|
|
|
+ availableSpace ??= new Size(400, 300);
|
|
|
+
|
|
|
+ var canvas = new FreeCanvas();
|
|
|
+ value.HandleVisitor(x => x.Initialize(null, canvas));
|
|
|
+ var valueMeasure = value.Measure(availableSpace);
|
|
|
+
|
|
|
+ expected.HandleVisitor(x => x.Initialize(null, canvas));
|
|
|
+ var expectedMeasure = expected.Measure(availableSpace);
|
|
|
+
|
|
|
+ valueMeasure.Should().BeEquivalentTo(expectedMeasure);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void CompareDrawOperations(Element value, Element expected, Size? availableSpace = null)
|
|
|
+ {
|
|
|
+ availableSpace ??= new Size(400, 300);
|
|
|
+
|
|
|
+ var valueCanvas = new OperationRecordingCanvas();
|
|
|
+ value.HandleVisitor(x => x.Initialize(null, valueCanvas));
|
|
|
+ value.Draw(availableSpace);
|
|
|
+
|
|
|
+ var expectedCanvas = new OperationRecordingCanvas();
|
|
|
+ expected.HandleVisitor(x => x.Initialize(null, expectedCanvas));
|
|
|
+ expected.Draw(availableSpace);
|
|
|
+
|
|
|
+ valueCanvas.Operations.Should().BeEquivalentTo(expectedCanvas.Operations);
|
|
|
+ }
|
|
|
}
|
|
|
}
|