public void SubmitSlugsHaveAllProperties_IsNotValid_WhenUrlIsEmpty() { // Arrange var submitSlugs = new SubmitSlug { AuthToken = "this is auth token", URL = "", Environment = "local", }; var behaviours = new List <Behaviour> { new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithSubmitSlug(submitSlugs) .Build() }; // Act var check = new SubmitSlugsHaveAllPropertiesCheck(_mockHostingEnv.Object); var result = check.Validate(behaviours); // Assert Assert.False(result.IsValid); Assert.Collection <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message)); }
public void EmptyBehaviourSlugsCheck_IsValid_WhenSubmitSlugIsNotEmpty() { // Arrange var submitSlug = new SubmitSlug { Environment = "local", URL = "test-url" }; var behaviours = new List <Behaviour> { new BehaviourBuilder() .WithSubmitSlug(submitSlug) .Build() }; EmptyBehaviourSlugsCheck check = new(); // Act & Assert var result = check.Validate(behaviours); // Assert Assert.True(result.IsValid); Assert.DoesNotContain(IntegrityChecksConstants.FAILURE, result.Messages); }
public void CurrentEnvironmentSubmitSlugsCheck_IsNotValid_WhenPageSlugIsNotPresentFor() { // Arrange var submitSlug = new SubmitSlug { Environment = "mysteryEnvironment", URL = "test-url" }; var behaviours = new List <Behaviour> { new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithSubmitSlug(submitSlug) .Build() }; var check = new CurrentEnvironmentSubmitSlugsCheck(_mockHostingEnv.Object); // Act & Assert var result = check.Validate(behaviours); // Assert Assert.False(result.IsValid); Assert.Collection <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message)); }
public ElementBuilder WithCalculationSlugs(SubmitSlug submitSlug) { if (_property.CalculationSlugs == null) { _property.CalculationSlugs = new List <SubmitSlug>(); } _property.CalculationSlugs.Add(submitSlug); return(this); }
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 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 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 async Task PaymentSubmission_ShouldThrowApplicationException_WhenGatewayResponseContent_IsEmpty() { // Arrange var postUrl = "www.post.url"; var submitSlug = new SubmitSlug { AuthToken = "AuthToken", Environment = "local", URL = "www.location.com" }; var formData = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithSubmitSlug(submitSlug) .WithPageSlug(postUrl) .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("") }); _mockPageHelper .Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >())) .Returns(page); // Act var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.PaymentSubmission(new MappingEntity { BaseForm = schema, FormAnswers = new FormAnswers { Path = "page-one" } }, "form", "")); // Assert Assert.StartsWith($"SubmitService::PaymentSubmission, Gateway", result.Message); _mockGateway.Verify(_ => _.PostAsync(It.IsAny <string>(), It.IsAny <object>()), Times.Once); }
public async Task ProcessSubmission_Applicaton_ShouldCatchException_WhenGatewayCallThrowsException() { // Arrange var submitSlug = new SubmitSlug() { AuthToken = "AuthToken", Environment = "local", URL = "www.Environment.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>())) .ThrowsAsync(new Exception("error")); _mockPageHelper .Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >())) .Returns(page); // Act & Assert var result = await Assert.ThrowsAsync <Exception>(() => _service.PaymentSubmission(new MappingEntity { BaseForm = schema, FormAnswers = new FormAnswers { Path = "page-one" } }, "form", "")); Assert.StartsWith("error", result.Message); }
private static MappingEntity GetMappingEntityData() { var submitSlug = new SubmitSlug { AuthToken = "testToken", Environment = "local", URL = "customer-pay", CallbackUrl = "callbackUrl" }; var formAnswers = new FormAnswers { Path = "customer-pay" }; var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .WithSubmitSlug(submitSlug) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("customer-pay") .Build(); var formSchema = new FormSchemaBuilder() .WithPage(page) .Build(); var mappingEntity = new MappingEntityBuilder() .WithBaseForm(formSchema) .WithFormAnswers(formAnswers) .WithData(new object()) .Build(); return(mappingEntity); }
public void CheckSubmitSlugsHaveAllProperties_IsValid_WhenAuthTokenAndUrlAreNotNullOrEmpty() { // Arrange var submitSlugs = new SubmitSlug { AuthToken = "this is auth token", URL = "test" }; var behaviours = new List <Behaviour> { new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitForm) .WithSubmitSlug(submitSlugs) .Build() }; // Act var check = new SubmitSlugsHaveAllPropertiesCheck(_mockHostingEnv.Object); var result = check.Validate(behaviours); // Assert Assert.True(result.IsValid); }
public BehaviourBuilder WithSubmitSlug(SubmitSlug submitSlug) { _submitSlugs.Add(submitSlug); return(this); }
public PayServiceTests() { _paymentProvider.Setup(_ => _.ProviderName).Returns("testPaymentProvider"); _mockCache.Setup(_ => _.GetFromCacheOrDirectlyFromSchemaAsync <List <PaymentInformation> >(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <ESchemaType>())) .ReturnsAsync(new List <PaymentInformation> { new PaymentInformation { FormName = "testForm", PaymentProvider = "testPaymentProvider", Settings = new Settings { ComplexCalculationRequired = false, Amount = "12.65" } }, new PaymentInformation { FormName = "testFormwithnovalidpayment", PaymentProvider = "invalidPaymentPorvider", Settings = new Settings { ComplexCalculationRequired = false } }, new PaymentInformation { FormName = "complexCalculationForm", PaymentProvider = "testPaymentProvider", Settings = new Settings { ComplexCalculationRequired = true } } }); _mockDistributedCacheExpirationSettings.Setup(_ => _.Value).Returns( new DistributedCacheExpirationConfiguration { UserData = 30, PaymentConfiguration = 5 }); var submitSlug = new SubmitSlug { AuthToken = "testToken", Environment = "local", URL = "customer-pay", CallbackUrl = "ddjshfkfjhk" }; var formAnswers = new FormAnswers { Path = "customer-pay" }; var behaviour = new BehaviourBuilder() .WithBehaviourType(EBehaviourType.SubmitAndPay) .WithSubmitSlug(submitSlug) .Build(); var page = new PageBuilder() .WithBehaviour(behaviour) .WithPageSlug("customer-pay") .Build(); var formSchema = new FormSchemaBuilder() .WithPage(page) .Build(); var mappingEntity = new MappingEntityBuilder() .WithBaseForm(formSchema) .WithFormAnswers(formAnswers) .WithData(new object()) .Build(); var paymentProviderItems = new List <IPaymentProvider> { _paymentProvider.Object }; _mockPaymentProvider.Setup(m => m.GetEnumerator()).Returns(() => paymentProviderItems.GetEnumerator()); _mockSessionHelper.Setup(_ => _.GetSessionGuid()).Returns("d96bceca-f5c6-49f8-98ff-2d823090c198"); _mockMappingService.Setup(_ => _.Map("d96bceca-f5c6-49f8-98ff-2d823090c198", "testForm")) .ReturnsAsync(mappingEntity); _mockMappingService.Setup(_ => _.Map("d96bceca-f5c6-49f8-98ff-2d823090c198", "nonexistanceform")) .ReturnsAsync(mappingEntity); _mockHostingEnvironment.Setup(_ => _.EnvironmentName).Returns("local"); _service = new PayService(_mockPaymentProvider.Object, _mockLogger.Object, _mockGateway.Object, _mockCache.Object, _mockDistributedCacheExpirationSettings.Object, _mockSessionHelper.Object, _mockMappingService.Object, _mockHostingEnvironment.Object, _mockPageHelper.Object); }
public async Task <HttpResponseMessage> PostAsync(MappingEntity mappingEntity, SubmitSlug submitSlug) => await _gateway.PostAsync(submitSlug.URL, mappingEntity.Data, submitSlug.Type, submitSlug.AuthToken);