public void Validate_WhenModelIsValid_ReturnsTrue() { // Simplest possible valid scenario PaymentOptionsVm paymentOptionsVm = new PaymentOptionsVm() { SelectedPaymentOption = PaymentOptionsSelectionsVm.Values.FullPayment, FullPaymentSelectedSourceOfFunds = "anything" }; Assert.IsTrue(_paymentOptionsValidatorProcess.Validate(paymentOptionsVm)); }
public async Task <IBuildDirectDebitPlanOverviewVmValidationResult> ValidateAndBuild( IUserIdentity loggedInUser, IApplicationSessionState applicationSessionState, Guid lowellReferenceSurrogateKey, PaymentOptionsVm paymentOptionsVmWithUserEntries, DirectDebitDetailsVm directDebitDetailsVmWithUserEntries, string caseflowUserId) { // // Payment Options - reconstruct from CaseFlow, populate user entris and validate clean // PaymentOptionsVm paymentOptionsVm = await _buildPaymentOptionsVmService.Build(loggedInUser, applicationSessionState, lowellReferenceSurrogateKey, caseflowUserId); _buildPaymentOptionsVmService.UpdateFieldsFromUserEntries(loggedInUser, paymentOptionsVm, paymentOptionsVmWithUserEntries); if (!_paymentOptionsVmValidatorProcess.Validate(paymentOptionsVm)) { return new ValidationResult() { IsValid = false } } ; // // Direct Debit Details - reconstruct from fresh payment options, populate user entris and validate clean // DirectDebitDetailsVm directDebitDetailsVm = _buildDirectDebitDetailsVmService.Build(paymentOptionsVm); _buildDirectDebitDetailsVmService.UpdateFieldsFromUserEntries(directDebitDetailsVm, directDebitDetailsVmWithUserEntries); if (!_directDebitDetailsVmValidatorProcess.Validate(directDebitDetailsVm)) { return new ValidationResult() { IsValid = false } } ; // // Return valid result with overview built clean // return(new ValidationResult() { IsValid = true, DirectDebitPlanOverviewVm = Build(paymentOptionsVm, directDebitDetailsVm) }); } } }
// Checks the information entered by the user against CaseFlow afresh // If validation fails, returns false and OneOffPaymentReviewVm will be output as NULL // If successful, returns true and OneOffPaymentReviewVm will be output populated public async Task <IBuildOneOffPaymentReviewVmValidationResult> ValidateAndBuild( IUserIdentity loggedInUser, IApplicationSessionState applicationSessionState, Guid lowellReferenceSurrogateKey, PaymentOptionsVm paymentOptionsVmWithUserEntries, string caseflowUserId) { // Reload from CaseFlow PaymentOptionsVm paymentOptionsVm = await _buildPaymentOptionsVmService.Build(loggedInUser, applicationSessionState, lowellReferenceSurrogateKey, caseflowUserId); // Populate user entries, giving a clean model to validate _buildPaymentOptionsVmService.UpdateFieldsFromUserEntries(loggedInUser, paymentOptionsVm, paymentOptionsVmWithUserEntries); if (!_paymentOptionsVmValidatorProcess.Validate(paymentOptionsVm)) { return new ValidationResult() { IsValid = false } } ; // Ensure we are not using this - must use clean, validated model (defensive coding) // ReSharper disable once RedundantAssignment paymentOptionsVmWithUserEntries = null; var postDataXml = _verifonePaymentProviderService.CreatePayload(paymentOptionsVm); OneOffPaymentReviewVm vm = new OneOffPaymentReviewVm() { LowellReference = paymentOptionsVm.LowellReference, ClientName = paymentOptionsVm.ClientName, VerifoneUrl = _verifoneSetting.ApiEndpoint, VerifonePostDataXml = postDataXml, VerifoneTransactionGuid = paymentOptionsVm.VerifoneTransactionGuid.ToString(), UserID = loggedInUser.UserId, PaidInFull = paymentOptionsVm.SelectedPaymentOption == PaymentOptionsSelectionsVm.Values.FullPayment, DiscountAvailable = paymentOptionsVm.DiscountBalanceAvailable, DiscountSelected = paymentOptionsVm.DiscountAccepted, PlanInPlace = paymentOptionsVm.PlanInPlace, InArrears = !String.IsNullOrEmpty(paymentOptionsVm.ArrearsMessage) }; // Source payment information from appropriate nested object if (paymentOptionsVm.SelectedPaymentOption == PaymentOptionsSelectionsVm.Values.FullPayment) { vm.PaymentAmount = paymentOptionsVm.FullPaymentAmountDerived; vm.SourceOfFunds = paymentOptionsVm.FullPaymentSelectedSourceOfFunds; vm.SourceOfFundsOther = paymentOptionsVm.FullPaymentSourceOfFundsOtherText; vm.PaidInFull = true; } else if (paymentOptionsVm.SelectedPaymentOption == PaymentOptionsSelectionsVm.Values.PartialPayment) { Debug.Assert(paymentOptionsVm.PartialPaymentAmount != null, "paymentOptionsVmWithUserEntries.PartialPaymentAmount != null"); vm.PaymentAmount = paymentOptionsVm.PartialPaymentAmount.Value; vm.SourceOfFunds = paymentOptionsVm.PartialPaymentSelectedSourceOfFunds; vm.SourceOfFundsOther = paymentOptionsVm.PartialPaymentSourceOfFundsOtherText; } else { throw new ApplicationException("Invalid SelectedPaymentOption"); } return(new ValidationResult() { IsValid = true, OneOffPaymentReviewVm = vm }); } }