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")); }
// 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; } }