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"));
 }
Exemple #2
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;
            }
        }