public void TestAllCoursesWhenEmptyShouldReturnNoCourses() { var controller = new CoursesController(new BangaloreUniversityData(), new User("habala", "babbala", Role.Student)); var result = controller.All(); Assert.AreEqual(Message.NoCourses, result.Display()); }
public void ViewAllCourse_WhereAreCoursesWithNoStudent_ShouldReturnCoursesOrderedByName() { User firstUser = new User(FirstUsername, "password", Role.Lecturer); var db = new BangaloreUniversityData(); CoursesController coursesController = new CoursesController(db, firstUser); coursesController.Create(FirstCourse); coursesController.Create(SecondCourse); coursesController.Create(ThirdCourse); coursesController.Create(FourthCourse); IView courseView = coursesController.All(); string actualView = courseView.Display(); StringBuilder expectedView = new StringBuilder(); expectedView.AppendLine("All courses:"); expectedView.AppendLine("CourseA (0 students)"); expectedView.AppendLine("CourseA (0 students)"); expectedView.AppendLine("CourseB (0 students)"); expectedView.Append("CourseC (0 students)"); Assert.AreEqual(expectedView.ToString(), actualView, "Does not return proper view(course order) when there are no views!"); }
public void TestWithNoCourses() { IBangaloreUniversityData data = new BangaloreUniversityData(); User user = new User("firstLecturer", "firstPass", Role.Guest); CoursesController controller = new CoursesController(data, user); string message = controller.All().Display(); Assert.AreEqual("No courses.", message); }
public void ViewAllCourse_WhereAreNoCourses_ShouldReturnExpectedMessage() { User user = new User(FirstUsername, "password", Role.Student); CoursesController coursecoController = new CoursesController(new BangaloreUniversityData(), user); IView courseView = coursecoController.All(); string actualView = courseView.Display(); string expectedView = "No courses."; Assert.AreEqual(expectedView, actualView, "Does not return proper view when there are no views!"); }
public void TestWithOneCourseAndNoStudents() { IBangaloreUniversityData data = new BangaloreUniversityData(); User user = new User("firstLecturer", "firstPass", Role.Lecturer); CoursesController controller = new CoursesController(data, user); controller.Create("Object-Oriented+Programming"); string message = controller.All().Display(); var courses = new StringBuilder(); courses.AppendLine("All courses:"); foreach (var course in data.Courses.Items) { courses.AppendFormat("{0} ({1} students)", course.CourseName, course.Students.Count); } Assert.AreEqual(courses.ToString(), message); }
public void TestAllCoursesWhenHasCoursesShouldReturnTheCourses() { var data = new BangaloreUniversityData(); var loginController = new UsersController(data, null); loginController.Register("habala", "babbala", "babbala", "Lecturer"); var user = new User("habala", "babbala", Role.Lecturer); var controller = new CoursesController(data, user); controller.Create("tessst"); controller.Create("tessst1"); controller.Create("tessst3"); var result = controller.All(); var message = @"All courses: tessst (0 students) tessst1 (0 students) tessst3 (0 students)"; Assert.AreEqual(message, result.Display()); }
public void ViewAllCourse_WhereAreCoursesWithSameNameButDifferenStudentsCount_ShouldReturnCoursesOrderedByStudents() { User firstUser = new User(FirstUsername, "password", Role.Lecturer); User secondUser = new User(SecondUsername, "password", Role.Student); User thirdUser = new User(SecondUsername, "password", Role.Student); var db = new BangaloreUniversityData(); CoursesController coursesController = new CoursesController(db, firstUser); coursesController.Create(FirstCourse); coursesController.Create(FirstCourse); coursesController.Create(FirstCourse); coursesController.Create(FirstCourse); coursesController.Enroll(1); Enroll_InCourse(db, secondUser, 1); Enroll_InCourse(db, thirdUser, 1); Enroll_InCourse(db, secondUser, 2); Enroll_InCourse(db, firstUser, 2); Enroll_InCourse(db, secondUser, 3); Enroll_InCourse(db, firstUser, 3); Enroll_InCourse(db, firstUser, 4); IView courseView = coursesController.All(); string actualView = courseView.Display(); StringBuilder expectedView = new StringBuilder(); expectedView.AppendLine("All courses:"); expectedView.AppendLine("CourseA (3 students)"); expectedView.AppendLine("CourseA (2 students)"); expectedView.AppendLine("CourseA (2 students)"); expectedView.Append("CourseA (1 students)"); Assert.AreEqual(expectedView.ToString(), actualView, "Does not return proper view(course order) when there are no views!"); }
public void TestWithSeveralCoursesAndDifferentStudents() { IBangaloreUniversityData data = new BangaloreUniversityData(); User user = new User("firstLecturer", "firstPass", Role.Lecturer); CoursesController controller = new CoursesController(data, user); controller.Create("Object-Oriented+Programming"); controller.Create("High-Quality+Code"); controller.Create("Java+Basics"); controller.Enroll(1); controller.Enroll(3); string message = controller.All().Display(); var courses = new StringBuilder(); courses.AppendLine("All courses:"); foreach (var course in data.Courses.Items.OrderBy(c => c.CourseName).ThenByDescending(c => c.Students.Count)) { courses.AppendFormat("{0} ({1} students)", course.CourseName, course.Students.Count).AppendLine(); } Assert.AreEqual(courses.ToString().Trim(), message); }