Пример #1
0
        public void Save_ReturnsStudentName_name()
        {
            Student newStudent = new Student("Sally");

            newStudent.Save();

            List <Student> expected = new List <Student> {
                newStudent
            };
            List <Student> result = Student.GetAll();

            Assert.Equal(expected, result);
        }
        public void Test_SaveToDataBase_GetAll()
        {
            List <Student> allStudents = new List <Student> {
            };
            List <Student> testList    = new List <Student> {
            };
            Student newStudent         = new Student("John");

            testList.Add(newStudent);

            newStudent.Save();
            allStudents = Student.GetAll();

            Assert.Equal(testList, allStudents);
        }
Пример #3
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            Student firstStudent = new Student("Jerry", "03/01/2012");

            firstStudent.Save();

            //Act
            Student savedStudent = Student.GetAll()[0];

            int result = savedStudent.GetId();
            int testId = firstStudent.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Пример #4
0
        public void Test_Save()
        {
            //Arrange
            Student firstStudent = new Student("Jerry", "03/01/2012");

            firstStudent.Save();

            //Act
            List <Student> result   = Student.GetAll();
            List <Student> testList = new List <Student> {
                firstStudent
            };

            //Assert
            Assert.Equal(testList, result);
        }
Пример #5
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange

            Student testStudent = new Student("Joe", "2-12-2012", 2);

            //Act
            testStudent.Save();
            Student savedStudent = Student.GetAll()[0];

            int result = savedStudent.GetId();
            int testId = testStudent.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Пример #6
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Department> AllDepartments = Department.GetAll();
                return(View["index.cshtml", AllDepartments]);
            };

            Post["/department/new"] = _ => {
                Department newDepartment = new Department(Request.Form["department-name"]);
                newDepartment.Save();

                List <Department> AllDepartments = Department.GetAll();
                return(View["index.cshtml", AllDepartments]);
            };

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

            Post["/course/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["/students"] = _ => {
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };

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

            Delete["/student/delete/{id}"] = parameters => {
                Student foundStudent = Student.Find(parameters.id);
                foundStudent.Delete();
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };
        }
Пример #7
0
        public void Delete_DeletesIndividualStudent_list()
        {
            Student newStudent1 = new Student("Sally");

            newStudent1.Save();
            Student newStudent2 = new Student("Gretel");

            newStudent2.Save();

            newStudent2.Delete();

            List <Student> expected = new List <Student> {
                newStudent1
            };
            List <Student> actual = Student.GetAll();

            Assert.Equal(expected, actual);
        }
Пример #8
0
        public void Test_Delete_DeleteSingleStudent()
        {
            //Arrange
            Student testInput = new Student("John", "8-10-2009", 3);

            testInput.Save();
            Student testInput2 = new Student("Jose", "8-10-2009", 3);

            testInput2.Save();

            //Act
            testInput.Delete();
            List <Student> result     = Student.GetAll();
            List <Student> resultList = new List <Student> {
                testInput2
            };

            Assert.Equal(result, resultList);
        }
Пример #9
0
        public void GetAll_StudentEmptyAtFirst_true()
        {
            int result = Student.GetAll().Count;

            Assert.Equal(0, result);
        }
Пример #10
0
        public void TEST_CheckDBIsEmpty()
        {
            int result = Student.GetAll().Count;

            Assert.Equal(0, result);
        }
        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]);
            };
        }
Пример #12
0
        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"]);
            };
        }
Пример #13
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/students"] = _ => {
                List <Student> allStudents = Student.GetAll();
                return(View["students.cshtml", allStudents]);
            };

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

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

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

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

            Post["/courses"] = _ => {
                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/{courseId}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Course         selectedCourse     = Course.Find(parameters.courseId);
                List <Student> students           = selectedCourse.GetStudents();
                List <Student> allStudents        = Student.GetAll();
                model.Add("selected-course", selectedCourse);
                model.Add("students", students);
                model.Add("all-students", allStudents);
                return(View["course.cshtml", model]);
            };

            Get["/students/{studentId}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Student       selectedStudent     = Student.Find(parameters.studentId);
                List <Course> courses             = selectedStudent.GetCourses();
                List <Course> allCourses          = Course.GetAll();
                model.Add("selected-student", selectedStudent);
                model.Add("courses", courses);
                model.Add("all-courses", allCourses);
                return(View["student.cshtml", model]);
            };

            Post["/courses/{courseId}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Course selectedCourse             = Course.Find(parameters.courseId);
                selectedCourse.AddStudent(Student.Find(Request.Form["selected-student"]));
                List <Student> students    = selectedCourse.GetStudents();
                List <Student> allStudents = Student.GetAll();
                model.Add("selected-course", selectedCourse);
                model.Add("students", students);
                model.Add("all-students", allStudents);
                return(View["course.cshtml", model]);
            };

            Delete["/students/{student_id}/delete"] = parameters => {
                Student foundStudent = Student.Find(parameters.student_id);
                foundStudent.Delete();
                List <Student> allStudents = Student.GetAll();
                return(View["students.cshtml", allStudents]);
            };

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

            Delete["/students"] = _ => {
                Student.DeleteAll();
                List <Student> allStudents = Student.GetAll();
                return(View["students.cshtml", allStudents]);
            };

            Get["/courses/results"] = _ => {
                List <Course> matches = Course.Search(Request.Form["search"]);
                return(View["results.cshtml", matches]);
            };
        }