public async Task ProcessOrganisation_Application_ShouldThrowApplicationException_WhenOrganisationProvider_ThrowsException()
        {
            _organisationProvider.Setup(_ => _.SearchAsync(It.IsAny <string>())).Throws <Exception>();

            var element = new ElementBuilder()
                          .WithType(EElementType.Organisation)
                          .WithOrganisationProvider(EOrganisationProvider.Fake.ToString())
                          .WithQuestionId("test-address")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .WithValidatedModel(true)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                { "Guid", Guid.NewGuid().ToString() },
                { "subPath", "" },
                { element.Properties.QuestionId, _searchModel.SearchTerm },
            };

            var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessOrganisation(viewModel, page, schema, "", "page-one"));

            _organisationProvider.Verify(_ => _.SearchAsync(It.IsAny <string>()), Times.Once);
            _pageHelper.Verify(_ => _.GenerateHtml(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), It.IsAny <List <object> >()), Times.Never);
            Assert.StartsWith($"OrganisationService.ProccessInitialOrganisation:: An exception has occured while attempting to perform organisation lookup, Exception: ", result.Message);
        }
        public async Task Build_ShouldReturn_Correct_StartPageUrl()
        {
            // Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.H2)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithStartPageUrl("page-one")
                             .WithBaseUrl("base-test")
                             .WithPage(page)
                             .Build();

            _mockPageContentFactory
            .Setup(_ => _.Build(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), It.IsAny <List <object> >()))
            .ReturnsAsync(new FormBuilderViewModel());

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

            // Act
            var result = await _factory.Build(string.Empty, formSchema, string.Empty, new FormAnswers(), EBehaviourType.SubmitForm);

            // Assert
            Assert.Equal(formSchema.StartPageUrl, result.StartPageUrl);
        }
Ejemplo n.º 3
0
        public void Validate_Should_Return_Error_WhenSummarySection_IsMissingTitle()
        {
            // Arrange
            var section = new Section
            {
                Pages = new List <string> {
                    "test-page"
                }
            };

            var element = new ElementBuilder()
                          .WithType(EElementType.Summary)
                          .withSummarySection(section)
                          .Build();

            var page1 = new PageBuilder()
                        .WithPageSlug("test-page")
                        .WithElement(element)
                        .Build();

            var schema = new FormSchemaBuilder()
                         .WithName("test-name")
                         .WithPage(page1)
                         .Build();

            // Act
            var result = _validator.Validate(schema);

            // Assert
            Assert.False(result.IsValid);
            Assert.Single(result.Messages);
            Assert.Equal($"{IntegrityChecksConstants.FAILURE}FormSchemaIntegrityCheck::SummaryFormCheck, Summary section is defined but section title is empty. Please add a title for the section.", result.Messages.First());
        }
Ejemplo n.º 4
0
        public async Task RenderAsync_ShouldCall_ElementHelper_ToGetCurrentValue_ForAddressFields()
        {
            //Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.AddressManual)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var viewModel = new Dictionary <string, dynamic> {
                { AddressManualConstants.POSTCODE, "sk11aa" }
            };

            var schema = new FormSchemaBuilder()
                         .WithName("form-name")
                         .Build();

            var formAnswers = new FormAnswers();
            //Act
            var result = await element.RenderAsync(
                _mockIViewRender.Object,
                _mockElementHelper.Object,
                string.Empty,
                viewModel,
                page,
                schema,
                _mockHostingEnv.Object,
                formAnswers);

            //Assert
            _mockIViewRender.Verify(_ => _.RenderAsync(It.Is <string>(x => x == "AddressManual"), It.IsAny <form_builder.Models.Elements.AddressManual>(), It.IsAny <Dictionary <string, object> >()), Times.Once);
            _mockElementHelper.Verify(_ => _.CurrentValue(It.IsAny <string>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormAnswers>(), It.IsAny <string>()), Times.Exactly(4));
        }
