public void Test_Find_FindsDepartmentInDatabase() { //Arrange Department testDepartment = new Department("History"); testDepartment.Save(); //Act Department foundDepartment = Department.Find(testDepartment.GetId()); //Assert Assert.Equal(testDepartment, foundDepartment); }
public void Test_AddMajor_DisplaysAddedMajors() { Student testStudent = new Student("Bob", enrollmentDate); testStudent.Save(); Department testDepartment = new Department("History"); testDepartment.Save(); testStudent.AddMajor(testDepartment.GetId()); List<Department> resultList = testStudent.GetMajors(); List<Department> expectedList= new List<Department>{testDepartment}; Assert.Equal(expectedList, resultList); }
public void Test_Save_AssignsIdToObject() { //Arrange Department testDepartment = new Department("History"); //Act testDepartment.Save(); Department savedDepartment = Department.GetAll()[0]; int result = savedDepartment.GetId(); int testId = testDepartment.GetId(); //Assert Assert.Equal(testId, result); }
public void Test_DropMajor_DropsSelectedMajor() { Student testStudent = new Student("Bob", enrollmentDate); testStudent.Save(); Department testDepartment1 = new Department("Chinese"); testDepartment1.Save(); testStudent.AddMajor(testDepartment1.GetId()); Department testDepartment2 = new Department("Spanish"); testDepartment2.Save(); testStudent.AddMajor(testDepartment2.GetId()); testStudent.DropMajor(testDepartment1.GetId()); List<Department> resultList = testStudent.GetMajors(); List<Department> expectedList= new List<Department>{testDepartment2}; Assert.Equal(expectedList, resultList); }
public HomeModule() { Get["/"]=_=>View["index.cshtml"]; Get["/courses"]=_=> { List<Course> allCourses = Course.GetAll(); return View["courses.cshtml", allCourses]; }; Get["/courses/new"]=_=>{ List<Department> departments = Department.GetAll(); return View["course_new.cshtml" , departments]; }; Post["/courses/new"]=_=> { Course newCourse = new Course(Request.Form["course-name"], Request.Form["department"]); newCourse.Save(); List<Course> allCourses = Course.GetAll(); return View["courses.cshtml", allCourses]; }; // Get["courses/{id}"] = parameters => // { // Course course = Course.Find(parameters.id); // return View["course.cshtml", course]; // }; Get["students/{id}"] = parameters => { Student student = Student.Find(parameters.id); return View["student.cshtml", student]; }; Get["/students"]=_=> { List<Student> allStudents = Student.GetAll(); return View["students.cshtml", allStudents]; }; Get["/students/new"]=_=>View["student_new.cshtml"]; Post["/students/new"]=_=> { Student newStudent = new Student(Request.Form["student-name"], Request.Form["enrollment-date"]); newStudent.Save(); List<Student> allStudents = Student.GetAll(); return View["students.cshtml", allStudents]; }; Post["/students/{id}/addCourse"] = parameters => { Student student = Student.Find(parameters.id); student.AddCourse(Request.Form["course"]); return View["student.cshtml", student]; }; Post["/students/{id}/deleteCourse"] = parameters => { Student student = Student.Find(parameters.id); student.DropCourse(Request.Form["course"]); return View["student.cshtml", student]; }; Post["/students/{id}/updatemajors"]=parameters=> { Student student = Student.Find(parameters.id); int majorCount = student.GetMajors().Count; if(majorCount == 0 && Request.Form["new-major"] !=0) { student.AddMajor(Request.Form["new-major"]); } else if(majorCount == 1) { if(Request.Form["current-major"]==0) { student.DropMajor(Request.Form["current-major"]); } else if(Request.Form["current-major"]!=student.GetMajors()[0].GetId()) { student.DropMajor(student.GetMajors()[0].GetId()); student.AddMajor(Request.Form["current-major"]); } if(Request.Form["additional-major"] !=0) { student.AddMajor(Request.Form["additonal-major"]); } } else { if(Request.Form["first-major"]==0) { student.DropMajor(Request.Form["first-major"]); } else if(Request.Form["first-major"]!=student.GetMajors()[0].GetId()) { student.DropMajor(student.GetMajors()[0].GetId()); student.AddMajor(Request.Form["first-major"]); } if(Request.Form["second-major"]==0) { student.DropMajor(Request.Form["second-major"]); } else if(Request.Form["second-major"]!=student.GetMajors()[1].GetId()) { student.DropMajor(student.GetMajors()[1].GetId()); student.AddMajor(Request.Form["second-major"]); } } return View["student.cshtml", student]; }; Get["/departments"]=_=> { List<Department> departments = Department.GetAll(); return View["departments.cshtml", departments]; }; Get["/departments/new"]=_=>View["department_new.cshtml"]; Post["/departments/new"]=_=> { Department department = new Department(Request.Form["department-name"]); department.Save(); List<Department> departments = Department.GetAll(); return View["departments.cshtml", departments]; }; Get["/departments/{id}"]=parameters=> { Department department = Department.Find(parameters.id); return View["department.cshtml", department]; }; }
public void Test_Save_SavesToDatabase() { //Arrange Department testDepartment = new Department("History"); //Act testDepartment.Save(); List<Department> result = Department.GetAll(); List<Department> testList = new List<Department>{testDepartment}; //Assert Assert.Equal(testList, result); }