public void ShouldMap()
        {
            var entity = new CourseBuilder().Build();
            var model = new CourseToCourseJsonModelMapper().Build(entity);

            model.CourseCode.ShouldBe(entity.CourseCode);
            model.CourseTitle.ShouldBe(entity.CourseTitle);
        }
예제 #2
0
 private IEnumerable<Web.Data.Entities.Course> SetUpCourses()
 {
     var courses = new List<Web.Data.Entities.Course>();
     var course1 = new CourseBuilder().Build();
     var course2 = new CourseBuilder().Build();
     courses.Add(course1);
     courses.Add(course2);
     _mockGenericRepository.Setup(repo => repo.GetAll<Web.Data.Entities.Course>()).Returns(courses);
     return courses;
 }
예제 #3
0
        public void ShouldHaveErrorsIfCourseExists()
        {
            Setup();
            var courseEntity = new CourseBuilder().Build();

            _genericRepository
                .Get(Arg.Any<Expression<Func<Web.Data.Entities.Course, bool>>>())
                .Returns(courseEntity);

            _validator.ShouldHaveValidationErrorFor(c => c.CourseCode, _courseCreateModel.CourseCode);
        }
예제 #4
0
        public void PostCreateShouldSaveCourse()
        {
            var controller = SetUpController();

            var createModel = new CreateModel();
            var courseToSave = new CourseBuilder().Build();
            _mockCreateModelToCourseMapper.Setup(mapper => mapper.Build(createModel)).Returns(courseToSave);

            controller.Create(createModel);

            _mockGenericRepository.Verify(repo => repo.Add(courseToSave));
            _mockGenericRepository.Verify(repo => repo.Save());
        }
예제 #5
0
        public void PostCreateShouldRedirectToCourseIndex()
        {
            var controller = SetUpController();

            var createModel = new CreateModel();
            var courseToSave = new CourseBuilder().Build();
            _mockCreateModelToCourseMapper.Setup(mapper => mapper.Build(createModel)).Returns(courseToSave);

            var result = (RedirectToRouteResult) controller.Create(createModel);

            Assert.Equal("Course", result.RouteValues["Controller"]);
            Assert.Equal("Index", result.RouteValues["Action"]);
        }