Ejemplo n.º 5
0
        public async Task RenderAsync_ShouldCall_PageHelper_ToGetCurrentValue()
        {
            //Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.Map)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var viewModel = new Dictionary <string, dynamic>();

            var schema = new FormSchemaBuilder()
                         .WithName("form-name")
                         .Build();

            var formAnswers = new FormAnswers();

            //Act
            await element.RenderAsync(
                _mockIViewRender.Object,
                _mockElementHelper.Object,
                string.Empty,
                viewModel,
                page,
                schema,
                _mockHostingEnv.Object,
                formAnswers);

            //Assert
            _mockIViewRender.Verify(_ => _.RenderAsync(It.Is <string>(x => x.Equals("Map")), It.IsAny <Map>(), It.IsAny <Dictionary <string, object> >()), Times.Once);
            _mockElementHelper.Verify(_ => _.CurrentValue <object>(It.IsAny <string>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormAnswers>(), It.IsAny <string>()), Times.Once);
        }
Ejemplo n.º 6
0
        public async Task ProcessAddress_Application_ShouldThrowApplicationException_WhenAddressProvider_ThrowsException()
        {
            _addressProvider.Setup(_ => _.SearchAsync(It.IsAny <string>()))
            .Throws <Exception>();

            var testAddressProvider = "testAddressProvider";

            var element = new ElementBuilder()
                          .WithType(EElementType.Address)
                          .WithAddressProvider(testAddressProvider)
                          .WithQuestionId("test-address")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .WithValidatedModel(true)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                { "Guid", Guid.NewGuid().ToString() },
                { $"{element.Properties.QuestionId}-postcode", "SK11aa" },
            };

            var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessAddress(viewModel, page, schema, "", "page-one"));

            _addressProvider.Verify(_ => _.SearchAsync(It.IsAny <string>()), Times.Once);
            _pageHelper.Verify(_ => _.GenerateHtml(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), It.IsAny <List <object> >()), Times.Never);
            Assert.StartsWith($"AddressService::ProcessSearchAddress, An exception has occured while attempting to perform postcode lookup on Provider '{testAddressProvider}' with searchterm 'SK11aa' Exception:", result.Message);
        }
Ejemplo n.º 7
0
        public void CheckUploadedFilesSummaryQuestionsIsSet_ShouldThrowException_WhenElementDoNotContain_Required_Text()
        {
            // Arrange
            var pages = new List <Page>();

            var element = new ElementBuilder()
                          .WithType(EElementType.UploadedFilesSummary)
                          .WithPropertyText(string.Empty)
                          .WithFileUploadQuestionIds(new List <string> {
                ""
            })
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithName("test-name")
                         .WithPage(page)
                         .Build();

            // Act
            var check  = new UploadedFilesSummaryQuestionsIsSetCheck();
            var result = check.Validate(element);

            // Assert
            Assert.False(result.IsValid);
            Assert.Collection <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message));
        }
