public void AssignTeachToCourse_CourseNotFound_ReturnsFalse() { var teacherRepository = new TeacherRepository(Context); var teacher = new Teacher() { FirstName = "Mikesh", LastName = "Mistry" }; //add a teacher teacherRepository.Add(teacher); //find the newly added teacher var enrollingTeacher = teacherRepository.Find(teacher => teacher.FirstName == "Mikesh") .FirstOrDefault(); //found the teacher if (enrollingTeacher != null) { //assign a teacher to a course that does not exist var assignedCourseToTeacher = courseRepository.AssignTeacherToCourse(enrollingTeacher.TeacherId, 1234); //should return false indicating course was not assigned to the teacher Assert.IsFalse(assignedCourseToTeacher); } }
public void AssignTeachToCourse_TeacherNotFound_ReturnsFalse() { var courseRepository = new CourseRepository(Context); //create the course var course = new Course() { Name = "Introduction to C#", Description = "Introduction to C# programming fundamentals" }; //add a course courseRepository.Add(course); //find the newly added course var enrollingCourse = courseRepository.Find(course => course.Name == "Introduction to C#") .FirstOrDefault(); //found the course if (enrollingCourse != null) { //assign a course to a teacher that does not exist var assignedTeacherToCourse = courseRepository.AssignTeacherToCourse(1234, enrollingCourse.CourseId); //should return false indicating course was not assigned to the teacher Assert.IsFalse(assignedTeacherToCourse); } }
public void GetAssignedCourse_TeacherFound_ReturnsCourses() { //create the new student var newTeacher = new Teacher() { FirstName = "Mikesh", LastName = "Mistry" }; //add the teacher to the database teacherRepository.Add(newTeacher); //add some courses var courseRepository = new CourseRepository(Context); var courseList = new List <Course>(); // add a list of courses courseList.Add(new Course { Name = "Introduction to C#", Description = "Introduces students to C# programming" }); courseList.Add(new Course { Name = "Introduction to Java", Description = "Introduces students to Java programming" }); //add the course using add range courseRepository.AddRange(courseList); //use the find method to find a teacher var foundTeacher = teacherRepository.Find(teacher => teacher.FirstName == "Mikesh" && teacher.LastName == "Mistry").FirstOrDefault(); //found the student if (foundTeacher != null) { //enroll the teacher into the two course foreach (var course in courseList) { courseRepository.AssignTeacherToCourse(foundTeacher.TeacherId, course.CourseId); } //get the found teacher var teacherCourseList = teacherRepository.GetId(foundTeacher.TeacherId); if (teacherCourseList != null) { //the count of the courseList used to add the courses to the teacher var courseListCount = courseList.Count(); var teacherEnrolledCoursesCount = teacherCourseList.Courses.Count(); //insure the counts are the same Assert.AreEqual(courseListCount, teacherEnrolledCoursesCount); //insure that ids are the same Assert.AreEqual(foundTeacher.TeacherId, teacherCourseList.TeacherId); } } }