public void Test_MonthIsInvalid() { ValidatorDate_MMDDYYYY validator = new ValidatorDate_MMDDYYYY(); string errorMsg; bool result = validator.ValidateField("99012015", out errorMsg); Assert.IsFalse(result); Assert.AreEqual(errorMsg, "Field is not a date: 99012015", "errorMsg is: " + errorMsg); }
public void Test_FieldIsTooShort() { ValidatorDate_MMDDYYYY validator = new ValidatorDate_MMDDYYYY(); string errorMsg; bool result = validator.ValidateField("120120", out errorMsg); Assert.IsFalse(result); Assert.AreEqual(errorMsg, "Field is not correct format (MMDDYYYY): 120120", "errorMsg is: " + errorMsg); }
public void Test_FieldContainsAlphaChars() { ValidatorDate_MMDDYYYY validator = new ValidatorDate_MMDDYYYY(); string errorMsg; bool result = validator.ValidateField("abcdefgh", out errorMsg); Assert.IsFalse(result); Assert.AreEqual(errorMsg, "Field is not a date: abcdefgh", "errorMsg is: " + errorMsg); }
public void Test_FieldIsMMDDYYYY() { ValidatorDate_MMDDYYYY validator = new ValidatorDate_MMDDYYYY(); string errorMsg; bool result = validator.ValidateField("12012015", out errorMsg); Assert.IsTrue(result); Assert.AreEqual(errorMsg, "", "errorMsg is: " + errorMsg); }
public Dictionary<int, List<IValidator>> GetValidators() { Dictionary<int, List<IValidator>> validators = new Dictionary<int, List<IValidator>>(); var section = (Hashtable)ConfigurationManager.GetSection("validators"); foreach (DictionaryEntry pair in section) { IValidator validator; int key = Int32.Parse(pair.Key.ToString()); string value = pair.Value.ToString(); switch (value) { case "ValidatorDateValidator_YYMMDD": validator = new ValidatorDate_YYMMDD(); break; case "ValidatorDateValidator_YYYYMMDD": validator = new ValidatorDate_YYYYMMDD(); break; case "ValidatorDateValidator_MMDDYYYY": validator = new ValidatorDate_MMDDYYYY(); break; case "ValidatorNumber": validator = new ValidatorNumber(); break; case "ValidatorNoNumbers": validator = new ValidatorNoNumbers(); break; case "ValidatorFieldIsNotBlank": validator = new ValidatorFieldIsNotBlank(); break; case "ValidatorCurrency": validator = new ValidatorCurrency(); break; default: validator = null; break; } if (value.Contains("ValidatorFieldLength_")) { string[] parts = value.Split('_'); int fieldLength = Int32.Parse(parts[1].ToString()); validator = new ValidatorFieldLength(fieldLength); } if (value.Contains("ValidatorMaxFieldLength")) { string[] parts = value.Split('_'); int maxFieldLength = Int32.Parse(parts[1].ToString()); validator = new ValidatorMaxFieldLength(maxFieldLength); } if (validator != null) { List<IValidator> validatorList; if (!validators.TryGetValue(key, out validatorList)) { validatorList = new List<IValidator>(); validators.Add(key, validatorList); } validatorList.Add(validator); } } return validators; }