示例#1
0
        public void Test_suppress_3()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆'>
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
           <validator location='西城分馆' suppress=''>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("西城分馆", "0000001");
                Assert.AreEqual(false, result.OK);
                Assert.AreEqual("suppressed", result.ErrorCode);
                Assert.AreEqual("馆藏地 '西城分馆' 不打算定义验证规则", result.ErrorInfo);

                Assert.AreEqual(null, result.Type);
            }
        }
示例#2
0
        public void Test13()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
               <transform>
                    barcode----'tail'
               </transform>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("海淀分馆", "0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual(null, result.ErrorCode);

                Assert.AreEqual("entity", result.Type);
            }
        }
示例#3
0
        public void Test12_transform()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999' transform='barcode+&quot;tail1&quot;'></range>
               </entity>
               <transform>
                    barcode+'tail2'
               </transform>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Transform("海淀分馆", "0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
                Assert.AreEqual("0000001tail1", result.TransformedBarcode);
                Assert.AreEqual(true, result.Transformed);
            }
        }
示例#4
0
        public void Test14_transform()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Transform("海淀分馆", "T0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("notMatch", result.ErrorCode);

                Assert.AreEqual(null, result.Type);
                Assert.AreEqual(null, result.TransformedBarcode);
                Assert.AreEqual(false, result.Transformed);
            }
        }
示例#5
0
        public void TestNeedValidation05()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999' transform='barcode+&quot;tail&quot;'></range>
               </entity>
               <transform>
                    barcode+'tail'
               </transform>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.NeedValidate("海淀分馆");
                Assert.AreEqual(true, result);
            }
        }
示例#6
0
        public void Test_sample_01()
        {
            string xml = @"
        <collection>
    <validator location='南开区中营瑞丽小学,南开区中营瑞丽小学/*'>
        <patron>
            <CMIS />
            <range value='ZYRLP00001-ZYRLP99999' />
        </patron>
        <entity>
            <range value='ZYRL000001-ZYRL999999' />
        </entity>
    </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("南开区中营瑞丽小学", "ZYRL000010");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }

            {
                var result = validator.Validate("南开区中营瑞丽小学", "ZYRL000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }

            {
                var result = validator.Validate("南开区中营瑞丽小学", "ZYRL000009");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }
        }
示例#7
0
        public void Test11()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999' transform='barcode+&quot;tail&quot;'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("海淀分馆", "0000001");
                Assert.AreEqual(result.OK, true);
                Assert.AreEqual(result.Type, "entity");
                Assert.AreEqual(result.TransformedBarcode, "0000001tail");
                Assert.AreEqual(result.Transformed, true);
            }
        }
示例#8
0
        public void Test03()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' transform='...' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("海淀分馆", "P0000001");
                Assert.AreEqual(result.OK, false);
                Assert.AreEqual(result.ErrorCode, "notMatch");
                Assert.AreEqual(result.TransformedBarcode, null);
                Assert.AreEqual(result.Transformed, false);
            }
        }
        public void IsNotValidWhenBarcodeIsNotValid()
        {
            validator = new BarcodeValidator(null, "invalid");

            validator.Validate();

            Assert.False(validator.IsValid);
        }
        public void IsValidWhenBarcodeIsValid()
        {
            validator = new BarcodeValidator(null, "AB123:1");

            validator.Validate();

            Assert.True(validator.IsValid);
        }
