public void Test_MonthIsInvalid()
        {
            ValidatorDate_YYMMDD validator = new ValidatorDate_YYMMDD();

            string errorMsg;

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

            Assert.IsFalse(result);
            Assert.AreEqual(errorMsg, "Field is not a date: 153007", "errorMsg is: " + errorMsg);
        }
        public void Test_FieldIsTooShort()
        {
            ValidatorDate_YYMMDD validator = new ValidatorDate_YYMMDD();

            string errorMsg;

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

            Assert.IsFalse(result);
            Assert.AreEqual(errorMsg, "Field is not correct format (YYMMDD): 15100", "errorMsg is: " + errorMsg);
        }
        public void Test_FieldIsYYMMDD()
        {
            ValidatorDate_YYMMDD validator = new ValidatorDate_YYMMDD();

            string errorMsg;

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

            Assert.IsTrue(result);
            Assert.AreEqual(errorMsg, "", "errorMsg is: " + errorMsg);
        }
        public void Test_FieldContainsAlphaChars()
        {
            ValidatorDate_YYMMDD validator = new ValidatorDate_YYMMDD();

            string errorMsg;

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

            Assert.IsFalse(result);
            Assert.AreEqual(errorMsg, "Field is not a date: abcdef", "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;
        }