Ejemplo n.º 8
0
        public async Task ProcessBooking_Should_Process_CheckYourBookingPage_And_ReserveBooking()
        {
            var appointmentTypeGuid = new Guid();
            var element             = new ElementBuilder()
                                      .WithType(EElementType.Booking)
                                      .WithBookingProvider("testBookingProvider")
                                      .WithQuestionId("bookingQuestion")
                                      .WithAppointmentType(appointmentTypeGuid)
                                      .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithValidatedModel(true)
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithBaseUrl("base-form")
                             .Build();

            var model = new Dictionary <string, object> {
                { LookUpConstants.SubPathViewModelKey, BookingConstants.CHECK_YOUR_BOOKING },
                { $"{element.Properties.QuestionId}-{BookingConstants.APPOINTMENT_DATE}", DateTime.Now.ToString() },
                { $"{element.Properties.QuestionId}-{BookingConstants.APPOINTMENT_START_TIME}", DateTime.Now.ToString() },
                { $"{element.Properties.QuestionId}-{BookingConstants.APPOINTMENT_END_TIME}", DateTime.Now.ToString() }
            };

            await _service.ProcessBooking(model, page, formSchema, "guid", "path");

            _bookingProvider.Verify(_ => _.Reserve(It.IsAny <BookingRequest>()), Times.Once);
            _mockMappingService.Verify(_ => _.MapBookingRequest(It.IsAny <string>(), It.IsAny <IElement>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <string>()), Times.Once);
            _mockPageHelper.Verify(_ => _.SaveAnswers(It.IsAny <Dictionary <string, object> >(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IEnumerable <CustomFormFile> >(), It.IsAny <bool>(), It.IsAny <bool>()), Times.Once);
        }
Ejemplo n.º 9
0
        public void GetPage_ShouldReturnPageImmediately_IfOnlyOnePageFound()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToPage)
                            .WithPageSlug("test-test")
                            .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithPageSlug("success")
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithBaseUrl("baseUrl")
                             .WithName("form name")
                             .WithStartPageUrl("page1")
                             .WithPage(page)
                             .Build();

            // Act
            formSchema.GetPage(_mockPageHelper.Object, "success");

            // Assert
            _mockPageHelper.Verify(_ => _.CheckRenderConditionsValid(It.IsAny <List <Page> >()), Times.Never);
        }
