Added tests to check simple, container-like constraints for some elements
This commit is contained in:
Родитель
e411554a29
Коммит
6d333da84c
|
@ -9,6 +9,8 @@ namespace QuestPDF.UnitTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class AlignmentTests
|
public class AlignmentTests
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void Measure() => SimpleContainerTests.Measure<Alignment>();
|
||||||
[Test]
|
[Test]
|
||||||
public void Draw_HorizontalCenter_VerticalCenter()
|
public void Draw_HorizontalCenter_VerticalCenter()
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class BackgroundTests
|
public class BackgroundTests
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void Measure() => SimpleContainerTests.Measure<Background>();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Draw_ShouldHandleNullChild()
|
public void Draw_ShouldHandleNullChild()
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,9 @@ namespace QuestPDF.UnitTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class BorderTests
|
public class BorderTests
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void Measure() => SimpleContainerTests.Measure<Border>();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ComponentShouldNotAffectLayout()
|
public void ComponentShouldNotAffectLayout()
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class BoxTests
|
public class BoxTests
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void Measure() => SimpleContainerTests.Measure<Box>();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Draw_Wrap()
|
public void Draw_Wrap()
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,5 +78,8 @@ namespace QuestPDF.UnitTests
|
||||||
.ExpectChildMeasure(new Size(400, 300), new FullRender(300, 250))
|
.ExpectChildMeasure(new Size(400, 300), new FullRender(300, 250))
|
||||||
.CheckMeasureResult(new FullRender(300, 250));
|
.CheckMeasureResult(new FullRender(300, 250));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Draw() => SimpleContainerTests.Draw<EnsureSpace>();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -81,5 +81,8 @@ namespace QuestPDF.UnitTests
|
||||||
.ExpectChildMeasure(new Size(400, 200), new FullRender(100, 100))
|
.ExpectChildMeasure(new Size(400, 200), new FullRender(100, 100))
|
||||||
.CheckMeasureResult(new FullRender(100, 200));
|
.CheckMeasureResult(new FullRender(100, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Draw() => SimpleContainerTests.Draw<Extend>();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FluentAssertions" Version="6.1.0" />
|
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||||
<PackageReference Include="Moq" Version="4.13.1" />
|
<PackageReference Include="Moq" Version="4.13.1" />
|
||||||
<PackageReference Include="nunit" Version="3.13.2" />
|
<PackageReference Include="nunit" Version="3.13.2" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
||||||
|
|
|
@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class RotateTests
|
public class RotateTests
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void Measure() => SimpleContainerTests.Measure<Rotate>();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,5 +47,8 @@ namespace QuestPDF.UnitTests
|
||||||
.ExpectChildMeasure(new Size(400, 300), new FullRender(300, 200))
|
.ExpectChildMeasure(new Size(400, 300), new FullRender(300, 200))
|
||||||
.CheckMeasureResult(new FullRender(300, 200));
|
.CheckMeasureResult(new FullRender(300, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Draw() => SimpleContainerTests.Draw<ShowEntire>();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,27 +11,7 @@ namespace QuestPDF.UnitTests
|
||||||
public class ShowOnceTest
|
public class ShowOnceTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldRenderOnce_WhenRenderingCalledMultipleTimes()
|
public void Draw()
|
||||||
{
|
|
||||||
var child = new Mock<Element>();
|
|
||||||
|
|
||||||
child
|
|
||||||
.Setup(x => x.Measure(It.IsAny<Size>()))
|
|
||||||
.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<Size>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Draw_HorizontalRight_VerticalTop()
|
|
||||||
{
|
{
|
||||||
TestPlan
|
TestPlan
|
||||||
.For(x => new ShowOnce()
|
.For(x => new ShowOnce()
|
||||||
|
|
|
@ -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<TElement>() where TElement : Element, IContainer, new()
|
||||||
|
{
|
||||||
|
Measure_Wrap<TElement>();
|
||||||
|
Measure_PartialRender<TElement>();
|
||||||
|
Measure_FullRender<TElement>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Measure_Wrap<TElement>() 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<TElement>() 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<TElement>() 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<TElement>() where TElement : Element, IContainer, new()
|
||||||
|
{
|
||||||
|
TestPlan
|
||||||
|
.For(x => new TElement
|
||||||
|
{
|
||||||
|
Child = x.CreateChild()
|
||||||
|
})
|
||||||
|
.DrawElement(new Size(1200, 900))
|
||||||
|
.ExpectChildDraw(new Size(1200, 900))
|
||||||
|
.CheckDrawResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,9 @@ namespace QuestPDF.UnitTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TranslateTests
|
public class TranslateTests
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void Measure() => SimpleContainerTests.Measure<Translate>();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче