Пример #1
0
        public void PostCreateShouldReturnItselfWhenModelStateIsInvalid()
        {
            var controller  = SetUpController();
            var createModel = new CreateModel();

            controller.ModelState.AddModelError("error", "some error in the model state");

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

            Assert.Equal(createModel, result.Model);
            Assert.Equal("", result.ViewName);
        }
Пример #2
0
        public virtual ActionResult Create(CreateModel createModel)
        {
            if (!ModelState.IsValid)
            {
                createModel.ParentCourseList = GetParentCourseList();
                return View(createModel);
            }

            var course = _createModelToCourseMapper.Build(createModel);
            _genericRepository.Add(course);
            _genericRepository.Save();

            return RedirectToAction(Actions.Index());
        }
Пример #3
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());
        }
Пример #4
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"]);
        }
Пример #5
0
        public void ShouldMapCreateModelToCourse()
        {
            var schoolRepository = Substitute.For<ISchoolRepository>();
            schoolRepository.GetSchool().Returns(
                new School
                {
                    EducationOrganization = new EducationOrganization { EducationOrganizationId = 1 }
                });

            var parentCourse = new ParentCourseBuilder().Build();

            var courseCreateModel = new CreateModel
            {
                CourseCode = "CSC101",
                CourseTitle = "Intro to Programming",
                NumberOfParts = 1,
                AcademicSubject = AcademicSubjectDescriptorEnum.EnglishLanguageArts,
                CourseDescription = "Learnin some Java",
                DateCourseAdopted = new DateTime(2014, 07, 03),
                HighSchoolCourseRequirement = false,
                CourseGPAApplicability = CourseGPAApplicabilityTypeEnum.Applicable,
                CourseDefinedBy = CourseDefinedByTypeEnum.LEA,
                MinimumAvailableCreditType = CreditTypeEnum.Adulteducationcredit,
                MinimumAvailableCreditConversion = 3m,
                MinimumAvailableCredit = 3m,
                MaximumAvailableCreditType = CreditTypeEnum.CareerandTechnicalEducationcredit,
                MaximumAvailableCreditConversion = 3m,
                MaximumAvailableCredit = 3m,
                CareerPathway = CareerPathwayTypeEnum.AgricultureFoodandNaturalResources,
                TimeRequiredForCompletion = 10,
                ParentCourseId = parentCourse.Id
            };

            var genericRepository = Substitute.For<IGenericRepository>();
            genericRepository.Get(Arg.Any<Expression<Func<Web.Data.Entities.ParentCourse, bool>>>())
                .Returns(parentCourse);

            var createModelToCourseMapper = new CreateModelToCourseMapper(genericRepository, schoolRepository);
            var courseEntity = createModelToCourseMapper.Build(courseCreateModel);

            courseEntity.CourseCode.ShouldBe("CSC101");
            courseEntity.CourseTitle.ShouldBe("Intro to Programming");
            courseEntity.NumberOfParts.ShouldBe(1);
            courseEntity.AcademicSubjectDescriptorId.ShouldBe((int)AcademicSubjectDescriptorEnum.EnglishLanguageArts);
            courseEntity.CourseDescription.ShouldBe("Learnin some Java");
            courseEntity.DateCourseAdopted.ShouldBe(new DateTime(2014, 07, 03));
            courseEntity.HighSchoolCourseRequirement.ShouldBe(false);
            courseEntity.CourseGPAApplicabilityTypeId.ShouldBe((int)CourseGPAApplicabilityTypeEnum.Applicable);
            courseEntity.CourseDefinedByTypeId.ShouldBe((int)CourseDefinedByTypeEnum.LEA);
            courseEntity.MinimumAvailableCreditTypeId.ShouldBe((int)CreditTypeEnum.Adulteducationcredit);
            courseEntity.MinimumAvailableCreditConversion.ShouldBe(3m);
            courseEntity.MinimumAvailableCredit.ShouldBe(3m);
            courseEntity.MaximumAvailableCreditTypeId.ShouldBe((int)CreditTypeEnum.CareerandTechnicalEducationcredit);
            courseEntity.MaximumAvailableCreditConversion.ShouldBe(3m);
            courseEntity.MaximumAvailableCredit.ShouldBe(3m);
            courseEntity.CareerPathwayTypeId.ShouldBe((int)CareerPathwayTypeEnum.AgricultureFoodandNaturalResources);
            courseEntity.TimeRequiredForCompletion.ShouldBe(10);

            courseEntity.ParentCourseId.ShouldBe(parentCourse.Id);
            courseEntity.ParentCourse.ShouldBe(parentCourse);
        }
 public void HaveEnteredValidInputForAllFields()
 {
     _createCourseModel = new CreateCourseModelBuilder().Build();
     _courseIndexPage = _courseCreatePage.CreateCourse(_createCourseModel);
 }
Пример #7
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());
        }
Пример #8
0
        public void PostCreateShouldReturnItselfWhenModelStateIsInvalid()
        {
            var controller = SetUpController();
            var createModel = new CreateModel();
            controller.ModelState.AddModelError("error", "some error in the model state");

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

            Assert.Equal(createModel, result.Model);
            Assert.Equal("", result.ViewName);
        }
Пример #9
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"]);
        }
Пример #10
0
 private void Setup()
 {
     _genericRepository = Substitute.For<IGenericRepository>();
     _courseCreateModel = new CreateCourseModelBuilder().Build();
     _validator = new CreateModelValidator(new RepositoryReader<Web.Data.Entities.Course>(_genericRepository));
 }