public void AddStudent(Student student) { if (student == null) { throw new ArgumentNullException("Student cannot be null"); } if (this.studentsList.Count < 29) { if (this.studentsList.Contains(student)) { throw new ApplicationException("The same student cannot be added more than once"); } this.studentsList.Add(student); student.AddCourse(this); return; } throw new ApplicationException("Students in a class must be less than 30"); }
public void GetCourseStudentInfo() { Student pesho = new Student("Pepito", 10101); pesho.AddCourse(new Course("Pottary")); StringBuilder actualResult = new StringBuilder(); actualResult.AppendLine(pesho.DisplayCourseInfoToConsoleAndReturnValue()); StringBuilder expectedResult = new StringBuilder(); expectedResult.AppendLine("Pepito is attending:"); expectedResult.AppendFormat("Course name: Pottary"); expectedResult.AppendLine(); Assert.AreEqual(expectedResult, expectedResult); }