示例#1
0
        private void GenerateWithFailingCanvas()
        {
            Bill          bill   = SampleData.CreateExample1();
            FailingCanvas canvas = new FailingCanvas();

            bill.Format.OutputSize = OutputSize.QrBillOnly;
            QRBill.Draw(bill, canvas);
        }
 private void GenerateAndCompareBill(Bill bill, GraphicsFormat graphicsFormat, SeparatorType separatorType,
                                     string expectedFileName)
 {
     bill.Format.GraphicsFormat = graphicsFormat;
     bill.Format.SeparatorType  = separatorType;
     byte[] imageData = QRBill.Generate(bill);
     FileComparison.AssertFileContentsEqual(imageData, expectedFileName);
 }
示例#3
0
        public void DecodeMissingEpd()
        {
            string invalidText            = SampleQRCodeText.CreateQrCodeText1(false).Replace("EPD", "E_P");
            QRBillValidationException err = Assert.Throws <QRBillValidationException>(
                () => QRBill.DecodeQrCodeText(invalidText));

            TestHelper.AssertSingleError(err.Result, ValidationConstants.KeyValidDataStructure, ValidationConstants.FieldTrailer);
        }
示例#4
0
        public void DecodeInvalidNumber()
        {
            string invalidText            = SampleQRCodeText.CreateQrCodeText1(false).Replace("3949.75", "1239d49.75");
            QRBillValidationException err = Assert.Throws <QRBillValidationException>(
                () => QRBill.DecodeQrCodeText(invalidText));

            TestHelper.AssertSingleError(err.Result, ValidationConstants.KeyValidNumber, ValidationConstants.FieldAmount);
        }
示例#5
0
 private Task GenerateAndCompareBill(Bill bill, OutputSize outputSize, GraphicsFormat graphicsFormat)
 {
     bill.Format.OutputSize     = outputSize;
     bill.Format.GraphicsFormat = graphicsFormat;
     bill.Format.FontFamily     = "Arial,\"Liberation Sans\"";
     byte[] imageData = QRBill.Generate(bill);
     return(VerifyImages.VerifyPng(imageData));
 }
 public void CreateTextError1()
 {
     Assert.Throws <QRBillValidationException>(() =>
     {
         Bill bill   = SampleData.CreateExample4();
         bill.Amount = -0.01m;
         QRBill.EncodeQrCodeText(bill);
     });
 }
示例#7
0
        public void CreateQrBillFrench()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            bill.Format.Language       = Language.FR;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_fr.svg");
        }
示例#8
0
        public void CreateQrBill5()
        {
            Bill bill = SampleData.CreateExample3();

            bill.Format.OutputSize     = OutputSize.QrBillWithHorizontalLine;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_ex5.svg");
        }
示例#9
0
        public void CreateQrBill4()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_ex4.svg");
        }
示例#10
0
        private void QrCodeAsSvg4()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize     = OutputSize.QrCodeOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrcode_ex4.svg");
        }
 private void CreateText5()
 {
     Assert.Throws <QRBillValidationException>(() =>
     {
         Bill bill   = SampleData.CreateExample4();
         bill.Amount = 0.0m;
         QRBill.EncodeQrCodeText(bill);
     });
 }
示例#12
0
        public Task CreateQrBillFrench()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            bill.Format.Language       = Language.FR;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
示例#13
0
        public Task CreateQrBill5()
        {
            Bill bill = SampleData.CreateExample3();

            bill.Format.OutputSize     = OutputSize.QrBillExtraSpace;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
示例#14
0
        public void PdfSaveAs()
        {
            Bill bill = SampleData.CreateExample4();

            using PDFCanvas canvas =
                      new PDFCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight);
            QRBill.Draw(bill, canvas);
            canvas.SaveAs("qrbill.pdf");
        }
示例#15
0
        public Task QrCodeAsSvg4()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize     = OutputSize.QrCodeOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
示例#16
0
        private static void GenerateWithInvalidData1()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Creditor.Name         = " ";
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.PDF;
            QRBill.Generate(bill);
        }
示例#17
0
        public void PngSaveAs()
        {
            Bill bill = SampleData.CreateExample6();

            using PNGCanvas canvas =
                      new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Helvetica, Arial, \"Liberation Sans\"");
            QRBill.Draw(bill, canvas);
            canvas.SaveAs("qrbill.png");
        }
