public void ValidateAgeIsOver21True()
        {
            // Valid: Must be over 21
            DateTime dateTime = new DateTime(1992, 8, 18);
            Boolean  result   = TeacherValidationHelper.IsOverAgeTwentyOne(dateTime);

            Assert.IsTrue(result);
        }
Ejemplo n.º 2
0
        public override void ValidateProperty(string propertyName)
        {
            string error = "";

            switch (propertyName)
            {
            case "Surname":
                if (!TeacherValidationHelper.IsValidNameFormat(Surname))
                {
                    error = TeacherValidationHelper.ERROR_SURNAME_FORMAT;
                }
                break;

            case "Forename":
                if (!TeacherValidationHelper.IsValidNameFormat(Forename))
                {
                    error = TeacherValidationHelper.ERROR_FORNAME_FORMAT;
                }
                break;

            case "DOB":
                if (DOB == DateTime.Today)
                {
                    error = TeacherValidationHelper.ERROR_EMPTY_STRING;
                }
                else if (DOB > DateTime.Today)
                {
                    error = TeacherValidationHelper.ERROR_AGE_NOTFUTURE;
                }
                else if (!TeacherValidationHelper.IsOverAgeTwentyOne(DOB))
                {
                    error = TeacherValidationHelper.ERROR_AGE_NOTOVERAGE;
                }
                break;

            case "Phone":
                if (!TeacherValidationHelper.IsValidPhoneFormat(Phone))
                {
                    error = TeacherValidationHelper.ERROR_PHONE_FORMAT;
                }
                break;

            case "Type":
                if (Type == ' ')
                {
                    error = TeacherValidationHelper.ERROR_EMPTY_STRING;
                }
                break;

            case "Subjects":
                if (String.IsNullOrEmpty(Subjects))
                {
                    error = TeacherValidationHelper.ERROR_EMPTY_STRING;
                }
                break;
            }

            if (error != "")
            {
                AddErrors(propertyName, error);
            }
            else
            {
                RemoveErrors(propertyName);
            }
        }