public void IsSchoolNameValidTest()
 {
     Assert.AreEqual((false, "Missing value for school name!"), SchoolValidation.IsSchoolNameValid("  "));
     Assert.AreEqual((false, "Invalid school name, no special or numeric characters allowed!"), SchoolValidation.IsSchoolNameValid("Spring-well"));
     Assert.AreEqual((false, "Invalid school name!"), SchoolValidation.IsSchoolNameValid("Spring  well"));
     Assert.AreEqual((true, ""), SchoolValidation.IsSchoolNameValid("Springwell"));
 }
Example #2
0
        // Custom Constructor 2.

        /**
         * <summary>This alternate custom constructor is responsible for creating a School object.</summary>
         *
         * <param name="name">The school name.</param>
         * <param name="first">The lowest school year.</param>
         * <param name="last">The highest school year</param>
         *
         * <example>
         * <code>School sl = new School("Earlmount High", 7, 11);</code>
         * This creates a School object with name as "Earlmount High", with years 7 to 11.</example>
         */
        public School(string name, int first, int last)
        {
            if (!SchoolValidation.IsSchoolNameValid(name).Item1)
            {
                // Throws an exception with a message dependent on what invalidates the school's name.
                throw new ArgumentException(SchoolValidation.IsSchoolNameValid(name).Item2);
            }
            else
            {
                GetSchoolName = name;
            }

            if (first >= last)
            {
                // Throws an exception if the first academic year is greater than or equal to the last academic year.
                throw new ArgumentException("First academic year can not be greater than or equal to last academic year!");
            }
            else if (first < 1 || first > 12)
            {
                // Throws an exception if the first academic year is less than 1 or greater than 12.
                throw new ArgumentException("First academic year can not be less than 1 or greater than 12!");
            }
            else if (last < 2 || last > 13)
            {
                // Throws an exception if the last academic year is less than 2 or greater than 13.
                throw new ArgumentException("Last academic year can not be less than 2 or greater than 13!");
            }
            else
            {
                // Creates an empty list to be populated by years within a school.
                GetYears = new List <AcademicYear>();
                // Adds a range of years to the School object.
                AddYears(first, last);
            }
        }
Example #3
0
        // Custom Constructor.

        /**
         * <summary>This custom constructor is responsible for creating a School object.</summary>
         *
         * <param name="name">The school name.</param>
         * <param name="year">The year number.</param>
         *
         * <example>
         * <code>School sl = new School("Portsborough Secondary", 8);</code>
         * This creates a School object with the name as "Portsborough Secondary" and  year as '8'.</example>
         */
        public School(string name, int year)
        {
            if (!SchoolValidation.IsSchoolNameValid(name).Item1)
            {
                // Throws an exception with a message dependent on what invalidates the school's name.
                throw new ArgumentException(SchoolValidation.IsSchoolNameValid(name).Item2);
            }
            else
            {
                GetSchoolName = name;
            }

            if (year < 1 || year > 13)
            {
                // Throws an exception if the year number is less than 1 or greater than 13.
                throw new ArgumentException("Academic year is outside the valid range (1 - 13)!");
            }
            else
            {
                // Creates an empty list to be populated by years within a school.
                GetYears = new List <AcademicYear>();
                // Adds the AcademicYear object to the School object.
                AddYear(new AcademicYear(year));
            }
        }
        public void StringToInt()
        {
            //Arrange
            string text = "5";
            int    integer;

            //Act
            SchoolValidation.StringToInt(text, out integer);

            //Assert
            Assert.AreEqual(5, integer);
        }
Example #5
0
        private void btnFindStudent_Click(object sender, RoutedEventArgs e)
        {
            int studentID = 0;

            if (SchoolValidation.StringToInt(txtStudentFind.Text, out studentID))
            {
                if (StudentDB.IsValidStudentID(studentID))
                {
                    EFStudent student = schoolData.EFStudents.Where(s => s.StudentID == studentID).Single();
                    oldStudent                 = student;
                    txtFirstName.Text          = student.First_Name.Trim();
                    txtLastName.Text           = student.Last_Name.Trim();
                    txtAddress.Text            = student.Address.Trim();
                    txtZip.Text                = student.ZipCode.ToString();
                    cboStates.SelectedValue    = student.StateCode;
                    lblStudentFullName.Content = student.First_Name.Trim() + " " + student.Last_Name.Trim();
                    lblStudentID.Content       = studentID.ToString();
                    if (student.Photo != null)
                    {
                        StringtoImage(student.Photo.Trim());
                    }
                    else
                    {
                        StringtoImage("http://i882.photobucket.com/albums/ac22/CoreySanders/noImage_zpsctmad3nk.png");
                    }
                    ToggleEditMode();
                }
                else
                {
                    MessageBox.Show("Is not a valid student");
                }
            }
            else
            {
                MessageBox.Show("Please insert a valid student id (number between 0 - 1000000)");
            }
        }