Ejemplo n.º 10
0
        public async Task ProcessMonthRequest_ShouldThrow_ApplicationException_WhenViewModelDoes_NotContainRequestedMonth()
        {
            // Act
            var guid = Guid.NewGuid();

            var element = new ElementBuilder()
                          .WithType(EElementType.Booking)
                          .WithBookingProvider("testBookingProvider")
                          .WithQuestionId("bookingQuestion")
                          .WithAppointmentType(guid)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithBaseUrl("base-form")
                             .Build();

            // Assert
            var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessMonthRequest(new Dictionary <string, object>(), formSchema, page, "guid"));

            _bookingProvider.Verify(_ => _.GetAvailability(It.IsAny <AvailabilityRequest>()), Times.Never);
            _mockPageHelper.Verify(_ => _.SaveFormData(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            _mockDistributedCache.Verify(_ => _.GetString(It.IsAny <string>()), Times.Never);
            Assert.Equal("BookingService::ProcessMonthRequest, request for appointment did not contain requested month", result.Message);
        }
Ejemplo n.º 11
0
        public async Task ProcessMonthRequest_ShouldThrow_ApplicationException_When_RequestedMonth_IsBefore_Today()
        {
            // Act
            var guid = Guid.NewGuid();

            var element = new ElementBuilder()
                          .WithType(EElementType.Booking)
                          .WithBookingProvider("testBookingProvider")
                          .WithQuestionId("bookingQuestion")
                          .WithAppointmentType(guid)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithBaseUrl("base-form")
                             .Build();

            var model = new Dictionary <string, object> {
                { BookingConstants.BOOKING_MONTH_REQUEST, DateTime.Now.AddMonths(-1).ToString() }
            };

            // Assert
            var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessMonthRequest(model, formSchema, page, "guid"));

            _bookingProvider.Verify(_ => _.GetAvailability(It.IsAny <AvailabilityRequest>()), Times.Never);
            _mockPageHelper.Verify(_ => _.SaveFormData(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            _mockDistributedCache.Verify(_ => _.GetString(It.IsAny <string>()), Times.Never);
            Assert.Equal("BookingService::ProcessMonthRequest, Invalid request for appointment search, Start date provided is before today", result.Message);
        }
        public async Task ProcessFile_ProcessSelectedFiles_ShouldCallPageFactory_IfModelStateInvalid()
        {
            // Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.MultipleFileUpload)
                          .WithQuestionId("fileUpload")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithValidatedModel(true)
                       .WithPageSlug("page-one")
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .WithBaseUrl("baseUrl")
                         .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                {
                    "Submit", "Submit"
                }
            };

            // Act
            var result = await _service.ProcessFile(viewModel, page, schema,
                                                    new Guid().ToString(), It.IsAny <string>(), null, false);

            // Assert
            _mockPageFactory.Verify(_ => _.Build(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), null), Times.Once);
            Assert.IsType <ProcessRequestEntity>(result);
            Assert.True(result.UseGeneratedViewModel);
        }
        public async Task ProcessFile_RemoveFile_ShouldRemoveFileFromResponse()
        {
            // Arrange
            var callbackCacheProvider = string.Empty;
            var cachedAnswers         =
                "{\"FormName\":\"file-upload\",\"Path\":\"page-one\",\"CaseReference\":null,\"StartPageUrl\":null,\"FormData\":{},\"AdditionalFormData\":{},\"Pages\":[{\"PageSlug\":\"page-one\",\"Answers\":[{\"QuestionId\":\"fileUpload-fileupload\",\"Response\":[{\"Key\":\"file-fileUpload-fileupload-b3df0129-c527-4fb8-8cd6-e35e622116f6\",\"TrustedOriginalFileName\":\"SMBC.png\",\"UntrustedOriginalFileName\":\"SMBC.png\",\"Content\":null,\"FileSize\":26879,\"FileName\":null}]}]}]}";

            var updatedAnswers =
                "{\"FormName\":\"file-upload\",\"Path\":\"page-one\",\"CaseReference\":null,\"StartPageUrl\":null,\"FormData\":{},\"AdditionalFormData\":{},\"Pages\":[{\"PageSlug\":\"page-one\",\"Answers\":[{\"QuestionId\":\"fileUpload-fileupload\",\"Response\":[]}]}]}";

            var viewModel = new Dictionary <string, dynamic>
            {
                { $"{FileUploadConstants.FILE_TO_DELETE}", "SMBC.png" }
            };

            var formSchema = new FormSchemaBuilder()
                             .WithBaseUrl("file-upload")
                             .Build();

            _mockDistributedCache.Setup(_ => _.GetString(It.IsAny <string>()))
            .Returns(cachedAnswers);

            _mockDistributedCache.Setup(_ =>
                                        _.SetStringAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((x, y, z) => callbackCacheProvider = y);

            // Act
            var result = await _service.ProcessFile(viewModel, It.IsAny <Page>(), formSchema, Guid.NewGuid().ToString(), "page-one", null, true);

            // Assert
            _mockDistributedCache.Verify(_ => _.SetStringAsync(It.IsAny <string>(), updatedAnswers, CancellationToken.None), Times.Once);
            Assert.IsType <ProcessRequestEntity>(result);
        }
Ejemplo n.º 14
0
        public void IncomingFormDataValuesCheck_IsNotValid_WhenActionType_IsUnknown()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToPage)
                            .WithPageSlug("test-test")
                            .Build();

            var incomingValueWithNoType = new IncomingValuesBuilder()
                                          .WithQuestionId("testQuestionId")
                                          .WithName("test-value")
                                          .WithHttpActionType(EHttpActionType.Unknown)
                                          .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithIncomingValue(incomingValueWithNoType)
                       .WithPageTitle("test-page")
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .WithName("test-form")
                         .Build();

            IncomingFormDataValuesCheck check = new();

            // Act & Assert
            var result = check.Validate(schema);

            Assert.False(result.IsValid);
            Assert.Collection <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message));
        }
Ejemplo n.º 15
0
        public async Task ProcessAddress_ShouldCall_PageHelper_ToProcessSearchResults()
        {
            var element = new ElementBuilder()
                          .WithType(EElementType.Address)
                          .WithQuestionId("test-address")
                          .WithAddressProvider("testAddressProvider")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .WithValidatedModel(true)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .Build();

            _pageHelper.Setup(_ => _.GenerateHtml(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), It.IsAny <List <object> >()))
            .ReturnsAsync(new FormBuilderViewModel());

            var viewModel = new Dictionary <string, dynamic>
            {
                { "Guid", Guid.NewGuid().ToString() },
                { $"{element.Properties.QuestionId}-postcode", "SK11aa" },
            };

            await _service.ProcessAddress(viewModel, page, schema, "", "page-one");

            _addressProvider.Verify(_ => _.SearchAsync(It.IsAny <string>()), Times.Once);
        }
