Beispiel #1
0
        public void Test_AddCourse_AddCourseToStudent()
        {
            Student testStudent = new Student("John", "8-10-2009", 3);

            testStudent.Save();

            Course testCourse = new Course("Psychobiology", 1, "PSC121");

            testCourse.Save();

            Course testCourse2 = new Course("Psychobiology", 1, "PSC121");

            testCourse2.Save();

            testStudent.AddCourse(testCourse);
            testStudent.AddCourse(testCourse2);

            List <Course> testList = new List <Course> {
                testCourse, testCourse2
            };
            List <Course> result = testStudent.GetCourses();

            Assert.Equal(result, testList);
        }
        public void Test_GetCoursesAssociatedWithStudent()
        {
            List <Course> allCourses  = new List <Course> {
            };
            List <Course> testCourses = new List <Course> {
            };

            Course newCourse = new Course("Math", "MTH 001");

            newCourse.Save();

            Student newStudent = new Student("John");

            newStudent.Save();

            newStudent.AddCourse(newCourse);
            allCourses = newStudent.GetCourses();
            testCourses.Add(newCourse);

            Assert.Equal(testCourses, allCourses);
        }
        public void Test_AddCourse_AddsCourseToStudent()
        {
            //Arrange
            Student testStudent = new Student("Jerry", "03/01/2012");

            testStudent.Save();

            Course testCourse = new Course("History", "100");

            testCourse.Save();

            //Act
            testStudent.AddCourse(testCourse);

            List <Course> result   = testStudent.GetCourses();
            List <Course> testList = new List <Course> {
                testCourse
            };

            //Assert
            Assert.Equal(testList, result);
        }
Beispiel #4
0
        public void Test_GetCourses_RetrieveListOfAllCourses()
        {
            Student testStudent = new Student("John", "8-10-2009", 3);

            testStudent.Save();

            Course testCourse = new Course("Psychobiology", 1, "PSC121");

            testCourse.Save();

            Course testCourse2 = new Course("Psychobiology", 1, "PSC121");

            testCourse2.Save();

            testStudent.AddCourse(testCourse);
            List <Course> savedCourses = testStudent.GetCourses();
            List <Course> resultList   = new List <Course> {
                testCourse
            };

            Assert.Equal(savedCourses, resultList);
        }
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                return(View["index.cshtml"]);
            };
            Get["/add-new-student"] = _ =>
            {
                return(View["add-new-student.cshtml"]);
            };
            Post["/added-student"] = _ =>
            {
                string studentName = Request.Form["student-name"];

                Student newStudent = new Student(studentName);
                newStudent.Save();
                return(View["added-student.cshtml", studentName]);
            };
            Get["/add-new-course"] = _ =>
            {
                return(View["add-new-course.cshtml"]);
            };
            Post["/added-course"] = _ =>
            {
                string courseName   = Request.Form["course-name"];
                string courseNumber = Request.Form["course-number"];
                Course newCourse    = new Course(courseName, courseNumber);
                newCourse.Save();
                return(View["added-course.cshtml", newCourse]);
            };
            Get["/view-all-courses"] = _ =>
            {
                List <Course> allCourses = new List <Course> {
                };
                allCourses = Course.GetAll();
                return(View["view-all-courses.cshtml", allCourses]);
            };
            Get["/view-all-students"] = _ =>
            {
                List <Student> allStudents = new List <Student> {
                };
                allStudents = Student.GetAll();
                return(View["view-all-students.cshtml", allStudents]);
            };
            Get["/course/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Course         selectedCourse     = Course.Find(parameters.id);
                List <Student> CourseStudents     = selectedCourse.GetStudents();
                List <Student> allStudents        = Student.GetAll();
                model.Add("course", selectedCourse);
                model.Add("CourseStudents", CourseStudents);
                model.Add("allStudents", allStudents);
                return(View["course.cshtml", model]);
            };
            Get["/student/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Student       selectedStudent     = Student.Find(parameters.id);
                List <Course> CourseStudents      = selectedStudent.GetCourses();
                List <Course> allCourses          = Course.GetAll();
                model.Add("student", selectedStudent);
                model.Add("CourseStudents", CourseStudents);
                model.Add("allCourses", allCourses);
                return(View["student.cshtml", model]);
            };
            Post["/student/add_course"] = _ =>
            {
                Student student = Student.Find(Request.Form["student-id"]);
                Course  course  = Course.Find(Request.Form["course-id"]);
                student.AddCourse(course);
                List <Student> allStudents = new List <Student> {
                };
                allStudents = Student.GetAll();
                return(View["view-all-students.cshtml", allStudents]);
            };
            Post["/course/add_student"] = _ =>
            {
                Course  course  = Course.Find(Request.Form["course-id"]);
                Student student = Student.Find(Request.Form["student-id"]);
                course.AddStudent(student);
                List <Course> allCourses = new List <Course> {
                };
                allCourses = Course.GetAll();
                return(View["view-all-courses.cshtml", allCourses]);
            };
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/courses"] = _ => {
                List <Course> AllCourses = Course.GetAll();
                return(View["courses.cshtml", AllCourses]);
            };

            Get["/courses/new"] = _ => {
                return(View["course_new.cshtml"]);
            };

            Post["/courses/new"] = _ => {
                Course newCourse = new Course(Request.Form["course-name"], Request.Form["course-number"]);
                newCourse.Save();
                List <Course> AllCourses = Course.GetAll();
                return(View["courses.cshtml", AllCourses]);
            };

            Get["courses/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Course         SelectedCourse     = Course.Find(parameters.id);
                List <Student> CourseStudents     = SelectedCourse.GetStudents();
                List <Student> AllStudents        = Student.GetAll();
                model.Add("course", SelectedCourse);
                model.Add("courseStudents", CourseStudents);
                model.Add("allStudents", AllStudents);
                return(View["course.cshtml", model]);
            };

            Post["course/add_student"] = _ => {
                Student student = Student.Find(Request.Form["student-id"]);
                Course  course  = Course.Find(Request.Form["course-id"]);
                course.AddStudent(student);
                return(View["success.cshtml"]);
            };