示例#18
0
        public void TooFewLines()
        {
            Bill bill = SampleData.CreateExample2();

            bill.UnstructuredMessage = null;
            TestHelper.NormalizeSourceBill(bill);
            string qrText = QRBill.EncodeQrCodeText(bill);

            qrText = qrText[0..^ 5];
示例#19
0
        public void SvgSaveAs()
        {
            Bill bill = SampleData.CreateExample2();

            using SVGCanvas canvas =
                      new SVGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Helvetica, Arial, Sans");
            QRBill.Draw(bill, canvas);
            canvas.SaveAs("qrbill.svg");
        }
示例#20
0
        private void PrintQRBill(PrintPageEventArgs e)
        {
            // ouput size for QR bill: 210 x 297mm
            bill.Format.OutputSize = OutputSize.A4PortraitSheet;

            // print QR bill at bottom of page
            e.Graphics.PageUnit = GraphicsUnit.Millimeter;
            using SystemDrawingCanvas canvas = new SystemDrawingCanvas(e.Graphics, 0, 297, 1, "Arial");
            QRBill.Draw(bill, canvas);
        }
示例#21
0
        public void DecodeTextB2()
        {
            Bill bill = SampleQRCodeText.CreateBillData2();

            TestHelper.NormalizeSourceBill(bill);
            Bill bill2 = QRBill.DecodeQrCodeText(SampleQRCodeText.CreateQrCodeText2(false));

            TestHelper.NormalizeDecodedBill(bill2);
            Assert.Equal(bill, bill2);
        }
示例#22
0
        public void DecodeText3()
        {
            Bill bill = SampleData.CreateExample3();

            TestHelper.NormalizeSourceBill(bill);
            Bill bill2 = QRBill.DecodeQrCodeText(QRBill.EncodeQrCodeText(bill));

            TestHelper.NormalizeDecodedBill(bill2);
            Assert.Equal(bill, bill2);
        }
示例#23
0
        public void DecodeInvalidRefType()
        {
            Bill   bill   = SampleData.CreateExample3();
            string qrText = QRBill.EncodeQrCodeText(bill);

            qrText = qrText.Replace("SCOR", "XXXX");
            Bill bill2 = QRBill.DecodeQrCodeText(qrText);

            Assert.Equal("XXXX", bill2.ReferenceType);
        }
        private void DecodeTextB1B()
        {
            Bill bill = SampleQRCodeText.CreateBillData1();

            TestHelper.NormalizeSourceBill(bill);
            Bill bill2 = QRBill.DecodeQrCodeText(SampleQRCodeText.CreateQrCodeText1(true));

            TestHelper.NormalizeDecodedBill(bill2);
            Assert.Equal(bill, bill2);
        }
示例#25
0
        public void WithAlternativeSchemes()
        {
            Bill bill = SampleData.CreateExample1();

            TestHelper.NormalizeSourceBill(bill);
            Bill bill2 = QRBill.DecodeQrCodeText(QRBill.EncodeQrCodeText(bill) + "\n");

            TestHelper.NormalizeDecodedBill(bill2);
            Assert.Equal(bill, bill2);
        }
        private void DecodeTextB1A()
        {
            Bill bill = SampleQRCodeText.CreateBillData1();

            NormalizeSourceBill(bill);
            Bill bill2 = QRBill.DecodeQrCodeText(SampleQRCodeText.CreateQrCodeText1(false));

            NormalizeDecodedBill(bill2);
            Assert.Equal(bill, bill2);
        }
        private void DecodeText2()
        {
            Bill bill = SampleData.CreateExample2();

            NormalizeSourceBill(bill);
            Bill bill2 = QRBill.DecodeQrCodeText(QRBill.EncodeQrCodeText(bill));

            NormalizeDecodedBill(bill2);
            Assert.Equal(bill, bill2);
        }
示例#28
0
        public Task SvgWithChallengingCharacters()
        {
            Bill bill = SampleData.CreateExample1();

            bill.UnstructuredMessage   = "<h1>&&\"ff\"'t'";
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
        public void CreateTextEmptyReference()
        {
            Bill             bill   = SampleQRCodeText.CreateBillData3();
            ValidationResult result = QRBill.Validate(bill);

            Assert.False(result.HasErrors);
            bill           = result.CleanedBill;
            bill.Reference = "";
            Assert.Equal(SampleQRCodeText.CreateQrCodeText3(false), QRBill.EncodeQrCodeText(bill));
        }
示例#30
0
        private static void GenerateWithInvalidData3()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Reference             = "RF1234";
            bill.Currency              = "XXX";
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.PDF;
            QRBill.Generate(bill);
        }