Ejemplo n.º 16
0
        public BookingControllerTests()
        {
            var element = new ElementBuilder()
                          .WithType(EElementType.Booking)
                          .WithQuestionId("valid")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithValidatedModel(true)
                       .WithPageSlug("valid")
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .Build();

            _schemaFactory.Setup(_ => _.Build("valid"))
            .ReturnsAsync(schema);

            _bookingController = new BookingController(_bookingService.Object, _schemaFactory.Object, _pageHelper.Object, _sessionHelper.Object);
            _bookingController.ControllerContext             = new ControllerContext();
            _bookingController.ControllerContext.HttpContext = new DefaultHttpContext();
            _bookingController.ControllerContext.HttpContext.Request.Query = new QueryCollection();
        }
Ejemplo n.º 17
0
        public async Task ProcessAddress_Application_ShouldThrowApplicationException_WhenNoMatchingAddressProvider()
        {
            var addressProvider = "NON-EXIST-PROVIDER";
            var element         = new ElementBuilder()
                                  .WithType(EElementType.Address)
                                  .WithAddressProvider(addressProvider)
                                  .WithQuestionId("test-address")
                                  .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .WithValidatedModel(true)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                { "Guid", Guid.NewGuid().ToString() },
                { $"{element.Properties.QuestionId}-postcode", "SK11aa" },
            };

            var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessAddress(viewModel, page, schema, "", "page-one"));

            _addressProvider.Verify(_ => _.SearchAsync(It.IsAny <string>()), Times.Never);
            Assert.Equal($"AddressService::ProcessSearchAddress, An exception has occured while attempting to perform postcode lookup on Provider '{addressProvider}' with searchterm 'SK11aa' Exception:", result.Message);
        }
Ejemplo n.º 18
0
        CheckRetrieveExternalDataAction_ShouldThrowException_WhenActionDoesNotContain_URL_or_TargetQuestionId(string url, string questionId, string env, string message)
        {
            // Arrange
            var action = new ActionBuilder()
                         .WithActionType(EActionType.RetrieveExternalData)
                         .WithPageActionSlug(new PageActionSlug
            {
                URL         = url,
                Environment = env
            })
                         .WithTargetQuestionId(questionId)
                         .Build();

            var schema = new FormSchemaBuilder()
                         .WithFormActions(action)
                         .Build();

            var check = new RetrieveExternalActionsCheck(_mockHostingEnv.Object);

            // Act & Assert
            var result = check.Validate(schema);

            Assert.False(result.IsValid);
            Assert.Contains(message, result.Messages);
        }
Ejemplo n.º 19
0
        public async Task ProcessStreet_Application_ShouldThrowApplicationException_WhenStreetProvider_ThrowsException()
        {
            _streetProvider.Setup(_ => _.SearchAsync(It.IsAny <string>())).Throws <Exception>();
            var fakeStreetProvider = EStreetProvider.Fake.ToString();

            var element = new ElementBuilder()
                          .WithType(EElementType.Street)
                          .WithQuestionId("street")
                          .WithStreetProvider(fakeStreetProvider)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .WithValidatedModel(true)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                { "Guid", Guid.NewGuid().ToString() },
                { "subPath", "" },
                { element.Properties.QuestionId, "streetname" },
            };

            var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessStreet(viewModel, page, schema, "", "page-one"));

            _streetProvider.Verify(_ => _.SearchAsync(It.IsAny <string>()), Times.Once);
            _pageHelper.Verify(_ => _.GenerateHtml(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), It.IsAny <List <object> >()), Times.Never);
            Assert.StartsWith($"StreetService::ProccessInitialStreet: An exception has occured while attempting to perform street lookup on Provider '{fakeStreetProvider}' with searchterm 'streetname' Exception:", result.Message);
        }
