Ejemplo n.º 1
0
        public void Encode_InvalidContentLength_ShouldThrowException()
        {
            Action action = () => EanEncoder.Encode("123");

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Invalid content length. Should be 7 or 12 if the code does not include a checksum, 8 or 13 if the code already includes a checksum");
        }
Ejemplo n.º 2
0
        public void Encode_InvalidCode_ShouldThrowException()
        {
            Action action = () => EanEncoder.Encode("invalid");

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Can only encode numerical digits (0-9)");
        }
Ejemplo n.º 3
0
        public void Encode_InvalidChecksum_ShouldThrowException()
        {
            Action action = () => EanEncoder.Encode("55123458");

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Checksum mismatch");
        }
Ejemplo n.º 4
0
        public void Render_Ean13_IncludeContentAsText()
        {
            var      renderer = new ImageRenderer(imageFormat: ImageFormat.Png, includeEanContentAsText: true);
            IBarcode barcode  = EanEncoder.Encode("978020137962");

            using Stream stream = File.OpenWrite(@"d:\temp\ean-test.png");
            renderer.Render(barcode, stream);
        }
Ejemplo n.º 5
0
        public void Render_Ean8_IncludeContentAsText()
        {
            var      renderer = new SvgRenderer(includeEanContentAsText: true);
            IBarcode barcode  = EanEncoder.Encode("1234567");

            using Stream stream = File.OpenWrite(@"d:\temp\ean-test.svg");
            renderer.Render(barcode, stream);
        }
Ejemplo n.º 6
0
        public void Encode(string testCode, string testResult, string kind, bool checkContent)
        {
            IBarcodeIntCS code = EanEncoder.Encode(testCode);

            if (checkContent)
            {
                code.Content.Should().Be(testCode);
            }

            code.Bounds.X.Should().Be(testResult.Length);
            code.Bounds.Y.Should().Be(1);
            code.Metadata.CodeKind.Should().Be(kind);
            code.Metadata.Dimensions.Should().Be(1);

            string encoded = string.Empty;
            int    i       = 0;

            foreach (var r in testResult)
            {
                encoded += code.At(i++, 0) ? "1" : "0";
            }
            encoded.Should().Be(testResult);
        }
Ejemplo n.º 7
0
 public void UpcaValidate(string input, string expected)
 {
     Assert.Equal(expected, EanEncoder.Validate(input, 12));
 }
Ejemplo n.º 8
0
 public void EanCheckDigit(string input, string expected)
 {
     Assert.Equal(expected, EanEncoder.CheckDigit(input));
 }