コード例 #1
0
        public void All_instructor_courses_returned_from_dbcontext()
        {
            var context    = new FakeSchoolContext();
            int?id         = 1;
            var instructor = new Instructor()
            {
                ID      = 1,
                Courses = new List <Course>()
                {
                    new Course()
                    {
                        CourseID    = 1,
                        Enrollments = new List <Enrollment>()
                        {
                            new Enrollment()
                        }
                    }
                }
            };

            context.Instructors.Add(instructor);

            var viewModel = new InstructorIndexData();

            viewModel.Instructors = context.Instructors
                                    .Include(i => i.OfficeAssignment)
                                    .Include(i => i.Courses.Select(c => c.Department))
                                    .OrderBy(i => i.LastName);
            viewModel.Courses     = viewModel.Instructors.Single(i => i.ID == id.Value).Courses;
            viewModel.Enrollments = viewModel.Courses.Single(x => x.CourseID == 1).Enrollments;

            Assert.Equal(1, viewModel.Instructors.Count());
            Assert.Equal(1, viewModel.Courses.Count());
            Assert.Equal(1, viewModel.Enrollments.Count());
        }
コード例 #2
0
        public void When_selecting_course_enrollments_displayed()
        {
            var fakeSchoolContext = new FakeSchoolContext();
            var instructor        = new Instructor()
            {
                ID      = 1,
                Courses = new List <Course>()
                {
                    new Course()
                    {
                        CourseID    = 1,
                        Enrollments = new List <Enrollment>()
                        {
                            new Enrollment()
                            {
                                EnrollmentID = 1
                            }
                        }
                    }
                }
            };

            fakeSchoolContext.Instructors.Add(instructor);

            var controller = new InstructorController(fakeSchoolContext);
            // Testing the Controller.GetInstructorIndexData() method
            var viewModel = controller.GetInstructorIndexData(1, 1);

            Assert.NotNull(viewModel.Enrollments.FirstOrDefault());
            Assert.Equal(1, viewModel.Enrollments.Count());
        }