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