예제 #1
0
        public async Task FeesPost()
        {
            var manageApi = new Mock <IManageApi>();

            var viewModel = new CourseFeesEnrichmentViewModel {
                FeeUkEu = 123, FeeInternational = 543, FeeDetails = "FeeDetails", CourseLength = CourseLength.TwoYears, FinancialSupport = "FinancialSupport"
            };

            var enrichmentModel = new CourseEnrichmentModel {
                FeeUkEu = 123.45m, FeeInternational = 543.21m, FeeDetails = "FeeDetails", CourseLength = null, FinancialSupport = "FinancialSupport"
            };

            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.FeesPost(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());
        }
예제 #2
0
        public async Task FeesPost_Invalid()
        {
            var manageApi = new Mock <IManageApi>();

            var viewModel = new CourseFeesEnrichmentViewModel {
                FeeUkEu = 123, FeeInternational = 543, FeeDetails = "FeeDetails", CourseLength = CourseLength.OneYear, FinancialSupport = "FinancialSupport"
            };

            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.FeesPost(TestHelper.ProviderCode, TestHelper.AccreditingProviderCode, TestHelper.TargetedProviderCode, viewModel);

            var viewResult = result as ViewResult;

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

            var model = viewResult.Model as CourseFeesEnrichmentViewModel;

            Assert.IsNotNull(model);

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

            Assert.AreEqual(viewModel.CourseLength, model.CourseLength);
            Assert.AreEqual(viewModel.FeeDetails, model.FeeDetails);
            Assert.AreEqual(viewModel.FeeInternational, model.FeeInternational);
            Assert.AreEqual(viewModel.FeeUkEu, model.FeeUkEu);
            Assert.AreEqual(viewModel.FinancialSupport, model.FinancialSupport);
        }