Added tests for several elements

This commit is contained in:
Marcin Ziąbek 2021-04-09 19:10:55 +02:00
Родитель 733dbc8746
Коммит 842b856f7a
12 изменённых файлов: 361 добавлений и 59 удалений

Просмотреть файл

@ -1,10 +0,0 @@
using NUnit.Framework;
namespace QuestPDF.UnitTests
{
[TestFixture]
public class DocumentTests
{
}
}

Просмотреть файл

@ -1,5 +1,7 @@
using NUnit.Framework;
using QuestPDF.Drawing.SpacePlan;
using QuestPDF.Elements;
using QuestPDF.Infrastructure;
using QuestPDF.UnitTests.TestEngine;
namespace QuestPDF.UnitTests
@ -12,5 +14,78 @@ namespace QuestPDF.UnitTests
[Test]
public void Draw_ShouldHandleNullChild() => new Extend().DrawWithoutChild();
[Test]
public void Measure_ReturnsWrap_WhenChildReturnsWrap()
{
TestPlan
.For(x => new Extend
{
Child = x.CreateChild()
})
.MeasureElement(new Size(400, 200))
.ExpectChildMeasure(new Size(400, 200), new Wrap())
.CheckMeasureResult(new Wrap());
}
[Test]
public void Measure_ReturnsPartialRender_WhenChildReturnsPartialRender()
{
TestPlan
.For(x => new Extend
{
Child = x.CreateChild(),
ExtendHorizontal = true,
ExtendVertical = true
})
.MeasureElement(new Size(400, 200))
.ExpectChildMeasure(new Size(400, 200), new PartialRender(300, 100))
.CheckMeasureResult(new PartialRender(400, 200));
}
[Test]
public void Measure_ReturnsFullRender_WhenChildReturnsFullRender()
{
TestPlan
.For(x => new Extend
{
Child = x.CreateChild(),
ExtendHorizontal = true,
ExtendVertical = true
})
.MeasureElement(new Size(400, 200))
.ExpectChildMeasure(new Size(400, 200), new FullRender(300, 100))
.CheckMeasureResult(new FullRender(400, 200));
}
[Test]
public void Measure_ExtendHorizontal()
{
TestPlan
.For(x => new Extend
{
Child = x.CreateChild(),
ExtendHorizontal = true,
ExtendVertical = false
})
.MeasureElement(new Size(400, 200))
.ExpectChildMeasure(new Size(400, 200), new FullRender(100, 100))
.CheckMeasureResult(new FullRender(400, 100));
}
[Test]
public void Measure_ExtendVertical()
{
TestPlan
.For(x => new Extend
{
Child = x.CreateChild(),
ExtendHorizontal = false,
ExtendVertical = true
})
.MeasureElement(new Size(400, 200))
.ExpectChildMeasure(new Size(400, 200), new FullRender(100, 100))
.CheckMeasureResult(new FullRender(100, 200));
}
}
}

Просмотреть файл

@ -3,6 +3,7 @@ using NUnit.Framework;
using QuestPDF.Drawing.SpacePlan;
using QuestPDF.Elements;
using QuestPDF.Infrastructure;
using QuestPDF.UnitTests.TestEngine;
namespace QuestPDF.UnitTests
{
@ -10,13 +11,19 @@ namespace QuestPDF.UnitTests
public class PageBreakTests
{
[Test]
public void Measure_ShouldReturnWrapThenFullRender()
public void Measure()
{
var pageBreak = new PageBreak();
TestPlan
.For(x => new PageBreak())
pageBreak.Measure(Helpers.RandomSize).Should().BeOfType<PartialRender>();
pageBreak.Draw(null, Size.Zero);
pageBreak.Measure(Helpers.RandomSize).Should().BeEquivalentTo(new FullRender(Size.Zero));
.MeasureElement(new Size(400, 300))
.CheckMeasureResult(new PartialRender(400, 300))
.DrawElement(new Size(400, 300))
.CheckDrawResult()
.MeasureElement(new Size(500, 400))
.CheckMeasureResult(new FullRender(Size.Zero));
}
}
}

Просмотреть файл

@ -1,10 +0,0 @@
using NUnit.Framework;
namespace QuestPDF.UnitTests
{
[TestFixture]
public class PageTests
{
}
}

Просмотреть файл

@ -1,10 +0,0 @@
using NUnit.Framework;
namespace QuestPDF.UnitTests
{
[TestFixture]
public class PageableColumnTests
{
}
}

Просмотреть файл

@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />

Просмотреть файл

@ -1,10 +1,115 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using FluentAssertions;
using FluentAssertions.Equivalency;
using NUnit.Framework;
using QuestPDF.Elements;
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;
using QuestPDF.UnitTests.TestEngine;
namespace QuestPDF.UnitTests
{
[TestFixture]
public class RowTests
{
#region Spacing
[Test]
public void Fluent_WithoutSpacing()
{
// arrange
var structure = new Container();
var childA = TestPlan.CreateUniqueElement();
var childB = TestPlan.CreateUniqueElement();
var childC = TestPlan.CreateUniqueElement();
// act
structure
.Row(stack =>
{
stack.Spacing(0);
stack.ConstantColumn(100).Element(childA);
stack.RelativeColumn(2).Element(childB);
stack.RelativeColumn(3).Element(childC);
});
// assert
var expected = new Row()
{
Children = new List<RowElement>
{
new ConstantRowElement(100)
{
Child = childA
},
new RelativeRowElement(2)
{
Child = childB
},
new RelativeRowElement(3)
{
Child = childC
},
}
};
structure.Child.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering().IncludingAllRuntimeProperties());
}
[Test]
public void Fluent_WithSpacing()
{
// arrange
var structure = new Container();
var childA = TestPlan.CreateUniqueElement();
var childB = TestPlan.CreateUniqueElement();
var childC = TestPlan.CreateUniqueElement();
// act
structure
.Row(stack =>
{
stack.Spacing(25);
stack.ConstantColumn(100).Element(childA);
stack.RelativeColumn(2).Element(childB);
stack.RelativeColumn(3).Element(childC);
});
// assert
var expected = new Padding
{
Right = -25,
Child = new Row()
{
Children = new List<RowElement>
{
new ConstantRowElement(100)
{
Child = childA
},
new ConstantRowElement(25),
new RelativeRowElement(2)
{
Child = childB
},
new ConstantRowElement(25),
new RelativeRowElement(3)
{
Child = childC
},
new ConstantRowElement(25)
}
}
};
structure.Child.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering().IncludingAllRuntimeProperties());
}
#endregion
}
}

