Ejemplo n.º 1
0
        public async Task AboutPost()
        {
            var manageApi = new Mock <IManageApi>();

            var viewModel = new AboutCourseEnrichmentViewModel {
                AboutCourse = "AboutCourse", InterviewProcess = "InterviewProcess", HowSchoolPlacementsWork = "HowSchoolPlacementsWork"
            };

            var enrichmentModel = new CourseEnrichmentModel {
                AboutCourse = "", InterviewProcess = "", HowSchoolPlacementsWork = ""
            };
            var ucasCourseEnrichmentGetModel = new UcasCourseEnrichmentGetModel {
                EnrichmentModel = enrichmentModel
            };

            manageApi.Setup(x => x.GetCourseEnrichment(TestHelper.ProviderCode, TestHelper.TargetedProviderCode)).ReturnsAsync(ucasCourseEnrichmentGetModel);

            var tempDataMock  = new Mock <ITempDataDictionary>();
            var urlHelperMock = new Mock <IUrlHelper>();

            var previewLink = "preview-link";

            Expression <Func <IUrlHelper, string> > urlSetup = url => url.Action(It.Is <UrlActionContext>(uac => uac.Action == "Preview"));

            urlHelperMock.Setup(urlSetup).Returns(previewLink);

            var frontendUrlMock = new Mock <IFrontendUrlService>();
            var controller      = new CourseController(manageApi.Object, new SearchAndCompareUrlService("http://www.example.com"), frontendUrlMock.Object);

            controller.TempData = tempDataMock.Object;
            controller.Url      = urlHelperMock.Object;
            var result = await controller.AboutPost(TestHelper.ProviderCode, TestHelper.AccreditingProviderCode, TestHelper.TargetedProviderCode, viewModel);

            var redirectToActionResult = result as RedirectToActionResult;

            Assert.IsNotNull(redirectToActionResult);
            Assert.AreEqual("Show", redirectToActionResult.ActionName);

            var tempData = controller.TempData;

            VerifyTempDataIsSet(tempDataMock, previewLink);

            var routeValues = redirectToActionResult.RouteValues;

            Assert.AreEqual(TestHelper.ProviderCode, routeValues["providerCode"]);
            Assert.AreEqual(TestHelper.AccreditingProviderCode, routeValues["accreditingProviderCode"]);
            Assert.AreEqual(TestHelper.TargetedProviderCode, routeValues["courseCode"]);

            manageApi.Verify(x => x.SaveCourseEnrichment(TestHelper.ProviderCode, TestHelper.TargetedProviderCode, It.Is <CourseEnrichmentModel>(c => Check(c, viewModel))), Times.Once());
        }
Ejemplo n.º 2
0
        public async Task AboutPost_Invalid()
        {
            var manageApi = new Mock <IManageApi>();

            var viewModel = new AboutCourseEnrichmentViewModel {
                AboutCourse = "AboutCourse", InterviewProcess = "InterviewProcess", HowSchoolPlacementsWork = "HowSchoolPlacementsWork"
            };
            var testCourse = new Course()
            {
                Name = "Name", CourseCode = "CourseCode"
            };

            manageApi.Setup(x => x.GetCourse(TestHelper.ProviderCode, TestHelper.TargetedProviderCode)).ReturnsAsync(testCourse);

            var frontendUrlMock = new Mock <IFrontendUrlService>();
            var controller      = new CourseController(manageApi.Object, new SearchAndCompareUrlService("http://www.example.com"), frontendUrlMock.Object);

            controller.ModelState.AddModelError("you", "failed");

            var result = await controller.AboutPost(TestHelper.ProviderCode, TestHelper.AccreditingProviderCode, TestHelper.TargetedProviderCode, viewModel);

            var viewResult = result as ViewResult;

            Assert.IsNotNull(viewResult);
            Assert.AreEqual("About", viewResult.ViewName);

            var model = viewResult.Model as AboutCourseEnrichmentViewModel;

            Assert.IsNotNull(model);

            Assert.AreEqual(TestHelper.ProviderCode, model.RouteData.ProviderCode);
            Assert.AreEqual(TestHelper.TargetedProviderCode, model.RouteData.CourseCode);

            Assert.AreEqual(viewModel.AboutCourse, model.AboutCourse);
            Assert.AreEqual(viewModel.InterviewProcess, model.InterviewProcess);
            Assert.AreEqual(viewModel.HowSchoolPlacementsWork, model.HowSchoolPlacementsWork);
        }