Пример #1
0
        public void IsAvailable_ShouldReturn_True_WhenNoEnvironmentAvailabilitiesAreSpecified()
        {
            // Arrange
            var formSchema = new FormSchema();

            // Act
            var result = formSchema.IsAvailable("Int");

            // Assert
            Assert.True(result);
        }
Пример #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
            });
        }