zplCore.comzplCore.com

LabelAssertions

public sealed class LabelAssertions

Fluent assertions on a rendered ZPL job. Job-level assertions (LabelAssertions.HasLabels, LabelAssertions.Renders, LabelAssertions.Complies, LabelAssertions.MatchesSnapshot, LabelAssertions.NoOverlaps, LabelAssertions.NoClipping, LabelAssertions.AllBarcodesDecode, LabelAssertions.FitsPrinter) check every label; after LabelAssertions.OnLabel they check that label only. Element selectors (LabelAssertions.Barcode, LabelAssertions.Text, LabelAssertions.FieldEquals) search label 0 unless LabelAssertions.OnLabel picks another one.

Properties

PropertyTypeDescription
Current { get; }ComplianceLabelThe label element selectors work on (label 0 unless LabelAssertions.OnLabel was used); null when the job has no such label.
Labels { get; }IReadOnlyList<ComplianceLabel>The measured labels of the job (elements with bounds in dots, ink) for custom assertions.
ScanProof { get; }ScanProofReportThe scan-proof report of the job (every barcode decoded back, measured and graded).

Methods

Method SignatureReturnsDescription
# AllBarcodesDecode()LabelAssertionsEvery barcode decodes back to the data its field asks for (scan-proof, two independent decoders).
# AllBarcodesHaveGrade(char atLeast)LabelAssertionsEvery graded barcode reaches at least grade atLeast (A–D) in the digital pre-check.
# Barcode(string selector, int? index = default)BarcodeAssertionsSelects one barcode of the label (see ZplSelectors: "#0", "^BC", "QR", "GS1-128", "SSCC", "(01)", or a substring of the data). Fails when nothing or – without index – more than one barcode matches. selector: Which barcode. · index: Pick the n-th match (0-based) when several barcodes match.
# Barcode(Func<ComplianceBarcode, bool> predicate, string description = "")BarcodeAssertionsSelects the barcode that satisfies predicate (exactly one).
# Complies(CompliancePacks packs, ComplianceSeverity failOn = ComplianceSeverity.Error)LabelAssertionsRuns compliance rule packs and fails on findings of failOn or above (default errors).
# Complies(ComplianceRulePack pack, ComplianceSeverity failOn = ComplianceSeverity.Error)LabelAssertionsRuns compliance rule packs (built-in or custom) and fails on findings of failOn or above.
# DoesNotHaveText(string text)LabelAssertionsNo text field of the label contains text (e.g. "TODO", "{{", placeholder data).
# FieldEquals(int fieldNumber, string expected)LabelAssertionsThe field with ^FNfieldNumber prints expected.
# FieldEquals(string field, string expected)LabelAssertionsThe field "FN1" / "^FN1" / "1" prints expected (data as drawn, after ^FH, ^SN and field values).
# FitsPrinter(PrinterProfile profile, bool failOnWarnings = false)LabelAssertionsThe labels print correctly on the printer model of profile (Printer Twin: printhead width and clipped fields, maximum length, resolution, firmware, options, fonts, memory; see PrinterProfileFit). profile: A printer profile, e.g. PrinterProfiles.Get("ZD421-203"). · failOnWarnings: Also fail on issues of severity warning.
# FitsPrinter(IZplPrinterFit printer, bool failOnWarnings = false)LabelAssertionsThe labels fit printer: resolution, print width, label length – or whatever the implementation checks (see IZplPrinterFit, e.g. a Printer Twin profile). printer: Printer limits. · failOnWarnings: Also fail on issues of severity warning.
# HasBarcodes(int count)LabelAssertionsThe label has exactly count barcodes.
# HasLabels(int count)LabelAssertionsThe job prints exactly count label formats (^XA…^XZ; ^PQ copies count once).
# HasText(string text)LabelAssertionsSome text field of the label contains text.
# MatchesSnapshot(string name, double tolerancePercent)LabelAssertionsPixel snapshot with tolerancePercent % changed pixels allowed (see LabelAssertions.MatchesSnapshot).
# MatchesSnapshot(string name, SnapshotTolerance? tolerance = default)LabelAssertionsCompares the 1-bit render of every label with the approved snapshot name.approved.png (plus the semantic snapshot name.approved.json) in ZplAssertSettings.SnapshotDirectory next to the test file. On failure name.received.png and name.diff.png are written and the message lists the changed regions and elements ("text "FROM" moved +12 dots"). Accept with ZPLCORE_ACCEPT_SNAPSHOTS=1 or zplcore snapshot accept <dir>.
# NoClipping()LabelAssertionsEvery element lies completely on the label (nothing cut off at the ^PW/^LL edge).
# NoOverlaps(int toleranceDots = 0)LabelAssertionsNo two elements' ink overlaps (text over text, text over barcode, lines through text …). Outlined boxes count with their four sides only and reverse (^FR) fields never count, so framed and inverted designs pass. toleranceDots: Overlaps of at most this many dots in width or height are ignored (touching lines).
# OnLabel(int index)LabelAssertionsSwitches to label index (0-based, print order; ^PQ copies are not separate labels).
# Renders(int? dpi = default, ZplDiagnosticSeverity failOn = ZplDiagnosticSeverity.Warning)LabelAssertionsThe ZPL renders at least one label and without render diagnostics of failOn or above (default warnings: invalid barcode data, missing fonts and graphics, malformed commands). dpi: Renders at this resolution instead of the test resolution (e.g. to prove a 203 dpi label also works at 300 dpi). · failOn: Lowest severity that fails.
# Satisfies(Func<ComplianceLabel, bool> predicate, string because, string expression = "")LabelAssertionsCustom assertion on the current label.
# Text(string text, int? index = default)TextAssertionsSelects one text field (exact content, else substring, else substring ignoring case). Fails when nothing or – without index – more than one text matches.