示例#1
0
        public void AssignGradeToStudent_StudentAndCourseNotFound_ReturnsFalse()
        {
            var result = false;

            result = gradeRepository.AssignGradeToStudent(1, 1, "A+");

            Assert.IsFalse(result);
        }
        public void GetGrades_StudentFound_ReturnsGrades()
        {
            //create the new student
            var newStudent = new Student()
            {
                FirstName = "Mikesh",
                LastName  = "Mistry"
            };

            //add the student to the database
            studentRepository.Add(newStudent);

            //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 student
            var foundstudent = studentRepository.Find(student => student.FirstName == "Mikesh" && student.LastName == "Mistry").FirstOrDefault();



            //found the student
            if (foundstudent != null)
            {
                //enroll the student into the two course
                foreach (var course in courseList)
                {
                    courseRepository.EnrollStudentIntoCourse(foundstudent.StudentId, course.CourseId);
                }


                //get the found student
                var studentCourseList = studentRepository.GetId(foundstudent.StudentId);

                if (studentCourseList != null)
                {
                    //check to see if the grade was added
                    var gradeAdded = false;

                    //assign a student a grade
                    var gradeRepository = new GradeRepository(Context);

                    foreach (var course in studentCourseList.Courses)
                    {
                        gradeAdded = gradeRepository.AssignGradeToStudent(studentCourseList.StudentId, course.CourseId, "A+");
                        Assert.IsTrue(gradeAdded);
                    }


                    Assert.AreEqual(2, studentCourseList.Grades.Count());
                }
            }
        }