// for students
            Get["/students"] = _ => {
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };

            Get["/students/new"] = _ => {
                return(View["student_new.cshtml"]);
            };

            Post["/students/new"] = _ => {
                Student newStudent = new Student(Request.Form["student-name"], Request.Form["student-date"]);
                newStudent.Save();
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };

            Get["students/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Student       SelectedStudent     = Student.Find(parameters.id);
                List <Course> StudentCourses      = SelectedStudent.GetCourses();
                List <Course> AllCourses          = Course.GetAll();
                model.Add("student", SelectedStudent);
                model.Add("studentCourses", StudentCourses);
                model.Add("allCourses", AllCourses);
                return(View["student.cshtml", model]);
            };

            Post["student/add_course"] = _ => {
                Course  course  = Course.Find(Request.Form["course-id"]);
                Student student = Student.Find(Request.Form["student-id"]);
                student.AddCourse(course);
                return(View["success.cshtml"]);
            };

// for department
            Get["/departments"] = _ => {
                List <Department> AllDepartments = Department.GetAll();
                return(View["departments.cshtml", AllDepartments]);
            };

            Get["/departments/new"] = _ => {
                return(View["department_new.cshtml"]);
            };

            Post["/departments/new"] = _ => {
                Department newDepartment = new Department(Request.Form["department-name"]);
                newDepartment.Save();
                List <Department> AllDepartments = Department.GetAll();
                return(View["departments.cshtml", AllDepartments]);
            };

            Get["departments/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Department     SelectedDepartment = Department.Find(parameters.id);
                List <Student> DepartmentStudents = SelectedDepartment.GetStudents();
                List <Student> AllStudents        = Student.GetAll();
                List <Course>  DepartmentCourses  = SelectedDepartment.GetCourses();
                List <Course>  AllCourses         = Course.GetAll();
                model.Add("department", SelectedDepartment);
                model.Add("departmentStudents", DepartmentStudents);
                model.Add("allStudents", AllStudents);
                model.Add("departmentCourses", DepartmentCourses);
                model.Add("allCourses", AllCourses);
                return(View["department.cshtml", model]);
            };

            Post["department/add_course"] = _ => {
                Course     course     = Course.Find(Request.Form["course-id"]);
                Department department = Department.Find(Request.Form["department-id"]);
                department.AddCourse(course);
                return(View["success.cshtml"]);
            };

            Post["department/add_student"] = _ => {
                Student    student    = Student.Find(Request.Form["student-id"]);
                Department department = Department.Find(Request.Form["department-id"]);
                department.AddStudent(student);
                return(View["success.cshtml"]);
            };
        }