Ejemplo n.º 20
0
        public SuccessWorkflowTests()
        {
            _workflow = new SuccessWorkflow(_mockPageService.Object, _mockSchemaFactory.Object, _mockActionsWorkflow.Object);

            var element = new ElementBuilder()
                          .WithType(EElementType.H2)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("success")
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithDocumentDownload(true)
                             .WithDocumentType(EDocumentType.Txt)
                             .WithStartPageUrl("page-one")
                             .WithBaseUrl("base-test")
                             .WithPage(page)
                             .Build();

            _mockSchemaFactory
            .Setup(_ => _.Build(It.IsAny <string>()))
            .ReturnsAsync(formSchema);

            _mockPageService
            .Setup(_ => _.FinalisePageJourney(It.IsAny <string>(), EBehaviourType.SubmitForm, It.IsAny <FormSchema>()))
            .ReturnsAsync(new SuccessPageEntity
            {
                FormAnswers = new FormAnswers()
            });
        }
        public void GetReducedAnswers_ShouldReturnPageAnswers_ThatExistInSchema()
        {
            // Arrange
            var formAnswers = new FormAnswers
            {
                Pages = new List <PageAnswers>
                {
                    new PageAnswers
                    {
                        Answers  = new List <Answers>(),
                        PageSlug = "page-1"
                    },
                    new PageAnswers
                    {
                        Answers  = new List <Answers>(),
                        PageSlug = "page-2"
                    },
                    new PageAnswers
                    {
                        Answers  = new List <Answers>(),
                        PageSlug = "page-3"
                    }
                }
            };

            var formSchema = new FormSchemaBuilder()
                             .WithPage(new Page
            {
                PageSlug   = "page-1",
                Behaviours = new List <Behaviour>
                {
                    new Behaviour
                    {
                        BehaviourType = EBehaviourType.GoToPage,
                        PageSlug      = "page-3"
                    }
                }
            })
                             .WithPage(new Page
            {
                PageSlug   = "page-2",
                Behaviours = new List <Behaviour>
                {
                    new Behaviour
                    {
                        BehaviourType = EBehaviourType.GoToPage,
                        PageSlug      = "page-3"
                    }
                }
            }
                                       )
                             .WithFirstPageSlug("page-1")
                             .Build();

            // Act
            var result = formAnswers.GetReducedAnswers(formSchema);

            // Assert
            Assert.Single(result);
        }
Ejemplo n.º 22
0
        public async Task Process_ShouldCallActionService()
        {
            // Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.H2)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("success")
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithDocumentDownload(true)
                             .WithDocumentType(EDocumentType.Txt)
                             .WithStartPageUrl("page-one")
                             .WithBaseUrl("base-test")
                             .WithPage(page)
                             .WithFormActions(new UserEmail
            {
                Properties = new BaseActionProperty(),
                Type       = EActionType.UserEmail
            })
                             .Build();

            _mockSchemaFactory.Setup(_ => _.Build(It.IsAny <string>())).ReturnsAsync(formSchema);

            // Act
            await _workflow.Process(EBehaviourType.SubmitForm, "form");

            // Assert
            _mockActionsWorkflow.Verify(_ => _.Process(It.IsAny <List <IAction> >(), It.IsAny <FormSchema>(), It.IsAny <string>()), Times.Once);
        }
