public void IsSubjectNameValidTest()
 {
     Assert.AreEqual((false, "Missing subject name!"), SubjectValidation.IsSubjectNameValid(""));
     Assert.AreEqual((false, "Invalid subject name, no special or numeric characters allowed!"), SubjectValidation.IsSubjectNameValid("M*aths"));
     Assert.AreEqual((false, "Invalid subject name!"), SubjectValidation.IsSubjectNameValid("Design && Technology"));
     Assert.AreEqual((true, ""), SubjectValidation.IsSubjectNameValid("Physics"));
 }
 public void IsSubjectIDValidTest()
 {
     Assert.AreEqual((false, "Missing subject ID!"), SubjectValidation.IsSubjectIDValid(""));
     Assert.AreEqual((false, "Invalid subject ID, no special characters allowed!"), SubjectValidation.IsSubjectIDValid("MAT*3"));
     Assert.AreEqual((false, "Invalid subject ID, only a single digit is allowed!"), SubjectValidation.IsSubjectIDValid("PSY43"));
     Assert.AreEqual((true, ""), SubjectValidation.IsSubjectIDValid("BIO5B"));
 }
 public void IsSubjectGradeValidTest()
 {
     Assert.AreEqual((false, "Missing subject type!"), SubjectValidation.IsSubjectGradeValid("B", ""));
     Assert.AreEqual((false, "Missing subject actual grade!"), SubjectValidation.IsSubjectGradeValid("", "actual"));
     Assert.AreEqual((false, "Invalid subject type!"), SubjectValidation.IsSubjectGradeValid("A", "attainment"));
     Assert.AreEqual((false, "Invalid subject grade!"), SubjectValidation.IsSubjectGradeValid("F", "actual"));
     Assert.AreEqual((true, ""), SubjectValidation.IsSubjectGradeValid("A", "actual"));
 }
Exemplo n.º 4
0
 public override void Create(Subject subject)
 {
     if (SubjectValidation.IsValidSubject(subject))
     {
         DataAccessProvider.ExecuteNonQuery($"INSERT INTO Subjects (SubjectName, UniversityID) " +
                                            $"values (\'{subject.SubjectName}\', " +
                                            $"{subject.UniversityId})");
     }
 }
Exemplo n.º 5
0
 public override void Update(Subject subject)
 {
     if (SubjectValidation.IsValidSubject(subject) &&
         SubjectValidation.IsValidSubjectId(subject.SubjectId))
     {
         DataAccessProvider.ExecuteNonQuery($"UPDATE Subjects SET " +
                                            $"SubjectName = \'{subject.SubjectName}\', " +
                                            $"UniversityID = {subject.UniversityId} " +
                                            $"WHERE SubjectID = {subject.SubjectId}");
     }
 }
Exemplo n.º 6
0
        private void AddSubjectButton_Click(object sender, EventArgs e)
        {
            var subjectRepository = new SubjectRepository();

            var subjectName = addSubjectNameTextBox.Text;
            var subject     = new Subject(subjectName, _universityId);

            if (!SubjectValidation.IsValidSubject(subject))
            {
                return;
            }

            subjectRepository.Create(subject);
            RefreshForm();
        }
Exemplo n.º 7
0
        // Custom Constructor.

        /**
         * <summary>This custom constructor method is responsible for creating a Subject object.</summary>
         *
         * <param name="ID">The ID of the subject.</param>
         * <param name="name">The name of the subject.</param>
         * <param name="actualGrade">The actual subject grade.</param>
         * <param name="expectedGrade">The expected subject grade.</param>
         *
         * <example>
         * <code>Subject sub = new Subject("PHY4", "Physics", "B", "A*");</code>
         * This creates a Subject object with "PHY4" as the subject ID, "Physics" as the subject name, "B" as the actual grade and "A*" as the expected grade.</example>
         */
        public Subject(string ID, string name, string actualGrade, string expectedGrade)
        {
            if (!SubjectValidation.IsSubjectIDValid(ID).Item1)
            {
                // Throws an exception with a message dependent on what invalidates the subject ID.
                throw new ArgumentException(SubjectValidation.IsSubjectIDValid(ID).Item2);
            }
            else
            {
                GetSubjectID = ID;
            }

            if (!SubjectValidation.IsSubjectNameValid(name).Item1)
            {
                // Throws an exception with a message dependent on what invalidates the subject name.
                throw new ArgumentException(SubjectValidation.IsSubjectNameValid(name).Item2);
            }
            else
            {
                GetSubjectName = name;
            }

            if (!SubjectValidation.IsSubjectGradeValid(actualGrade, "actual").Item1)
            {
                // Throws an exception with a message dependent on what invalidates the subject's actual grade.
                throw new ArgumentException(SubjectValidation.IsSubjectIDValid(ID).Item2);
            }
            else
            {
                GetActualGrade = actualGrade;
            }

            if (!SubjectValidation.IsSubjectGradeValid(expectedGrade, "expected").Item1)
            {
                // Throws an exception with a message dependent on what invalidates the subject's expected grade.
                throw new ArgumentException(SubjectValidation.IsSubjectIDValid(ID).Item2);
            }
            else
            {
                GetExpectedGrade = expectedGrade;
            }
        }