Extends Verify to allow verification of documents via QuestPDF.
See Milestones for release notes.
Designed to help assert the output of projects using QuestPDF to generate PDFs.
Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.
[ModuleInitializer]publicstaticvoidInit(){VerifierSettings.UseSsimForPng();VerifyQuestPdf.Initialize();}This sample uses Verify.ImageMagick to ignore small rendering differences that are expected between differens operating systesm.
Other compares options:
- https://github.com/VerifyTests/Verify.ImageHash
- https://github.com/VerifyTests/Verify.ImageMagick
- https://github.com/VerifyTests/Verify.Phash
- https://github.com/VerifyTests/Verify.ImageSharp.Compare
internalstaticIDocumentGenerateDocument()=>Document.Create(container =>{container.Page(AddPage);container.Page(AddPage);});staticvoidAddPage(PageDescriptorpage){page.Size(PageSizes.A5);page.Margin(1,Unit.Centimetre);page.PageColor(Colors.Grey.Lighten3);page.DefaultTextStyle(_ =>_.FontSize(20));page.Header().Text("Hello PDF!").SemiBold().FontSize(36);page.Content().Column(_ =>_.Item().Text(Placeholders.LoremIpsum()));page.Footer().AlignCenter().Text(_ =>{_.Span("Page ");_.CurrentPageNumber();});}[Test]publicTaskVerifyDocument(){vardocument=GenerateDocument();returnVerify(document);}{
Pages: 2,
Settings: {
ContentDirection: LeftToRight,
PDFA_Conformance: None,
PDFUA_Conformance: None,
ImageCompressionQuality: High,
ImageRasterDpi: 288
}
}QuestPDF renders the source pdf, and it is included in the snapshot as a .verified.pdf. Generating it is expensive, and committing it is not always wanted. ExcludeTargets drops it from a verification and skips the generation, while the rendered pages and info still verify:
[Test]publicTaskExcludePdf(){vardocument=GenerateDocument();returnVerify(document).ExcludeTargets("pdf");}To exclude the pdf for every test, call VerifierSettings.ExcludeTargets("pdf") at initialization.
To render only a defined number of pages at the start of a document:
[Test]publicTaskPagesToInclude(){vardocument=GenerateDocument();returnVerify(document).PagesToInclude(1);}To dynamically control what pages are rendered:
[Test]publicTaskPagesToIncludeDynamic(){vardocument=GenerateDocument();returnVerify(document).PagesToInclude(pageNumber =>pageNumber==2);}