Ejemplo n.º 23
0
        public void ConditionalElementsAreValidCheck_IsNotValid_NoConditionalElement(
            EElementType elementType,
            string conditionalElementId)
        {
            // Arrange
            var option1 = new Option {
                ConditionalElementId = conditionalElementId, Value = "Value1"
            };
            var element1 = new ElementBuilder()
                           .WithType(elementType)
                           .WithOptions(new List <Option> {
                option1
            })
                           .Build();

            var page = new PageBuilder()
                       .WithElement(element1)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .WithName("test-name")
                         .Build();

            // Act
            ConditionalElementCheck check = new();
            var result = check.Validate(schema);

            // Assert
            Assert.False(result.IsValid);
            Assert.All <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message));
        }
Ejemplo n.º 24
0
        public async Task RenderAsync_ShouldDisableButton_OnClick_WhenPropertyIsEnabled()
        {
            //Arrange
            var callback = new Button();

            _mockIViewRender.Setup(_ => _.RenderAsync(It.IsAny <string>(), It.IsAny <Button>(), It.IsAny <Dictionary <string, dynamic> >()))
            .Callback <string, Button, Dictionary <string, dynamic> >((a, b, c) => callback = b);

            var element = new ElementBuilder()
                          .WithType(EElementType.Button)
                          .WithPropertyText("test text")
                          .WithDisableOnClick(true)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithName("form-name")
                         .Build();

            var formAnswers = new FormAnswers();

            var viewModel = new Dictionary <string, dynamic>();

            //Act
            await element.RenderAsync(_mockIViewRender.Object, _mockElementHelper.Object, string.Empty, viewModel, page, schema, _mockHostingEnv.Object, formAnswers);

            //Assert
            Assert.True(callback.Properties.DisableOnClick);
            _mockIViewRender.Verify(_ => _.RenderAsync(It.Is <string>(x => x.Equals("Button")), It.IsAny <Button>(), It.IsAny <Dictionary <string, object> >()), Times.Once);
        }
Ejemplo n.º 25
0
        public async Task RenderAsync_ShouldCallGenerateDocumentUploadUrl_Base64StringCaseRef()
        {
            //Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.DocumentUpload)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var viewModel = new Dictionary <string, dynamic>();

            var schema = new FormSchemaBuilder()
                         .WithName("form-name")
                         .Build();

            var formAnswers = new FormAnswers();

            //Act
            await element.RenderAsync(
                _mockIViewRender.Object,
                _mockElementHelper.Object,
                string.Empty,
                viewModel,
                page,
                schema,
                _mockHostingEnv.Object,
                formAnswers);

            //Assert
            _mockIViewRender.Verify(_ => _.RenderAsync(It.Is <string>(x => x.Equals("DocumentUpload")), It.IsAny <DocumentUpload>(), It.IsAny <Dictionary <string, object> >()), Times.Once);
            _mockElementHelper.Verify(_ => _.GenerateDocumentUploadUrl(It.IsAny <Element>(), It.IsAny <FormSchema>(), It.IsAny <FormAnswers>()), Times.Once);
        }
Ejemplo n.º 26
0
        public async Task Build_ShouldCallCache_ToGetCurrentFormAnswers_WhenFormAnswers_AreNull()
        {
            // Arrange
            _mockPageHelper.Setup(_ => _.GenerateHtml(
                It.IsAny<Page>(),
                It.IsAny<Dictionary<string, dynamic>>(),
                It.IsAny<FormSchema>(),
                It.IsAny<string>(),
                It.IsAny<FormAnswers>(),
                It.IsAny<List<object>>()))
                .ReturnsAsync(new FormBuilderViewModel { RawHTML = string.Empty });

            var formSchema = new FormSchemaBuilder()
                .WithBaseUrl("base")
                .WithName("form name")
                .Build();

            var page = new PageBuilder()
                .WithPageSlug("page-one")
                .Build();

            // Act
            await _factory.Build(page, new Dictionary<string, dynamic>(), formSchema, string.Empty);

            // Assert
            _mockDistributedCacheWrapper.Verify(_ => _.GetString(It.IsAny<string>()), Times.Once);
        }
        public async Task Build_ShouldDeleteCacheEntry()
        {
            // Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.H2)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithStartPageUrl("page-one")
                             .WithBaseUrl("base-test")
                             .WithPage(page)
                             .Build();

            var guid = new Guid();

            // Act
            await _factory.Build(string.Empty, formSchema, guid.ToString(), new FormAnswers(), EBehaviourType.SubmitForm);

            // Assert
            _mockSessionHelper.Verify(_ => _.RemoveSessionGuid(), Times.Once);
            _mockDistributedCache.Verify(_ => _.Remove(It.Is <string>(x => x == guid.ToString())), Times.Once);
        }
