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)); }
public void GetNextPage_ShouldReturn_BehaviourSubmit_WhenMix_OfMultipleEqualAndCheckbox_WithinSameBehaviour() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithCondition(new Condition { EqualTo = "apple", QuestionId = "test" }) .WithCondition(new Condition { CheckboxContains = "berry", QuestionId = "data" }) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .Build(); var viewModel = new Dictionary <string, dynamic> { { "test", "pear" }, { "data", "berry" } }; // Act var result = page.GetNextPage(viewModel); // Assert Assert.Equal(EBehaviourType.SubmitForm, result.BehaviourType); }
public void GetNextPage_ShouldReturn_CorrectBehaviour_When_MixedConditions_Submit_And_EqualTo() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithCondition(new Condition { EqualTo = "apple", QuestionId = "test" }) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .Build(); var viewModel = new Dictionary <string, dynamic> { { "test", "apple" } }; // Act var result = page.GetNextPage(viewModel); // Assert Assert.Equal(EBehaviourType.GoToPage, result.BehaviourType); }
public void RenderConditionsValidCheck_IsNotValid_If_TwoOrMorePagesWithTheSameSlug_HaveEmptyRenderConditions() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("success") .Build(); var page2 = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("success") .Build(); page.RenderConditions = new List <Condition>(); page2.RenderConditions = new List <Condition>(); var schema = new FormSchemaBuilder() .WithName("test-name") .WithPage(page) .WithPage(page2) .Build(); // Act var check = new RenderConditionsValidCheck(); var result = check.Validate(schema); // Assert Assert.False(result.IsValid); Assert.Contains($"FAILURE - Render Conditions Valid Check, More than one {page.PageSlug} page has no render conditions", result.Messages); }
public async Task PaymentConfigurationCheck_IsNotValid_WhenConfigFound_ForForm_ButStaticAmountAndCalculationSlugsAreNotSet() { // Arrange _mockPaymentConfigProvider .Setup(_ => _.Get <List <PaymentInformation> >()) .ReturnsAsync(new List <PaymentInformation> { new PaymentInformation { FormName = "test-name", PaymentProvider = "testProvider", Settings = new Settings() } }); var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .Build(); var schema = new FormSchemaBuilder() .WithPage(page) .WithName("test-name") .WithBaseUrl("test-name") .Build(); // Act var check = new PaymentConfigurationCheck(_mockHostingEnv.Object, _mockPaymentProviders.Object, _mockPaymentConfigProvider.Object); // Assert var result = await check.ValidateAsync(schema); Assert.False(result.IsValid); }
public async Task PaymentConfigurationCheck_IsNotValid_WhenNoConfigFound_ForForm() { // Arrange _mockPaymentConfigProvider .Setup(_ => _.Get <List <PaymentInformation> >()) .ReturnsAsync(new List <PaymentInformation>()); var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .Build(); var schema = new FormSchemaBuilder() .WithPage(page) .WithName("test-name") .Build(); var check = new PaymentConfigurationCheck(_mockHostingEnv.Object, _mockPaymentProviders.Object, _mockPaymentConfigProvider.Object); // Assert var result = await check.ValidateAsync(schema); Assert.False(result.IsValid); Assert.Collection <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message)); }
public void GetNextPage_ShouldReturn_SubmitBehaviour_WhenMultipleSubmitForms() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithPageSlug("submit-one") .WithCondition(new Condition { EqualTo = "apple", QuestionId = "test" }) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithPageSlug("submit-two") .WithCondition(new Condition { CheckboxContains = "pear", QuestionId = "test" }) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .Build(); var viewModel = new Dictionary <string, dynamic> { { "test", "pear" } }; // Act var result = page.GetNextPage(viewModel); // Assert Assert.Equal(EBehaviourType.SubmitForm, result.BehaviourType); Assert.Equal("submit-two", result.PageSlug); }
public void GetNextPage_ShouldReturn_Behaviour_WhenCheckboxContains_Condition_True() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToExternalPage) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithCondition(new Condition { CheckboxContains = "value", QuestionId = "test" }) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .Build(); var viewModel = new Dictionary <string, dynamic> { { "test", "value" } }; // Act var result = page.GetNextPage(viewModel); // Assert Assert.Equal(EBehaviourType.GoToPage, result.BehaviourType); }
public void AddIncomingFormDataValues_Get_ShouldThrowException_WhenIncomingValueIsNull() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var incomingValue = new IncomingValuesBuilder() .WithQuestionId("testQuestionId") .WithName("testName") .WithHttpActionType(EHttpActionType.Get) .WithOptional(false) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithIncomingValue(incomingValue) .Build(); var queryData = new QueryCollection(); // Act & Assert var result = Assert.Throws <Exception>(() => _helper.AddIncomingFormDataValues(page, queryData, new FormAnswers())); Assert.Equal("IncomingDataHelper::AddIncomingFormDataValues, FormData does not contain testName required value", result.Message); }
public async Task Index_ShouldThrowApplicationException_ShouldRunDefaultBehaviour() { // Arrange var element = new ElementBuilder() .WithType(EElementType.H1) .WithQuestionId("test-id") .WithPropertyText("test-text") .Build(); var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.Unknown) .Build(); var page = new PageBuilder() .WithElement(element) .WithPageSlug("page-one") .WithBehaviour(behaviour) .WithValidatedModel(true) .Build(); _pageService.Setup(_ => _.ProcessRequest(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <IEnumerable <CustomFormFile> >(), It.IsAny <bool>())) .ReturnsAsync(new ProcessRequestEntity { Page = page }); _pageService.Setup(_ => _.GetBehaviour(It.IsAny <ProcessRequestEntity>())).Returns(new Behaviour { BehaviourType = EBehaviourType.Unknown }); var viewModel = new Dictionary <string, string[]>(); // Act & Assert var result = await Assert.ThrowsAsync <ApplicationException>(() => _homeController.Index("form", "page-one", viewModel, null)); Assert.Equal($"The provided behaviour type 'Unknown' is not valid", result.Message); }
public void CheckPageMeetsConditions_ShouldReturnFalse_If_RenderConditionsAreNotValid() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("page-continue") .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithRenderConditions(new Condition { QuestionId = "testRadio", ConditionType = ECondition.EqualTo, ComparisonValue = "yes" }) .Build(); var viewModel = new Dictionary <string, dynamic>(); // Act var result = page.CheckPageMeetsConditions(viewModel); // Assert Assert.False(result); }
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); }
public void GetNextPage_ShouldReturn_Behaviour_WhenIsNullOrEmpty_Condition_False() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToExternalPage) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithCondition(new Condition { IsNullOrEmpty = false, QuestionId = "test", ConditionType = ECondition.IsNullOrEmpty }) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .Build(); var viewModel = new Dictionary <string, dynamic> { { "test", "value" } }; // Act var result = page.GetNextPage(viewModel); // Assert Assert.Equal(EBehaviourType.GoToPage, result.BehaviourType); }
public void AddIncomingFormDataValues_Post_ShouldReturnSingleObject_WithOptionalTrue() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var incomingValue = new IncomingValuesBuilder() .WithQuestionId("questionIdTest") .WithName("nameTest") .WithOptional(true) .WithHttpActionType(EHttpActionType.Post) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithIncomingValue(incomingValue) .Build(); var formData = new Dictionary <string, dynamic>(); // Act var result = _helper.AddIncomingFormDataValues(page, formData); // Assert Assert.Empty(result); }
public void AddIncomingFormDataValues_Get_ShouldDecodeData_WhenBase64Encoded_IsTrue() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var incomingValue = new IncomingValuesBuilder() .WithQuestionId("test") .WithName("baseEncodeTest") .WithHttpActionType(EHttpActionType.Get) .WithBase64Encoding(true) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithIncomingValue(incomingValue) .Build(); var queryData = new Dictionary <string, StringValues> { { "baseEncodeTest", new StringValues("MTIzNDU2VGVzdA==") } }; var formData = new QueryCollection(queryData); // Act var result = _helper.AddIncomingFormDataValues(page, formData, new FormAnswers()); // Assert Assert.Single(result); Assert.True(result.ContainsKey("test")); Assert.True(result.ContainsValue("123456Test")); }
public void GetNextPage_ShouldThrowException_WhenNoConditions_Match_WithCorrect_Confition_Log() { // Arrange var pageSlug = "est-page"; var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithCondition(new Condition { EqualTo = "apple", QuestionId = "otherquestion" }) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .WithCondition(new Condition { EqualTo = "peach", QuestionId = "otherquestiontwo" }) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .WithPageSlug(pageSlug) .Build(); var viewModel = new Dictionary <string, dynamic> { { "otherquestion", "pear" } }; // Act var result = Assert.Throws <ApplicationException>(() => page.GetNextPage(viewModel)); // Assert Assert.Equal($"Page::GetNextPage, There was a problem whilst processing behaviors for page '{pageSlug}', Behaviour Answers and conditions: QuestionId: otherquestiontwo with answer 'null' QuestionId: otherquestion with answer pear", result.Message); }
public void AddIncomingFormDataValues_Get_ShouldReturn_EmptyObjectt_WhenOptional_AndValueNotSupplied() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var incomingValue = new IncomingValuesBuilder() .WithQuestionId("questionIdTest") .WithName("nameTest") .WithOptional(true) .WithHttpActionType(EHttpActionType.Get) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithIncomingValue(incomingValue) .Build(); // Act var result = _helper.AddIncomingFormDataValues(page, new QueryCollection(), new FormAnswers()); // Assert Assert.Empty(result); }
public async Task Index_ShouldCallActionsWorkflow_IfPageHasActions() { // Arrange var element = new ElementBuilder() .WithType(EElementType.Textbox) .WithQuestionId("test") .Build(); var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .WithPageSlug("url") .Build(); var pageActions = new ActionBuilder() .WithActionType(EActionType.RetrieveExternalData) .WithPageActionSlug(new PageActionSlug { URL = "www.test.com", Environment = "local", AuthToken = string.Empty }) .WithTargetQuestionId(string.Empty) .WithHttpActionType(EHttpActionType.Post) .Build(); var page = new PageBuilder() .WithElement(element) .WithPageSlug("page-one") .WithValidatedModel(true) .WithBehaviour(behaviour) .WithPageActions(pageActions) .Build(); var viewModel = new ViewModelBuilder() .WithEntry("Guid", Guid.NewGuid().ToString()) .WithEntry($"test", "test") .Build(); _pageService.Setup(_ => _.ProcessRequest(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <IEnumerable <CustomFormFile> >(), It.IsAny <bool>())) .ReturnsAsync(new ProcessRequestEntity { Page = page }); _pageService.Setup(_ => _.GetBehaviour(It.IsAny <ProcessRequestEntity>())).Returns(new Behaviour { BehaviourType = EBehaviourType.SubmitAndPay }); _paymentWorkflow.Setup(_ => _.Submit(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync("https://www.return.url"); // Act await _homeController.Index("form", "page-one", viewModel, null); // Assert _mockActionsWorkflow.Verify(_ => _.Process(page.PageActions, It.IsAny <FormSchema>(), It.IsAny <string>()), Times.Once); }
public void GetPage_ShouldReturnPageWithMatchingConditions() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("success") .WithRenderConditions(new Condition { QuestionId = "testRadio", ConditionType = ECondition.EqualTo, ComparisonValue = "yes" }) .Build(); var page2 = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("success") .WithRenderConditions(new Condition { QuestionId = "testRadio", ConditionType = ECondition.EqualTo, ComparisonValue = "no" }) .WithRenderConditions(new Condition { QuestionId = "testInput", ConditionType = ECondition.EqualTo, ComparisonDate = "test" }) .Build(); var formSchema = new FormSchemaBuilder() .WithBaseUrl("baseUrl") .WithName("form name") .WithStartPageUrl("page1") .WithPage(page) .WithPage(page2) .Build(); _mockPageHelper.Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >())).Returns(page); // Act var result = formSchema.GetPage(_mockPageHelper.Object, "success"); // Assert Assert.Equal(page, result); }
public async Task ProcessSubmission_ShouldCallGateway_WithFormData() { // Arrange var questionId = "testQuestion"; var callbackValue = new ExpandoObject() as IDictionary <string, object>; var element = new ElementBuilder() .WithQuestionId(questionId) .WithType(EElementType.Textarea) .Build(); var submitSlug = new SubmitSlug() { AuthToken = "AuthToken", Environment = "local", URL = "www.location.com" }; var formData = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithSubmitSlug(submitSlug) .Build(); var page = new PageBuilder() .WithBehaviour(formData) .WithElement(element) .WithPageSlug("page-one") .Build(); var schema = new FormSchemaBuilder() .WithPage(page) .Build(); _mockGateway.Setup(_ => _.PostAsync(It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK }) .Callback <string, object>((x, y) => callbackValue = (ExpandoObject)y); _mockPageHelper .Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >())) .Returns(page); // Act await _service.ProcessSubmission(new MappingEntity { Data = new ExpandoObject(), BaseForm = schema, FormAnswers = new FormAnswers { Path = "page-one" } }, "form", "123454"); // Assert _mockGateway.Verify(_ => _.PostAsync(It.IsAny <string>(), It.IsAny <object>()), Times.Once); Assert.NotNull(callbackValue); }
public void GetSubmitFormEndpoint_ShouldReturnCorrectSubmitActionUrl_WhenMultipleSubmits() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithPageSlug("page-one") .WithSubmitSlug(new SubmitSlug { Environment = "test" }) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithPageSlug("page-two") .WithCondition(new Condition { EqualTo = "test", QuestionId = "test" }) .WithSubmitSlug(new SubmitSlug { Environment = "test", URL = "page-two" }) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .Build(); // Act var result = page.GetSubmitFormEndpoint(new FormAnswers { Path = "page-one", Pages = new List <PageAnswers> { new PageAnswers { PageSlug = "page-one", Answers = new List <Answers> { new Answers { QuestionId = "test", Response = "test" } } } } }, "test"); // Assert Assert.Equal("page-two", result.URL); }
public async Task CheckForPaymentConfiguration_Should_ThrowException_WhenCalculateCostUrl_DoesNot_StartWithHttps() { // Arrange _mockPaymentConfigProvider .Setup(_ => _.Get <List <PaymentInformation> >()) .ReturnsAsync(new List <PaymentInformation> { new PaymentInformation { FormName = "test-name", PaymentProvider = "testProvider", Settings = new Settings { CalculationSlug = new SubmitSlug { URL = "http://", Environment = "non-local", AuthToken = "token" } } } }); _mockHostingEnv.Setup(_ => _.EnvironmentName) .Returns("non-local"); var pages = new List <Page>(); var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .Build(); var schema = new FormSchemaBuilder() .WithPage(page) .WithName("test-name") .WithBaseUrl("test-name") .Build(); // Act var check = new PaymentConfigurationCheck(_mockHostingEnv.Object, _mockPaymentProviders.Object, _mockPaymentConfigProvider.Object); // Assert var result = await check.ValidateAsync(schema); Assert.Collection <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message)); Assert.False(result.IsValid); }
public async Task ProcessSubmission__Application_ShoudlThrowApplicationException_WhenGatewayResponse_IsNotOk() { // Arrange var element = new ElementBuilder() .WithType(EElementType.H1) .WithQuestionId("test-id") .WithPropertyText("test-text") .Build(); var submitSlug = new SubmitSlug() { AuthToken = "AuthToken", Environment = "local", URL = "www.location.com" }; var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithSubmitSlug(submitSlug) .Build(); var page = new PageBuilder() .WithElement(element) .WithBehaviour(behaviour) .WithPageSlug("page-one") .Build(); var schema = new FormSchemaBuilder() .WithPage(page) .Build(); _mockGateway.Setup(_ => _.PostAsync(It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError }); _mockPageHelper .Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >())) .Returns(page); // Act var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessSubmission(new MappingEntity { BaseForm = schema, FormAnswers = new FormAnswers { Path = "page-one" } }, "form", "")); // Assert Assert.StartsWith("SubmitService::ProcessSubmission, An exception has occurred while attempting to call ", result.Message); _mockGateway.Verify(_ => _.PostAsync(It.IsAny <string>(), It.IsAny <object>()), Times.Once); }
public void RenderConditionsValidCheck_IsValid_If_TwoOrMorePagesWithTheSameSlugHaveRenderConditions_And_TheLastPageHasNoRenderConditions() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("success") .WithRenderConditions(new Condition { QuestionId = "test", EqualTo = "yes" }) .Build(); var page2 = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("success") .WithRenderConditions(new Condition { QuestionId = "test", EqualTo = "no" }) .Build(); var page3 = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("success") .Build(); page3.RenderConditions = new List <Condition>(); var schema = new FormSchemaBuilder() .WithName("test-name") .WithPage(page) .WithPage(page2) .WithPage(page3) .Build(); // Act var check = new RenderConditionsValidCheck(); var result = check.Validate(schema); // Assert Assert.True(result.IsValid); }
public void AddIncomingFormDataValues_Get_ShouldReturnMultipleValuesObject() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var incomingValue = new IncomingValuesBuilder() .WithQuestionId("questionIdTest") .WithName("nameTest") .WithOptional(true) .WithHttpActionType(EHttpActionType.Get) .Build(); var incomingValue2 = new IncomingValuesBuilder() .WithQuestionId("questionIdTest2") .WithName("nameTest2") .WithOptional(true) .WithHttpActionType(EHttpActionType.Get) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithIncomingValue(incomingValue) .WithIncomingValue(incomingValue2) .Build(); var queryData = new Dictionary <string, StringValues> { { "nameTest", new StringValues("45.23645") }, { "nameTest2", new StringValues("-2.345") }, }; var formData = new QueryCollection(queryData); // Act var result = _helper.AddIncomingFormDataValues(page, formData, new FormAnswers()); // Assert Assert.Equal(2, result.Count); Assert.True(result.ContainsKey("questionIdTest")); Assert.True(result.ContainsValue("45.23645")); Assert.True(result.ContainsKey("questionIdTest2")); Assert.True(result.ContainsValue("-2.345")); Assert.False(result.ContainsKey("nameTest")); Assert.False(result.ContainsKey("nameTest2")); }
public async Task PaymentConfigurationCheck_Should_VerifyCalculationSlugs_StartWithHttps() { // Arrange _mockPaymentConfigProvider .Setup(_ => _.Get <List <PaymentInformation> >()) .ReturnsAsync(new List <PaymentInformation> { new PaymentInformation { FormName = "test-name", PaymentProvider = "testProvider", Settings = new Settings { CalculationSlug = new SubmitSlug { URL = "https://", AuthToken = "token" } } } }); _mockHostingEnv.Setup(_ => _.EnvironmentName) .Returns("non-local"); var pages = new List <Page>(); var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .Build(); var schema = new FormSchemaBuilder() .WithPage(page) .WithName("test-name") .WithBaseUrl("test-name") .Build(); // Act var check = new PaymentConfigurationCheck(_mockHostingEnv.Object, _mockPaymentProviders.Object, _mockPaymentConfigProvider.Object); // Assert var result = await check.ValidateAsync(schema); Assert.True(result.IsValid); }
public void GetSubmitFormEndpoint_ShouldReturnNull_WhenNoFormSubmitAction() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("page-one") .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .Build(); // Act & Assert Assert.Throws <NullReferenceException>(() => page.GetSubmitFormEndpoint(new FormAnswers(), null)); }
public void GetNextPage_ShouldReturn_CorrectBehaviour_When_MixedConditions_ForEqualTo() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithCondition(new Condition { CheckboxContains = "apple", QuestionId = "test" }) .Build(); var behaviour2 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .WithCondition(new Condition { CheckboxContains = "pear", QuestionId = "test" }) .Build(); var behaviour3 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToExternalPage) .WithCondition(new Condition { EqualTo = "mango", QuestionId = "test" }) .Build(); var behaviour4 = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithCondition(new Condition { EqualTo = "berry", QuestionId = "test" }) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithBehaviour(behaviour2) .WithBehaviour(behaviour3) .WithBehaviour(behaviour4) .Build(); var viewModel = new Dictionary <string, dynamic> { { "test", "berry" } }; // Act var result = page.GetNextPage(viewModel); // Assert Assert.Equal(EBehaviourType.SubmitForm, result.BehaviourType); }
public async Task PaymentSubmission_ShouldCallGateway_AndReturn_Reference() { // Arrange var guid = Guid.NewGuid(); var submitSlug = new SubmitSlug { AuthToken = "AuthToken", Environment = "local", URL = "www.location.com" }; var formData = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithPageSlug("testUrl") .WithSubmitSlug(submitSlug) .Build(); var page = new PageBuilder() .WithBehaviour(formData) .WithPageSlug("page-one") .Build(); var schema = new FormSchemaBuilder() .WithPage(page) .Build(); _mockGateway.Setup(_ => _.PostAsync(It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("\"1234456\"") }); _mockPageHelper .Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >())) .Returns(page); // Act var result = await _service.PaymentSubmission((new MappingEntity { BaseForm = schema, FormAnswers = new FormAnswers { Path = "page-one" } }), "form", guid.ToString()); // Assert Assert.IsType <string>(result); _mockGateway.Verify(_ => _.PostAsync(It.IsAny <string>(), It.IsAny <object>())); }
public void AddIncomingFormDataValues_Post_ShouldCall_RecursiveCheckAndCreate_AndReturnCorrectObject() { // Arrange var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.GoToPage) .WithPageSlug("test-test") .Build(); var incomingValue = new IncomingValuesBuilder() .WithQuestionId("questionIdTest") .WithName("nameTest") .WithOptional(true) .WithHttpActionType(EHttpActionType.Post) .Build(); var incomingValue2 = new IncomingValuesBuilder() .WithQuestionId("questionIdTest2.nameTest2") .WithName("nameTest2") .WithHttpActionType(EHttpActionType.Post) .WithOptional(true) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithIncomingValue(incomingValue) .WithIncomingValue(incomingValue2) .Build(); var formData = new Dictionary <string, dynamic> { { "nameTest", "45.23645" }, { "questionIdTest2.nameTest2", "-2.345" } }; // Act var result = _helper.AddIncomingFormDataValues(page, formData); // Assert Assert.Equal(2, result.Count); Assert.True(result.ContainsKey("questionIdTest")); Assert.True(result.ContainsValue("45.23645")); Assert.False(result.ContainsKey("nameTest")); Assert.True(result.ContainsKey("questionIdTest2.nameTest2")); Assert.True(result.ContainsValue("-2.345")); Assert.False(result.ContainsKey("nameTest2")); }