Ejemplo n.º 1
0
        public void Encode_InvalidNumberSystem_ShouldThrowException()
        {
            Action action = () => UpcEEncoder.Encode("654321", (UpcENumberSystem)2);

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Only number systems 0 and 1 are supported by UPC E");
        }
Ejemplo n.º 2
0
        public void Encode_InvalidContentLength_ShouldThrowException()
        {
            Action action = () => UpcEEncoder.Encode("123", UpcENumberSystem.Zero);

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Invalid content length. Should be 6");

            Action action2 = () => UpcEEncoder.Encode("123", UpcENumberSystem.One);

            action2.Should().Throw <InvalidOperationException>()
            .WithMessage("Invalid content length. Should be 6");
        }
Ejemplo n.º 3
0
        public void Encode_InvalidCode_ShouldThrowException()
        {
            Action action = () => UpcEEncoder.Encode("invalid", UpcENumberSystem.Zero);

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Can only encode numerical digits (0-9)");

            Action action2 = () => UpcEEncoder.Encode("invalid", UpcENumberSystem.One);

            action2.Should().Throw <InvalidOperationException>()
            .WithMessage("Can only encode numerical digits (0-9)");
        }
Ejemplo n.º 4
0
        public void Encode(string testCode, UpcENumberSystem numberSystem, string testResult, string kind)
        {
            IBarcode code = UpcEEncoder.Encode(testCode, numberSystem);

            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);
        }