Exemplo n.º 1
0
        public void TestInputParamsValidation(string text, QRCodeEncodingMethod encoding, int correction, int version,
                                              int scaleMultiplier, bool shouldThrowArgumentException, bool shouldThrowArgumentOutOfRangeException, string caseName)
        {
            var colorForeground = Color.FromArgb(255, 5, 80, 205);
            var colorBackground = Color.FromArgb(255, 200, 255, 254);

            if (shouldThrowArgumentException)
            {
                ((Action)call).Should().ThrowExactly <ArgumentException>();
            }
            else if (shouldThrowArgumentOutOfRangeException)
            {
                ((Action)call).Should().ThrowExactly <ArgumentOutOfRangeException>();
            }
            else
            {
                call();
            }

            Assert.True(true, caseName);

            void call()
            {
                BarcodesMaker.GetQRCode(text, encoding, (QRCodeErrorCorrection)correction, (QRCodeVersion)version, scaleMultiplier,
                                        colorForeground, colorBackground);
            }
        }
        public void QuickStart_BarcodeQRCode()
        {
            byte[] dataQR = BarcodesMaker.GetQRCode("QRCode example",
                                                    QRCodeEncodingMethod.Binary,
                                                    QRCodeErrorCorrection.M,
                                                    8);
            using (Image image = Image.FromStream(new MemoryStream(dataQR)))
            {
                image.Save("QRCode.png", System.Drawing.Imaging.ImageFormat.Png);
            }

            FileComparer.AreEqual("etalon_QRCode.png", "QRCode.png").Should().Be(true);
        }
Exemplo n.º 3
0
        public void TestSetupColorsForQRCode()
        {
            var colorForeground = Color.FromArgb(255, 5, 80, 205);
            var colorBackground = Color.FromArgb(255, 200, 255, 254);

            byte[] data = BarcodesMaker.GetQRCode("test", QRCodeEncodingMethod.Binary, QRCodeErrorCorrection.M, QRCodeVersion.Version1,
                                                  1, colorForeground, colorBackground);

            using (var memStream = new MemoryStream(data))
                using (var bitmap = new Bitmap(memStream))
                {
                    bitmap.GetPixel(0, 0).Should().BeEquivalentTo(colorBackground);
                    bitmap.GetPixel(4, 4).Should().BeEquivalentTo(colorForeground);
                }
        }
Exemplo n.º 4
0
        public void TestVersionsOfQRCode()
        {
            for (int version = 1; version <= 40; version++)
            {
                // Method 1
                byte[] data = BarcodesMaker.GetQRCode("test", QRCodeEncodingMethod.Binary,
                                                      QRCodeErrorCorrection.M, (QRCodeVersion)version);
                string hash = CalculateImageCanvasHash(data);
                hash.Should().Be(QRCodesTestData.HashSHA2[version]);

                // Method 2
                data = BarcodesMaker.GetQRCode("test", QRCodeEncodingMethod.Binary, QRCodeErrorCorrection.M,
                                               (QRCodeVersion)version, 1, Color.Black, Color.White);
                hash = CalculateImageCanvasHash(data);
                hash.Should().Be(QRCodesTestData.HashSHA2[version]);
            }
        }
Exemplo n.º 5
0
        public void TestErrorCorrectionOfQRCode(QRCodeErrorCorrection correctionLevel, string expectedHash,
                                                string caseName)
        {
            // Method 1
            byte[] data = BarcodesMaker.GetQRCode("test", QRCodeEncodingMethod.Binary, correctionLevel, 1);
            string hash = CalculateImageCanvasHash(data);

            hash.Should().Be(expectedHash);

            // Method 2
            data = BarcodesMaker.GetQRCode("test", QRCodeEncodingMethod.Binary, correctionLevel, QRCodeVersion.Version1, 1,
                                           Color.Black, Color.White);
            hash = CalculateImageCanvasHash(data);
            hash.Should().Be(expectedHash);

            Assert.True(true, caseName);
        }
Exemplo n.º 6
0
        public void TestAutoSelectVersionsOfQRCode(string text, string hashExpected, bool isMethod2, string caseName)
        {
            byte[] data = new byte[0];
            if (isMethod2)
            {
                data = BarcodesMaker.GetQRCode(text, QRCodeEncodingMethod.Binary,
                                               QRCodeErrorCorrection.M);
            }
            else
            {
                data = BarcodesMaker.GetQRCode(text, QRCodeEncodingMethod.Binary,
                                               QRCodeErrorCorrection.M, 1, Color.Black, Color.White);
            }
            string hash = CalculateImageCanvasHash(data);

            hash.Should().Be(hashExpected);
            Assert.True(true, caseName);
        }