Exemplo n.º 1
0
        public void GetPage_ShouldThrowException_If_PageIsNull()
        {
            // Arrange
            var formSchema = new FormSchema
            {
                EnvironmentAvailabilities = new List <EnvironmentAvailability>
                {
                    new EnvironmentAvailability {
                        Environment = "Int",
                        IsAvailable = false
                    }
                }
            };

            _mockPageHelper.Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >())).Returns((Page)null);

            // Act & Assert
            var result = Assert.Throws <ApplicationException>(() => formSchema.GetPage(_mockPageHelper.Object, "path"));

            Assert.Contains("Requested path 'path' object could not be found or was not unique", result.Message);
        }
Exemplo n.º 2
0
        public async Task <ProcessRequestEntity> ProcessRequest(
            string form,
            string path,
            Dictionary <string, dynamic> viewModel,
            IEnumerable <CustomFormFile> files,
            bool modelStateIsValid)
        {
            FormSchema baseForm = await _schemaFactory.Build(form);

            if (!baseForm.IsAvailable(_environment.EnvironmentName))
            {
                throw new ApplicationException($"Form: {form} is not available in this Environment: {_environment.EnvironmentName.ToS3EnvPrefix()}");
            }

            var currentPage = baseForm.GetPage(_pageHelper, path);

            var sessionGuid = _sessionHelper.GetSessionGuid();

            if (sessionGuid == null)
            {
                throw new NullReferenceException($"Session guid null.");
            }

            if (currentPage == null)
            {
                throw new NullReferenceException($"Current page '{path}' object could not be found.");
            }

            if (currentPage.HasIncomingPostValues)
            {
                viewModel = _incomingDataHelper.AddIncomingFormDataValues(currentPage, viewModel);
            }

            currentPage.Validate(viewModel, _validators, baseForm);

            if (currentPage.Elements.Any(_ => _.Type == EElementType.Address))
            {
                return(await _addressService.ProcessAddress(viewModel, currentPage, baseForm, sessionGuid, path));
            }

            if (currentPage.Elements.Any(_ => _.Type == EElementType.Street))
            {
                return(await _streetService.ProcessStreet(viewModel, currentPage, baseForm, sessionGuid, path));
            }

            if (currentPage.Elements.Any(_ => _.Type == EElementType.Organisation))
            {
                return(await _organisationService.ProcessOrganisation(viewModel, currentPage, baseForm, sessionGuid, path));
            }

            if (currentPage.Elements.Any(_ => _.Type == EElementType.MultipleFileUpload))
            {
                return(await _fileUploadService.ProcessFile(viewModel, currentPage, baseForm, sessionGuid, path, files, modelStateIsValid));
            }

            if (currentPage.Elements.Any(_ => _.Type == EElementType.Booking))
            {
                return(await _bookingService.ProcessBooking(viewModel, currentPage, baseForm, sessionGuid, path));
            }

            _pageHelper.SaveAnswers(viewModel, sessionGuid, baseForm.BaseURL, files, currentPage.IsValid);

            if (!currentPage.IsValid)
            {
                var formModel = await _pageContentFactory.Build(currentPage, viewModel, baseForm, sessionGuid);

                return(new ProcessRequestEntity
                {
                    Page = currentPage,
                    ViewModel = formModel
                });
            }

            return(new ProcessRequestEntity
            {
                Page = currentPage
            });
        }
Exemplo n.º 3
0
        public async Task <SuccessPageEntity> Build(string form, FormSchema baseForm, string sessionGuid, FormAnswers formAnswers, EBehaviourType behaviourType)
        {
            var page = baseForm.GetPage(_pageHelper, "success");

            _distributedCache.Remove(sessionGuid);
            _sessionHelper.RemoveSessionGuid();

            if (page == null && behaviourType == EBehaviourType.SubmitAndPay)
            {
                page = GenerateGenericPaymentPage();
                baseForm.Pages.Add(page);
            }

            if (page == null)
            {
                return(new SuccessPageEntity
                {
                    ViewName = "Submit",
                    FormAnswers = formAnswers,
                    CaseReference = formAnswers.CaseReference,
                    FeedbackFormUrl = baseForm.FeedbackForm,
                    FeedbackPhase = baseForm.FeedbackPhase,
                    FormName = baseForm.FormName,
                    StartPageUrl = baseForm.StartPageUrl
                });
            }

            if (baseForm.DocumentDownload)
            {
                baseForm.DocumentType.ForEach((docType) =>
                {
                    var element = new ElementBuilder()
                                  .WithType(EElementType.DocumentDownload)
                                  .WithLabel($"Download {docType} document")
                                  .WithSource($"/v2/document/Summary/{docType}/{sessionGuid}")
                                  .WithDocumentType(docType)
                                  .Build();

                    page.Elements.Add(element);
                });
                var successIndex = baseForm.Pages.IndexOf(page);
                baseForm.Pages[successIndex] = page;
            }

            var result = await _pageFactory.Build(page, new Dictionary <string, dynamic>(), baseForm, sessionGuid, formAnswers);

            return(new SuccessPageEntity
            {
                HtmlContent = result.RawHTML,
                CaseReference = formAnswers.CaseReference,
                FeedbackFormUrl = result.FeedbackForm,
                FeedbackPhase = result.FeedbackPhase,
                FormName = result.FormName,
                StartPageUrl = result.StartPageUrl,
                PageTitle = result.PageTitle,
                BannerTitle = page.BannerTitle,
                LeadingParagraph = page.LeadingParagraph,
                DisplayBreadcrumbs = page.DisplayBreadCrumbs,
                Breadcrumbs = baseForm.BreadCrumbs
            });
        }