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); } }
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); } }
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); } }
public void Test12() { string xml = @" <collection> <validator location='海淀分馆' > <patron> <CMIS /> <range value='P000001-P999999' /> </patron> <entity> <range value='0000001-9999999' transform='barcode+"tail1"'></range> </entity> <transform> barcode+'tail2' </transform> </validator> </collection>"; BarcodeValidator validator = new BarcodeValidator(xml); { var result = validator.Validate("海淀分馆", "0000001"); Assert.AreEqual(false, result.OK); Assert.AreEqual(null, result.Type); } }
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 Test11() { string xml = @" <collection> <validator location='海淀分馆' > <patron> <CMIS /> <range value='P000001-P999999' /> </patron> <entity> <range value='0000001-9999999' transform='barcode+"tail"'></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); } }
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); } }
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); }
// 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); } }
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); } }
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); } }
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); } }
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); } } }