Exemplo n.º 1
0
 public void IsStudentNameValidTest()
 {
     Assert.AreEqual((false, "Missing student name type!"), StudentValidation.IsStudentNameValid("Carlos", null));
     Assert.AreEqual((false, "Missing student first name!"), StudentValidation.IsStudentNameValid(null, "first name"));
     Assert.AreEqual((false, "Invalid student name type!"), StudentValidation.IsStudentNameValid("Tyler", "forename"));
     Assert.AreEqual((false, "Invalid student first name, no special or numeric characters allowed!"), StudentValidation.IsStudentNameValid("Martin/James", "first name"));
     Assert.AreEqual((false, "Invalid student first name!"), StudentValidation.IsStudentNameValid("Ryan--Mark", "first name"));
     Assert.AreEqual((true, ""), StudentValidation.IsStudentNameValid("Stuart", "first name"));
 }
Exemplo n.º 2
0
        // Custom Constructor.

        /**
         * <summary>This custom constructor is responsible for creating a Student object.</summary>
         *
         * <param name="ID">A student's unique 4-digit ID number.</param>
         * <param name="f_name">A student's first name.</param>
         * <param name="l_name">A student's last name.</param>
         * <param name="year">A student's current school year.</param>
         * <param name="clName">A student's class name.</param>
         *
         * <example>
         * <code>Student sd = new Student("0007", "John", "Smith", 9, "Grey");</code>
         * This creates a Student object with the ID value as "0007", first name as "John", last name as "Smith", school year as '9' and class name as "Grey".
         * </example>
         */
        public Student(string ID, string f_name, string l_name, int year, string clName)
        {
            if (!StudentValidation.IsStudentIDValid(year, ID).Item1)
            {
                // Throws an exception with a message dependent on what invalidates the student ID.
                throw new ArgumentException(StudentValidation.IsStudentIDValid(year, ID).Item2);
            }
            else
            {
                GetStudentID = ID;
            }

            if (!StudentValidation.IsStudentNameValid(f_name, "first name").Item1)
            {
                // Throws an exception with a message dependent on what invalidates the student's first name.
                throw new ArgumentException(StudentValidation.IsStudentNameValid(f_name, "first name").Item2);
            }
            else
            {
                GetForename = f_name;
            }

            if (!StudentValidation.IsStudentNameValid(l_name, "last name").Item1)
            {
                // Throws an exception with a message dependent on what invalidates the student's last name.
                throw new ArgumentException(StudentValidation.IsStudentNameValid(l_name, "last name").Item2);
            }
            else
            {
                GetSurname = l_name;
            }

            if (year > 13 || year < 1)
            {
                // Throws an exception if 'year' is equal to a value less than 1 or greater than 13.
                throw new ArgumentException("Invalid academic year, only 1 - 13 are allowed!");
            }
            else
            {
                GetYear = year;
            }

            if (string.IsNullOrWhiteSpace(clName))
            {
                // Throws an exception if the 'clname' string is null, empty or only contains whitespaces.
                throw new ArgumentException("Missing student class name!");
            }
            else
            {
                bool notLetter = false;

                foreach (char c in clName)
                {
                    if (!char.IsLetter(c))
                    {
                        notLetter = true;
                    }
                }

                if (notLetter)
                {
                    // Throws an exception if the 'clname' string contains a disallowed character.
                    throw new ArgumentException("Invalid student class name, no special or numeric characters allowed!");
                }
                else
                {
                    GetClassName = clName;
                }
            }

            // Creates an empty list to be populated by subjects studied by the student.
            GetSubjects = new List <Subject>();

            // Sets the unique file path for the student.
            GetFilePath = "C:/Users/Student Results/Year " + GetYear + "/" + GetFullName + ".txt";
        }