Exemplo n.º 1
0
        public void DeleteGrade()
        {
            //create the student
            var newStudent = new Student()
            {
                FirstName = "Mikesh",
                LastName  = "Mistry"
            };


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

            //Find the student
            var foundStudent = studentRepository.GetAll().ToList();

            //create a course
            var newCourse = new Course()
            {
                Name        = "Introduction To C# Programming",
                Description = "Introduction To C# Programming"
            };

            //add the course to the database
            courseRepository.Add(newCourse);

            //find the course
            var foundCourse = courseRepository.GetAll().ToList();


            //create a new grade
            var newGrade = new Grade()
            {
                Student     = newStudent,
                Course      = newCourse,
                LetterGrade = "A+"
            };

            //add the grade
            gradeRepository.Add(newGrade);

            //find the grade
            var foundGrade = gradeRepository.Find(grade => grade.Student.StudentId == foundStudent[0].StudentId &&
                                                  grade.Course.CourseId == foundCourse[0].CourseId

                                                  ).FirstOrDefault();

            //test to see if we found the grade
            Assert.IsNotNull(foundGrade);

            //delete it
            gradeRepository.Remove(newGrade);

            foundGrade = gradeRepository.Find(grade => grade.Student.StudentId == foundStudent[0].StudentId &&
                                              grade.Course.CourseId == foundCourse[0].CourseId

                                              ).FirstOrDefault();

            //after deleting found grade should be null
            Assert.IsNull(foundGrade);
        }