Example #1
0
        public void BuildPaymentDto_MapsAsExpected()
        {
            //Arrange
            var paymentDto = new DirectDebitPaymentDto();


            //Act
            var result = _directDebitPlanProcess.SendDirectDebitPlanAsync(paymentDto);

            //Assert
            _apiGatewayProxy.Verify(x => x.SetupDirectDebitPlanAsync(paymentDto), Times.Once);
        }
Example #2
0
        public void SendAmendDirectDebitPlanAsync_CallsAmendPlanOnProxy()
        {
            DirectDebitPaymentDto directDebitPaymentDto = new DirectDebitPaymentDto();

            _apiGatewayProxyMock.Setup(x => x.AmendDirectDebitPlanAsync(directDebitPaymentDto))
            .Callback((DirectDebitPaymentDto dto) =>
            {
                Assert.AreEqual(directDebitPaymentDto, dto);
            })
            .Returns(Task.CompletedTask);

            _sendAmendDirectDebitPlanProcess.SendAmendDirectDebitPlanAsync(directDebitPaymentDto).Wait();

            _apiGatewayProxyMock.Verify(x => x.AmendDirectDebitPlanAsync(directDebitPaymentDto), Times.Once);
        }
        public async Task <bool> AmendDirectDebitPlan(IUserIdentity loggedInUser,
                                                      IApplicationSessionState applicationSessionState,
                                                      Guid lowellReferenceSurrogateKey,
                                                      AmendDirectDebitVm amendDirectDebitVmWithUserEntries,
                                                      string caseflowUserId)
        {
            // Must be a logged in user
            if (loggedInUser.IsLoggedInUser == false)
            {
                throw new ApplicationException("AmendDirectDebitPlan can only be used for a logged in user due to requiring email address.");
            }

            // Reload from CaseFlow
            AmendDirectDebitVm amendDirectDebitVm = await _buildAmendDirectDebitVmService.Build(applicationSessionState, lowellReferenceSurrogateKey, caseflowUserId);

            // Populate user entries, giving a clean model to validate
            _buildAmendDirectDebitVmService.UpdateFieldsFromUserEntries(amendDirectDebitVm, amendDirectDebitVmWithUserEntries);

            if (!_amendDirectDebitVmValidatorProcess.Validate(amendDirectDebitVm))
            {
                return(false);
            }

            // Ensure we are not using this - must use clean, validated model (defensive coding)
            // ReSharper disable once RedundantAssignment
            amendDirectDebitVmWithUserEntries = null;

            var directDebitPaymentDto = new DirectDebitPaymentDto
            {
                Frequency        = _directDebitFrequencyTranslator.TranslateClientScriptCompatibleValueToDescription(amendDirectDebitVm.PlanFrequency),
                LowellReference  = amendDirectDebitVm.LowellReference,
                PaymentAmount    = amendDirectDebitVm.DirectDebitAmount.Value,
                StartDate        = amendDirectDebitVm.PlanStartDate.ToShortDateString(),
                PlanTotal        = amendDirectDebitVm.OutstandingBalance,
                DiscountAmount   = amendDirectDebitVm.DiscountAmount,
                DiscountAccepted = amendDirectDebitVm.DiscountedBalance < amendDirectDebitVm.OutstandingBalance,
                EmailAddress     = loggedInUser.EmailAddress,
                User             = loggedInUser.IsLoggedInUser ? "WebUser" : "WebAnon"
            };

            await _sendAmendDirectDebitPlanProcess.SendAmendDirectDebitPlanAsync(directDebitPaymentDto);

            return(true);
        }
Example #4
0
        public DirectDebitPaymentDto BuildDirectDebitPlanDto(DirectDebitPlanOverviewVm directDebitPlanOverviewVm)
        {
            var dto = new DirectDebitPaymentDto()
            {
                SortCode           = directDebitPlanOverviewVm.SortCode,
                AccountNumber      = directDebitPlanOverviewVm.AccountNumber,
                AccountHoldersName = directDebitPlanOverviewVm.AccountHoldersName,
                LowellReference    = directDebitPlanOverviewVm.LowellReference,
                PaymentType        = directDebitPlanOverviewVm.PaymentType,
                StartDate          = directDebitPlanOverviewVm.StartDate,
                PaymentAmount      = directDebitPlanOverviewVm.PaymentAmount,
                Frequency          = directDebitPlanOverviewVm.Frequency,
                GuaranteeRead      = directDebitPlanOverviewVm.GuaranteeRead,
                PlanTotal          = directDebitPlanOverviewVm.PlanTotal,
                DiscountAccepted   = directDebitPlanOverviewVm.DiscountAccepted,
                DiscountAmount     = directDebitPlanOverviewVm.DiscountAmount,
                EmailAddress       = directDebitPlanOverviewVm.EmailAddress,
                User = directDebitPlanOverviewVm.UserLoggedIn ? "WebUser" : "WebAnon"
            };

            return(dto);
        }
        public void BuildDirectDebitPlanDto_PopulatesDtoFromViewModel(
            bool testGuaranteeRead, bool testDiscountAccepted)
        {
            DirectDebitPlanOverviewVm directDebitPlanOverviewVm = new DirectDebitPlanOverviewVm()
            {
                LowellReference    = "*LowellRef",
                PaymentAmount      = 123.01m,
                StartDate          = "*StartDate",
                PaymentType        = "*PaymentType",
                AccountHoldersName = "Bobbert",
                AccountNumber      = "12345678",
                SortCode           = "123456",
                PlanTotal          = 1123.45m,
                Frequency          = "*freq",
                GuaranteeRead      = testGuaranteeRead,
                DiscountAccepted   = testDiscountAccepted,
                DiscountAmount     = 17.50m,
                EmailAddress       = "*****@*****.**"
            };

            DirectDebitPaymentDto directDebitPaymentDto = _buildDirectDebitPlanDtoProcess.BuildDirectDebitPlanDto(directDebitPlanOverviewVm);

            Assert.AreEqual("*LowellRef", directDebitPaymentDto.LowellReference);
            Assert.AreEqual(123.01m, directDebitPaymentDto.PaymentAmount);
            Assert.AreEqual("*StartDate", directDebitPaymentDto.StartDate);
            Assert.AreEqual("*PaymentType", directDebitPaymentDto.PaymentType);
            Assert.AreEqual("Bobbert", directDebitPaymentDto.AccountHoldersName);
            Assert.AreEqual("12345678", directDebitPaymentDto.AccountNumber);
            Assert.AreEqual("123456", directDebitPaymentDto.SortCode);
            Assert.AreEqual(1123.45m, directDebitPaymentDto.PlanTotal);
            Assert.AreEqual("*freq", directDebitPaymentDto.Frequency);
            Assert.AreEqual(testGuaranteeRead, directDebitPaymentDto.GuaranteeRead);
            Assert.AreEqual(testDiscountAccepted, directDebitPaymentDto.DiscountAccepted);
            Assert.AreEqual(17.50m, directDebitPaymentDto.DiscountAmount);
            Assert.AreEqual("*****@*****.**", directDebitPaymentDto.EmailAddress);
        }
        public async Task AmendDirectDebitPlanAsync(DirectDebitPaymentDto dto)
        {
            var innerUrl = $"{_baseUrl}api/AmendDirectDebit/AmendPlan";

            await _restClient.PostNoResponseAsync(innerUrl, dto);
        }
 public async Task SendAmendDirectDebitPlanAsync(DirectDebitPaymentDto directDebitPaymentDto)
 {
     await _apiGatewayProxy.AmendDirectDebitPlanAsync(directDebitPaymentDto);
 }