示例#11
0
        public void Test03()
        {
            string xml = @"
        <collection>
           <validator location='北院???,北院书库1' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            // 字符数不够,匹配不上
            {
                var result = validator.Validate("北院", "0000001");
                Assert.AreEqual(false, result.OK);
                Assert.AreEqual(null, result.Type);
            }

            // 直接匹配
            {
                var result = validator.Validate("北院书库1", "0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }

            // 这个应该匹配不上
            {
                var result = validator.Validate("南院书库", "0000001");
                Assert.AreEqual(false, result.OK);
                Assert.AreEqual(null, result.Type);
            }

            // 前方一致匹配
            {
                var result = validator.Validate("北院其他库", "0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }

            // 前方一致匹配
            {
                var result = validator.Validate("北院阅览室", "0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }
        }
示例#12
0
        public void Test_pattern_02()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                    <!-- 读者证条码规则 -->
                   <range value='00000001-99999999' pattern='[0][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z]'/>
               </patron>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("海淀分馆", "0ABCEFGA");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("patron", result.Type);
            }
        }
示例#13
0
        //  Verify that barcode object has valid information before committing to the database.
        private bool ValidateBarcodeInformation()
        {
            // Validate my data and save in the results variable
            BarcodeValidator barcodeValidator = new BarcodeValidator();
            var results = barcodeValidator.Validate(this.barcode);

            // Check if the validator found any validation errors.
            if (results.IsValid == false)
            {
                foreach (ValidationFailure failure in results.Errors)
                {
                    MessageBox.Show($"{ failure.ErrorMessage }", "Product Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#14
0
        public void TestNeedValidation01()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.NeedValidate("西城分馆");
                Assert.AreEqual(false, result);
            }
        }
示例#15
0
        public void Test04()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' transform='...' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("海淀分馆1", "P0000001");
                Assert.AreEqual(false, result.OK);
                Assert.AreEqual("locationDefNotFound", result.ErrorCode);
            }
        }
示例#16
0
        public void Test02()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("海淀分馆", "P000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("patron", result.Type);
            }
        }
示例#17
0
        public void Test18_transform()
        {
            string xml = @"
<barcodeValidation>
    <validator location='第三中学'>
        <patron>
            <CMIS />
            <range value='T000001-T999999' />
            <range value='000001-999999' transform='result=&quot;T&quot;+barcode ;' />
        </patron>
        <entity>
            <range value='SZ001-SZ999' />
            <range value='Z001-Z999' transform='result= &quot;S&quot; + barcode ;' />
        </entity>
        <transform>
	        if (barcode.length == 4)
	            result = 'Z' + barcode;
            else if (barcode.length == 5)
                result = barcode;
            else
	            message = '待变换的输入条码号 \''+barcode+'\' 长度不对';
        </transform>
    </validator>
</barcodeValidation>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Transform("第三中学", "A0001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual(null, result.ErrorCode);

                Assert.AreEqual(null, result.Type);
                Assert.AreEqual("A0001", result.TransformedBarcode);
                Assert.AreEqual(true, result.Transformed);
            }
        }
示例#18
0
        public void Test01()
        {
            string xml = @"
        <collection>
           <validator location='海淀分馆,海淀分馆/阅览室1' >
               <patron>
                   <CMIS />
                   <range value='P000001-P999999' />
               </patron>
               <entity>
                   <range value='0000001-9999999'></range>
               </entity>
           </validator>
        </collection>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Validate("海淀分馆", "0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }

            {
                var result = validator.Validate("海淀分馆/阅览室1", "0000001");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("entity", result.Type);
            }

            // 这个应该匹配不上
            {
                var result = validator.Validate("海淀分馆/阅览室", "0000001");
                Assert.AreEqual(false, result.OK);
                Assert.AreEqual(null, result.Type);
            }

            // https://stackoverflow.com/questions/933613/how-do-i-use-assert-to-verify-that-an-exception-has-been-thrown
            // location 中使用模式会抛出异常
            {
                try
                {
                    var result = validator.Validate("海淀分馆/阅览室*", "0000001");
                    Assert.Fail("这里本应抛出异常 ArgumentException");
                }
                catch (Exception ex)
                {
                    Assert.IsTrue(ex is ArgumentException);
                }
            }


            // location 中使用模式会抛出异常
            {
                try
                {
                    var result = validator.Validate("海淀分馆/阅*", "0000001");
                    Assert.Fail("这里本应抛出异常 ArgumentException");
                }
                catch (Exception ex)
                {
                    Assert.IsTrue(ex is ArgumentException);
                }
            }
        }
示例#19
0
        public void Test04()
        {
            string xml = @"
<barcodeValidation>
    <validator location=''>
        <patron>
            <CMIS />
            <range value='000001-009999' />
            <range value='P000001-P999999' />
        </patron>
        <entity>
            <range value='00000001-00999999' />
            <range value='20000001-20999999' />
            <range value='Z00001-Z99999' />
        </entity>
    </validator>
    <validator location='北院*'>
        <patron>
            <CMIS />
            <range value='N0000-N9999' />
            <range value='DZ0000-DZ9999' />
        </patron>
        <entity>
            <range value='BY200000000-BY999999999' />
            <range value='200000000-999999999' transform='result= &quot;BY&quot; + barcode ;' />
        </entity>
    </validator>
    <validator location='中院*'>
        <patron>
            <CMIS />
            <range value='N0000-N9999' />
            <range value='DZ0000-DZ9999' />
        </patron>
        <entity>
            <range value='ZY200000000-ZY999999999' />
            <range value='200000000-999999999' transform='result= &quot;ZY&quot; + barcode ;' />
        </entity>
    </validator>
    <validator location='南院*'>
        <patron>
            <CMIS />
            <range value='N0000-N9999' />
            <range value='DZ0000-DZ9999' />
        </patron>
        <entity>
            <range value='NY200000000-NY999999999' />
            <range value='200000000-999999999' transform='result= &quot;NY&quot; + barcode ;' />
        </entity>
    </validator>
</barcodeValidation>";

            BarcodeValidator validator = new BarcodeValidator(xml);

            {
                var result = validator.Transform("北院", "N9999");
                Assert.AreEqual(true, result.OK);
                Assert.AreEqual("patron", result.Type);
                Assert.AreEqual(false, result.Transformed);
                Assert.AreEqual(null, result.TransformedBarcode);
            }

            /*
             * // 直接匹配
             * {
             *  var result = validator.Validate("北院书库1", "0000001");
             *  Assert.AreEqual(true, result.OK);
             *  Assert.AreEqual("entity", result.Type);
             * }
             *
             * // 这个应该匹配不上
             * {
             *  var result = validator.Validate("南院书库", "0000001");
             *  Assert.AreEqual(false, result.OK);
             *  Assert.AreEqual(null, result.Type);
             * }
             *
             * // 前方一致匹配
             * {
             *  var result = validator.Validate("北院其他库", "0000001");
             *  Assert.AreEqual(true, result.OK);
             *  Assert.AreEqual("entity", result.Type);
             * }
             *
             * // 前方一致匹配
             * {
             *  var result = validator.Validate("北院阅览室", "0000001");
             *  Assert.AreEqual(true, result.OK);
             *  Assert.AreEqual("entity", result.Type);
             * }
             */
        }
 internal void Generate(string barcodeValue)
 {
     EncodedValue = BarcodeValidator.Parse(barcodeValue, Symbology);
     Encode(EncodedValue);
 }
 /// <summary>
 /// Get the generated barcode as a bitmap image.
 /// </summary>
 /// <param name="barcodeValue"></param>
 /// <returns>Barcode image</returns>
 internal MemoryStream GetImage(string barcodeValue)
 {
     LinearEncoding.Clear();
     Encode(BarcodeValidator.Parse(barcodeValue, Symbology));
     return(LinearRenderer.DrawImageMemoryStream(this));
 }