Просмотреть файл

@ -1,10 +0,0 @@
using NUnit.Framework;
namespace QuestPDF.UnitTests
{
[TestFixture]
public class SectionTests
{
}
}

Просмотреть файл

@ -0,0 +1,51 @@
using NUnit.Framework;
using QuestPDF.Drawing.SpacePlan;
using QuestPDF.Elements;
using QuestPDF.Infrastructure;
using QuestPDF.UnitTests.TestEngine;
namespace QuestPDF.UnitTests
{
[TestFixture]
public class ShowEntireTests
{
[Test]
public void Measure_ReturnsWrap_WhenElementReturnsWrap()
{
TestPlan
.For(x => new ShowEntire
{
Child = x.CreateChild()
})
.MeasureElement(new Size(400, 300))
.ExpectChildMeasure(new Size(400, 300), new Wrap())
.CheckMeasureResult(new Wrap());
}
[Test]
public void Measure_ReturnsWrap_WhenElementReturnsPartialRender()
{
TestPlan
.For(x => new ShowEntire
{
Child = x.CreateChild()
})
.MeasureElement(new Size(400, 300))
.ExpectChildMeasure(new Size(400, 300), new PartialRender(300, 200))
.CheckMeasureResult(new Wrap());
}
[Test]
public void Measure_ReturnsFullRender_WhenElementReturnsFullRender()
{
TestPlan
.For(x => new ShowEntire
{
Child = x.CreateChild()
})
.MeasureElement(new Size(400, 300))
.ExpectChildMeasure(new Size(400, 300), new FullRender(300, 200))
.CheckMeasureResult(new FullRender(300, 200));
}
}
}

Просмотреть файл

@ -1,6 +1,11 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using FluentAssertions;
using FluentAssertions.Equivalency;
using NUnit.Framework;
using QuestPDF.Drawing.SpacePlan;
using QuestPDF.Elements;
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;
using QuestPDF.UnitTests.TestEngine;
@ -9,6 +14,8 @@ namespace QuestPDF.UnitTests
[TestFixture]
public class StackTests
{
#region Measure
[Test]
public void Measure_NoChildren_Empty()
{
@ -57,6 +64,10 @@ namespace QuestPDF.UnitTests
.CheckMeasureResult(new Wrap());
}
#endregion
#region Combined
[Test]
public void WhenPageable_AndChildReturnsWrap()
{
@ -167,5 +178,99 @@ namespace QuestPDF.UnitTests
.CheckDrawResult();
}
#endregion
#region Spacing
[Test]
public void Fluent_WithoutSpacing()
{
// arrange
var structure = new Container();
var childA = TestPlan.CreateUniqueElement();
var childB = TestPlan.CreateUniqueElement();
var childC = TestPlan.CreateUniqueElement();
// act
structure
.Stack(stack =>
{
stack.Spacing(0);
stack.Element(childA);
stack.Element(childB);
stack.Element(childC);
});
// assert
var expected = new Stack
{
Children = new List<Element>
{
childA,
childB,
childC
}
};
structure.Child.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering().IncludingAllRuntimeProperties());
}
[Test]
public void Fluent_WithSpacing()
{
// arrange
var structure = new Container();
var childA = TestPlan.CreateUniqueElement();
var childB = TestPlan.CreateUniqueElement();
var childC = TestPlan.CreateUniqueElement();
// act
structure
.Stack(stack =>
{
stack.Spacing(100);
stack.Element(childA);
stack.Element(childB);
stack.Element(childC);
});
// assert
var expected = new Padding
{
Bottom = -100,
Child = new Stack
{
Children = new List<Element>
{
new Padding
{
Bottom = 100,
Child = childA
},
new Padding
{
Bottom = 100,
Child = childB
},
new Padding
{
Bottom = 100,
Child = childC
},
}
}
};
var traceWriter = new StringBuilderTraceWriter();
structure.Child.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering().IncludingAllRuntimeProperties());
Console.WriteLine( traceWriter.ToString());
}
#endregion
}
}

Просмотреть файл

@ -1,10 +0,0 @@
using NUnit.Framework;
namespace QuestPDF.UnitTests
{
[TestFixture]
public class TemplateTests
{
}
}

Просмотреть файл

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text.Json;
using NUnit.Framework;
using QuestPDF.Drawing.SpacePlan;
using QuestPDF.Elements;
using QuestPDF.Infrastructure;
using QuestPDF.UnitTests.TestEngine.Operations;
@ -225,5 +226,13 @@ namespace QuestPDF.UnitTests.TestEngine
Element.Draw(Canvas, OperationInput);
return this;
}
public static Element CreateUniqueElement()
{
return new Text
{
Value = Guid.NewGuid().ToString("N")
};
}
}
}