public void Test_FieldIs8_TooShort()
        {
            ValidatorFieldLength validator = new ValidatorFieldLength(8);

            string errorMsg;

            bool result = validator.ValidateField("1234567", out errorMsg);

            Assert.IsFalse(result);
            Assert.AreEqual(errorMsg, "Field is not correct length (expected 8): 1234567", "errorMsg is: " + errorMsg);
        }
        public void Test_FieldIs8_Pass()
        {
            ValidatorFieldLength validator = new ValidatorFieldLength(8);

            string errorMsg;

            bool result = validator.ValidateField("12345678", 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;
        }