Ejemplo n.º 28
0
        public async Task Build_ShouldCall_Parse_On_TagParsers()
        {
            // Arrange
            _tagParser.Setup(_ => _.Parse(It.IsAny<Page>(), It.IsAny<FormAnswers>()))
                .Returns(new Page());
            var tagParserItems = new List<ITagParser> { _tagParser.Object, _tagParser.Object };
            _mockTagParsers.Setup(m => m.GetEnumerator()).Returns(() => tagParserItems.GetEnumerator());

            _mockPageHelper.Setup(_ => _.GenerateHtml(
                It.IsAny<Page>(),
                It.IsAny<Dictionary<string, dynamic>>(),
                It.IsAny<FormSchema>(),
                It.IsAny<string>(),
                It.IsAny<FormAnswers>(),
                It.IsAny<List<object>>()))
                .ReturnsAsync(new FormBuilderViewModel { RawHTML = string.Empty });

            var formSchema = new FormSchemaBuilder()
                .WithBaseUrl("base")
                .WithName("form name")
                .Build();

            var formAnswers = new FormAnswers();

            var page = new PageBuilder()
                .WithPageSlug("page-one")
                .Build();

            // Act
            await _factory.Build(page, new Dictionary<string, dynamic>(), formSchema, string.Empty, formAnswers);

            // Assert
            _tagParser.Verify(_ => _.Parse(It.IsAny<Page>(), It.IsAny<FormAnswers>()), Times.Exactly(2));
        }
Ejemplo n.º 29
0
        public void Validate_Should_Return_Error_WhenSummarySection_Has_NoPages_Defined_InSection()
        {
            // Arrange
            var section = new Section
            {
                Title = "section title"
            };

            var element = new ElementBuilder()
                          .WithType(EElementType.Summary)
                          .withSummarySection(section)
                          .Build();

            var page1 = new PageBuilder()
                        .WithPageSlug("test-page")
                        .WithElement(element)
                        .Build();

            var schema = new FormSchemaBuilder()
                         .WithName("test-name")
                         .WithPage(page1)
                         .Build();

            // Act
            var result = _validator.Validate(schema);

            // Assert
            Assert.False(result.IsValid);
            Assert.Single(result.Messages);
            Assert.Equal($"{IntegrityChecksConstants.FAILURE}FormSchemaIntegrityCheck::SummaryFormCheck, Summary section is defined but no pages have been specified to appear in the section.", result.Messages.First());
        }
Ejemplo n.º 30
0
        public void GenerateQuestionAndAnswersList_ShouldReturn_ListWithSingleItem_For_ElementType(EElementType type)
        {
            // Arrange
            var value = "value";

            _mockElementMapper
            .Setup(_ => _.GetAnswerStringValue(It.IsAny <IElement>(), It.IsAny <FormAnswers>()))
            .Returns(value);

            var formAnswers = new FormAnswers {
                Pages = new List <PageAnswers>()
            };
            var labelText = "I am a label";

            var element = new ElementBuilder()
                          .WithType(type)
                          .WithQuestionId("testQuestion")
                          .WithLabel(labelText)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithPage(page)
                             .Build();

            // Act
            var result = _documentCreation.GenerateQuestionAndAnswersList(formAnswers, formSchema);

            Assert.Equal(2, result.Count);
            Assert.Equal($"{labelText}: {value}", result[0]);
        }