public async Task GetSavedIncomeAndExpenditureTest()
        {
            string lowellReference = "123456789";

            IncomeAndExpenditureApiModel apiModel = new IncomeAndExpenditureApiModel()
            {
                Created = DateTime.Now.AddDays(-30)
            };

            IncomeAndExpenditure expected = new IncomeAndExpenditure()
            {
                Created = DateTime.Now.AddDays(-30)
            };

            this._restClient.Setup(x => x.PostAsync <IncomeAndExpenditureApiRequest, IncomeAndExpenditureApiModel>(
                                       "TESTING/api/BudgetCalculator/GetSavedIncomeAndExpenditure",
                                       It.Is <IncomeAndExpenditureApiRequest>(m => m.LowellReference == "123456789")))
            .Returns(Task.FromResult(apiModel));

            this._mapper.Setup(x => x.Map <IncomeAndExpenditure>(apiModel)).Returns(expected);

            IncomeAndExpenditure result = await _budgetCalculatorService.GetSavedIncomeAndExpenditure(lowellReference);

            Assert.AreEqual(expected, result);
        }
예제 #2
0
        public async Task <IncomeAndExpenditure> GetPartiallySavedIncomeAndExpenditure(string loggedInUserId, Guid caseflowUserId)
        {
            if (loggedInUserId == null)
            {
                return(null);
            }
            if (!_portalSettings.Features.EnablePartialSave)
            {
                return(null);
            }

            var innerUrl = $"{_portalSettings.GatewayEndpoint}api/BudgetCalculator/GetPartialSavedIncomeAndExpenditure";

            var dto = new PartialBudgetApiRequest
            {
                CaseflowUserId = caseflowUserId
            };

            IncomeAndExpenditureApiModel result = await _restClient.PostAsync <PartialBudgetApiRequest, IncomeAndExpenditureApiModel>(innerUrl, dto);

            if (result == null || result.Created < DateTime.UtcNow.AddDays(-30))
            {
                return(null);
            }

            return(_mapper.Map <IncomeAndExpenditure>(result));
        }
        public async Task GetPartiallySavedIncomeAndExpenditureTest()
        {
            this._portalSettings.Features.EnablePartialSave = true;

            string loggedInUserId = Guid.NewGuid().ToString();
            Guid   caseflowUserId = Guid.NewGuid();

            IncomeAndExpenditureApiModel apiModel = new IncomeAndExpenditureApiModel()
            {
                Created = DateTime.Now.AddDays(-5)
            };

            IncomeAndExpenditure expected = new IncomeAndExpenditure()
            {
                Created = DateTime.Now.AddDays(-5)
            };

            this._restClient.Setup(x => x.PostAsync <PartialBudgetApiRequest, IncomeAndExpenditureApiModel>(
                                       "TESTING/api/BudgetCalculator/GetPartialSavedIncomeAndExpenditure",
                                       It.Is <PartialBudgetApiRequest>(m => m.CaseflowUserId == caseflowUserId)))
            .Returns(Task.FromResult(apiModel));

            this._mapper.Setup(x => x.Map <IncomeAndExpenditure>(apiModel)).Returns(expected);

            IncomeAndExpenditure result = await this._budgetCalculatorService.
                                          GetPartiallySavedIncomeAndExpenditure(loggedInUserId, caseflowUserId);

            Assert.AreEqual(expected, result);
        }
        public async Task <AmendDirectDebitVm> Build(IApplicationSessionState session, Guid lowellReferenceSurrogateKey, string caseflowUserId)
        {
            string lowellReference = session.GetLowellReferenceFromSurrogate(lowellReferenceSurrogateKey);
            AccountReferenceDto accountReferenceDto = new AccountReferenceDto {
                LowellReference = lowellReference
            };
            var currentDirectDebit = await _getCurrentDirectDebitProcess.GetCurrentDirectDebit(accountReferenceDto);

            IncomeAndExpenditureApiModel incomeAndExpenditureDto = await _apiGatewayProxy.GetIncomeAndExpenditure(lowellReference);

            var workingAccounts = 0;

            if (caseflowUserId != null)
            {
                List <AccountSummary> accounts = await _accountService.GetAccounts(caseflowUserId);

                workingAccounts = accounts.Count(a => !a.AccountStatusIsClosed);
            }

            PaymentOptionsDto paymentOptionsDto = await _apiGatewayProxy.GetPaymentOptions(accountReferenceDto);

            var obj = new AmendDirectDebitVm
            {
                LowellReference    = currentDirectDebit.LowellReference,
                ClientName         = currentDirectDebit.ClientName,
                OutstandingBalance = currentDirectDebit.OutstandingBalance,
                DirectDebitAmount  = null,
                PlanType           = currentDirectDebit.PlanType,
                EarliestStartDate  = currentDirectDebit.EarliestInstalmentDate,
                LatestStartDate    = currentDirectDebit.LatestPlanSetupDate,
                PlanStartDate      = currentDirectDebit.EarliestInstalmentDate,
                DiscountedBalance  = currentDirectDebit.DiscountedBalance,
                DiscountAmount     = currentDirectDebit.DiscountAmount,
                DiscountExpiry     = currentDirectDebit.DiscountExpiry,
                DiscountPercentage = currentDirectDebit.DiscountPercentage,
                DiscountedBalancePreviouslyAccepted = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                Frequency                    = _buildFrequencyListProcess.BuildFrequencyList(currentDirectDebit.DirectDebitFrequencies),
                IandENotAvailable            = incomeAndExpenditureDto == null,
                IandELessThanOrIs12MonthsOld = (incomeAndExpenditureDto != null && incomeAndExpenditureDto.Created.AddMonths(12).Date >= DateTime.Now.Date),
                AverageMonthlyPayment        = _portalSetting.AverageMonthlyPaymentAmount,
                MonthlyDisposableIncome      = (incomeAndExpenditureDto == null ? 0 :
                                                (incomeAndExpenditureDto.DisposableIncome * (_portalSetting.MonthlyDisposableIncomePlanSetupPercentage / 100)))
            };

            obj.AccountCount = workingAccounts;

            if (workingAccounts > 1)
            {
                obj.MonthlyDisposableIncomePerAccount =
                    obj.MonthlyDisposableIncome / workingAccounts;
            }
            else
            {
                obj.MonthlyDisposableIncomePerAccount = obj.MonthlyDisposableIncome;
            }

            return(obj);
        }
예제 #5
0
        public void ConvertTest_SourceNull()
        {
            IncomeAndExpenditure         source          = null;
            IncomeAndExpenditureApiModel destination     = new IncomeAndExpenditureApiModel();
            IncomeAndExpenditureApiModel destinationCopy = Utilities.DeepCopy(destination);
            IncomeAndExpenditureApiModel expected        = null;

            IncomeAndExpenditureApiModel result = _converter.Convert(source, destination, null);

            Assert.AreEqual(expected, result);

            //Check that destination has not been modified
            Assert.IsTrue(Utilities.DeepCompare(destination, destinationCopy));
        }
        public async Task SaveIncomeAndExpenditureTest()
        {
            string lowellReference                = "123456789";
            IncomeAndExpenditure         iAndE    = new IncomeAndExpenditure();
            IncomeAndExpenditureApiModel apiModel = new IncomeAndExpenditureApiModel();

            this._mapper.Setup(x => x.Map <IncomeAndExpenditure, IncomeAndExpenditureApiModel>(iAndE))
            .Returns(apiModel);
            this._restClient.Setup(x => x.PostNoResponseAsync(
                                       "TESTING/api/BudgetCalculator/SaveIncomeAndExpenditure", apiModel)).Returns(Task.CompletedTask);

            await this._budgetCalculatorService.SaveIncomeAndExpenditure(iAndE, lowellReference);

            Assert.AreEqual(lowellReference, iAndE.LowellReference);
        }
        public async Task GetPartiallySavedIncomeAndExpenditureTest_ResultNull()
        {
            this._portalSettings.Features.EnablePartialSave = true;

            string loggedInUserId = Guid.NewGuid().ToString();
            Guid   caseflowUserId = Guid.NewGuid();

            IncomeAndExpenditureApiModel apiModel = null;

            this._restClient.Setup(x => x.PostAsync <PartialBudgetApiRequest, IncomeAndExpenditureApiModel>(
                                       "TESTING/api/BudgetCalculator/GetPartialSavedIncomeAndExpenditure",
                                       It.Is <PartialBudgetApiRequest>(m => m.CaseflowUserId == caseflowUserId)))
            .Returns(Task.FromResult(apiModel));

            Assert.IsNull(await this._budgetCalculatorService
                          .GetPartiallySavedIncomeAndExpenditure(loggedInUserId, caseflowUserId));
        }
예제 #8
0
        public async Task <IncomeAndExpenditure> GetSavedIncomeAndExpenditure(string lowellReference)
        {
            var innerUrl = $"{_portalSettings.GatewayEndpoint}api/BudgetCalculator/GetSavedIncomeAndExpenditure";

            var dto = new IncomeAndExpenditureApiRequest
            {
                LowellReference = lowellReference
            };

            IncomeAndExpenditureApiModel result =
                await _restClient.PostAsync <IncomeAndExpenditureApiRequest, IncomeAndExpenditureApiModel>(innerUrl, dto);

            if (result == null || result.Created < DateTime.UtcNow.AddDays(-180))
            {
                return(null);
            }

            return(_mapper.Map <IncomeAndExpenditure>(result));
        }
        public async Task PartiallySaveIncomeAndExpenditureTest()
        {
            string lowellReference                = "123456789";
            Guid   caseflowUserId                 = Guid.NewGuid();
            IncomeAndExpenditure         iAndE    = new IncomeAndExpenditure();
            IncomeAndExpenditureApiModel apiModel = new IncomeAndExpenditureApiModel();

            this._mapper.Setup(x => x.Map <IncomeAndExpenditure, IncomeAndExpenditureApiModel>(iAndE))
            .Returns(apiModel);

            this._restClient.Setup(x => x.PostAsync <PartialBudgetApiModel, bool>(
                                       "TESTING/api/BudgetCalculator/PartialSaveIncomeAndExpenditure",
                                       It.Is <PartialBudgetApiModel>(
                                           m => m.LowellReference == lowellReference &&
                                           m.CaseflowUserId == caseflowUserId &&
                                           m.PartialBudget == apiModel &&
                                           Math.Abs(m.CreatedDate.Subtract(DateTime.UtcNow).TotalSeconds) < 5)))
            .Returns(Task.FromResult(true));

            Assert.IsTrue(await this._budgetCalculatorService
                          .PartiallySaveIncomeAndExpenditure(iAndE, lowellReference, caseflowUserId));

            Assert.AreEqual(lowellReference, iAndE.LowellReference);
        }
예제 #10
0
        public void ConvertTest()
        {
            IncomeAndExpenditure source = new IncomeAndExpenditure()
            {
                AdultsInHousehold         = 1,
                Children16to18            = 2,
                ChildrenUnder16           = 3,
                Created                   = DateTime.Now.Date,
                CouncilTax                = 100,
                CouncilTaxArrears         = 110,
                CouncilTaxFrequency       = "monthly",
                ChildMaintenance          = 120,
                ChildMaintenanceArrears   = 130,
                ChildMaintenanceFrequency = "fortnightly",
                HomeContents              = 140,
                HomeContentsArrears       = 150,
                HomeContentsFrequency     = "weekly",
                HasArrears                = true,
                EmploymentStatus          = "employed full time",
                Healthcare                = 160,
                HealthcareFrequency       = "monthly",
                Housekeeping              = 170,
                HousekeepingFrequency     = "fortnightly",
                HousingStatus             = "homeowner",
                Leisure                   = 180,
                LeisureFrequency          = "weekly",
                LowellReference           = "123456789",
                Mortgage                  = 190,
                MortgageArrears           = 200,
                MortgageFrequency         = "monthly",
                OtherUtilities            = 210,
                OtherUtilitiesArrears     = 220,
                OtherUtilitiesFrequency   = "fortnightly",
                OtherIncome               = 230,
                OtherincomeFrequency      = "weekly",
                PersonalCosts             = 240,
                PersonalCostsFrequency    = "fortnightly",
                Pension                   = 250,
                PensionFrequency          = "weekly",
                PensionInsurance          = 260,
                PensionInsuranceFrequency = "monthly",
                Rental                        = 270,
                RentalArrears                 = 280,
                RentalFrequency               = "fortnightly",
                Rent                          = 290,
                RentArrears                   = 300,
                RentFrequency                 = "weekly",
                Salary                        = 310,
                SalaryFrequency               = "monthly",
                SavingsContributions          = 320,
                SavingsContributionsFrequency = "fortnightly",
                SchoolCosts                   = 330,
                SchoolCostsFrequency          = "weekly",
                ProfessionalCosts             = 340,
                ProfessionalCostsFrequency    = "monthly",
                SecuredLoans                  = 350,
                SecuredloansArrears           = 360,
                SecuredLoansFrequency         = "fortnightly",
                Travel                        = 370,
                TravelFrequency               = "weekly",
                TvLicence                     = 380,
                TvLicenceArrears              = 390,
                TvLicenceFrequency            = "monthly",
                User                          = "******",
                OtherDebts                    = new List <SaveOtherDebts>()
                {
                },
                Electricity          = 400,
                ElectricityArrears   = 410,
                ElectricityFrequency = "fortnightly",
                Gas                       = 420,
                GasArrears                = 430,
                GasFrequency              = "weekly",
                Water                     = 440,
                WaterArrears              = 450,
                WaterFrequency            = "monthly",
                BenefitsTotal             = 460,
                BenefitsTotalFrequency    = "fortnightly",
                EarningsTotal             = 470,
                EarningsTotalFrequency    = "weekly",
                ExpenditureTotal          = 480,
                IncomeTotal               = 490,
                DisposableIncome          = 500,
                UtilitiesTotal            = 510,
                UtilitiesTotalArrears     = 520,
                UtilitiesTotalFrequency   = "monthly",
                CCJs                      = 530,
                CCJsArrears               = 540,
                CCJsFrequency             = "fortnightly",
                CourtFines                = 550,
                CourtFinesArrears         = 560,
                CourtFinesFrequency       = "weekly",
                OtherExpenditure          = 570,
                OtherExpenditureFrequency = "monthly"
            };

            //Create a copy of source for later
            IncomeAndExpenditure sourceCopy = Utilities.DeepCopy(source);

            IncomeAndExpenditureApiModel destination = new IncomeAndExpenditureApiModel();
            IncomeAndExpenditureApiModel expected    = Utilities.DeepCopy(destination);

            this._calculatorService.Setup(x => x.InArrears(source)).Returns(true);

            expected.LowellReference = "123456789";
            expected.User            = "******";
            expected.Created         = DateTime.UtcNow;
            expected.HasArrears      = true;

            expected.AdultsInHousehold = 1;
            expected.ChildrenUnder16   = 3;
            expected.Children16to18    = 2;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.Salary          = 310;
            expected.SalaryFrequency = "M";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("weekly")).Returns("W");
            expected.Pension          = 250;
            expected.PensionFrequency = "W";

            expected.EarningsTotal          = 0.00M;
            expected.EarningsTotalFrequency = "";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.BenefitsTotal          = 460;
            expected.BenefitsTotalFrequency = "F";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("weekly")).Returns("W");
            expected.OtherIncome          = 230;
            expected.OtherincomeFrequency = "W";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.Mortgage          = 190;
            expected.MortgageFrequency = "M";
            expected.MortgageArrears   = 200;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("weekly")).Returns("W");
            expected.Rent          = 290;;
            expected.RentFrequency = "W";
            expected.RentArrears   = 300;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.SecuredLoans          = 350;
            expected.SecuredLoansFrequency = "F";
            expected.SecuredloansArrears   = 360;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.CouncilTax          = 100;
            expected.CouncilTaxFrequency = "M";
            expected.CouncilTaxArrears   = 110;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.Rental          = 270;
            expected.RentalFrequency = "F";
            expected.RentalArrears   = 280;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.TvLicence          = 380;
            expected.TvLicenceFrequency = "M";
            expected.TvLicenceArrears   = 390;

            expected.HomeContents          = 0.00M;
            expected.HomeContentsFrequency = "";
            expected.HomeContentsArrears   = 150.00M;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("weekly")).Returns("W");
            expected.Gas          = 420;
            expected.GasFrequency = "W";
            expected.GasArrears   = 430;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.OtherUtilities          = 210;
            expected.OtherUtilitiesFrequency = "F";
            expected.OtherUtilitiesArrears   = 220;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.Electricity          = 400;
            expected.ElectricityFrequency = "F";
            expected.ElectricityArrears   = 410;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.Water          = 440;
            expected.WaterFrequency = "M";
            expected.WaterArrears   = 450;

            expected.UtilitiesTotal          = 0.00M;
            expected.UtilitiesTotalFrequency = "";
            expected.UtilitiesTotalArrears   = 520.00M;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.ChildMaintenance          = 120;
            expected.ChildMaintenanceFrequency = "F";
            expected.ChildMaintenanceArrears   = 130;

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.Housekeeping          = 170;
            expected.HousekeepingFrequency = "F";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.PersonalCosts          = 240;
            expected.PersonalCostsFrequency = "F";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("weekly")).Returns("W");
            expected.Leisure          = 180;
            expected.LeisureFrequency = "W";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("weekly")).Returns("W");
            expected.Travel          = 370;
            expected.TravelFrequency = "W";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.Healthcare          = 160;
            expected.HealthcareFrequency = "M";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.PensionInsurance          = 260;
            expected.PensionInsuranceFrequency = "M";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("weekly")).Returns("W");
            expected.SchoolCosts          = 330;
            expected.SchoolCostsFrequency = "W";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("monthly")).Returns("M");
            expected.ProfessionalCosts          = 340;
            expected.ProfessionalCostsFrequency = "M";

            this._mapperHelper.Setup(x => x.ConvertFrequencyToInitial("fortnightly")).Returns("F");
            expected.SavingsContributions          = 320;
            expected.SavingsContributionsFrequency = "F";

            List <SaveOtherDebtsApiModel> otherDebts = new List <SaveOtherDebtsApiModel>()
            {
                new SaveOtherDebtsApiModel()
                {
                    Amount = 570, Arrears = 580, Frequency = "M", CountyCourtJudgement = true
                }
            };

            _mapperHelper.Setup(x => x.CreateOtherDebts(source)).Returns(otherDebts);
            expected.OtherDebts = otherDebts;

            MonthlyIncome monthlyIncome = new MonthlyIncome()
            {
                Total = 590
            };

            this._calculatorService.Setup(x => x.CalculateMonthlyIncome(source)).Returns(monthlyIncome);

            MonthlyOutgoings monthlyOutgoings = new MonthlyOutgoings()
            {
                Total = 600
            };

            this._calculatorService.Setup(x => x.CalculateMonthlyOutgoings(source)).Returns(monthlyOutgoings);

            this._mapperHelper.Setup(x => x.ConvertToHousingStatusCaseflow("homeowner")).Returns("Owner");
            this._mapperHelper.Setup(x => x.ConvertToEmploymentStatusCaseflow("employed full time")).Returns("Full-Time");

            expected.IncomeTotal      = 590;
            expected.ExpenditureTotal = 600;
            expected.DisposableIncome = -10;
            expected.HousingStatus    = "Owner";
            expected.EmploymentStatus = "Full-Time";

            IncomeAndExpenditureApiModel result = _converter.Convert(source, destination, null);

            //Check that source hasn't been modified
            Assert.IsTrue(Utilities.DeepCompare(source, sourceCopy));

            //Check that result is as expected
            Assert.IsTrue(Utilities.DeepCompare(expected, result, 1000));
        }
        public void ConvertTest()
        {
            IncomeAndExpenditureApiModel source = new IncomeAndExpenditureApiModel()
            {
                AdultsInHousehold         = 1,
                Children16to18            = 2,
                ChildrenUnder16           = 3,
                Created                   = DateTime.Now.Date,
                CouncilTax                = 100,
                CouncilTaxArrears         = 110,
                CouncilTaxFrequency       = "M",
                ChildMaintenance          = 120,
                ChildMaintenanceArrears   = 130,
                ChildMaintenanceFrequency = "F",
                HomeContents              = 140,
                HomeContentsArrears       = 150,
                HomeContentsFrequency     = "W",
                HasArrears                = true,
                EmploymentStatus          = "full-time",
                Healthcare                = 160,
                HealthcareFrequency       = "M",
                Housekeeping              = 170,
                HousekeepingFrequency     = "F",
                HousingStatus             = "owner",
                Leisure                   = 180,
                LeisureFrequency          = "W",
                LowellReference           = "123456789",
                Mortgage                  = 190,
                MortgageArrears           = 200,
                MortgageFrequency         = "M",
                OtherUtilities            = 210,
                OtherUtilitiesArrears     = 220,
                OtherUtilitiesFrequency   = "F",
                OtherIncome               = 230,
                OtherincomeFrequency      = "W",
                PersonalCosts             = 240,
                PersonalCostsFrequency    = "F",
                Pension                   = 250,
                PensionFrequency          = "W",
                PensionInsurance          = 260,
                PensionInsuranceFrequency = "M",
                Rental                        = 270,
                RentalArrears                 = 280,
                RentalFrequency               = "F",
                Rent                          = 290,
                RentArrears                   = 300,
                RentFrequency                 = "W",
                Salary                        = 310,
                SalaryFrequency               = "M",
                SavingsContributions          = 320,
                SavingsContributionsFrequency = "F",
                SchoolCosts                   = 330,
                SchoolCostsFrequency          = "W",
                ProfessionalCosts             = 340,
                ProfessionalCostsFrequency    = "M",
                SecuredLoans                  = 350,
                SecuredloansArrears           = 360,
                SecuredLoansFrequency         = "F",
                Travel                        = 370,
                TravelFrequency               = "W",
                TvLicence                     = 380,
                TvLicenceArrears              = 390,
                TvLicenceFrequency            = "M",
                User                          = "******",
                OtherDebts                    = new List <SaveOtherDebtsApiModel>()
                {
                },
                Electricity          = 400,
                ElectricityArrears   = 410,
                ElectricityFrequency = "F",
                Gas                     = 420,
                GasArrears              = 430,
                GasFrequency            = "W",
                Water                   = 440,
                WaterArrears            = 450,
                WaterFrequency          = "M",
                BenefitsTotal           = 460,
                BenefitsTotalFrequency  = "F",
                EarningsTotal           = 470,
                EarningsTotalFrequency  = "W",
                ExpenditureTotal        = 480,
                IncomeTotal             = 490,
                DisposableIncome        = 500,
                UtilitiesTotal          = 510,
                UtilitiesTotalArrears   = 520,
                UtilitiesTotalFrequency = "M"
            };

            List <SaveOtherDebts> otherDebts = new List <SaveOtherDebts>();

            //Create a copy of source for later
            IncomeAndExpenditureApiModel sourceCopy = Utilities.DeepCopy(source);

            IncomeAndExpenditure destination = new IncomeAndExpenditure();
            IncomeAndExpenditure expected    = Utilities.DeepCopy(destination);

            expected.LowellReference = "123456789";
            expected.User            = "******";
            expected.Created         = DateTime.Now.Date;
            expected.HasArrears      = true;

            _mapperHelper.Setup(x => x.ConvertEmploymentStatusFromCaseflow("full-time")).Returns("employed-full-time");
            _mapperHelper.Setup(x => x.ConvertHousingStatusFromCaseflow("owner")).Returns("homeowner");

            expected.EmploymentStatus  = "employed-full-time";
            expected.HousingStatus     = "homeowner";
            expected.AdultsInHousehold = 1;
            expected.Children16to18    = 2;
            expected.ChildrenUnder16   = 3;

            expected.IncomeTotal      = 490;
            expected.ExpenditureTotal = 480;
            expected.DisposableIncome = 500;

            _mapper.Setup(x => x.Map <List <SaveOtherDebts> >(source.OtherDebts)).Returns(otherDebts);
            expected.OtherDebts = otherDebts;

            _mapperHelper.Setup(x => x.MapRegularPayment(310, "M"))
            .Returns(new RegularPayment()
            {
                Amount = 310, Frequency = "monthly"
            });
            expected.Salary          = 310;
            expected.SalaryFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapRegularPayment(250, "W"))
            .Returns(new RegularPayment()
            {
                Amount = 250, Frequency = "weekly"
            });
            expected.Pension          = 250;
            expected.PensionFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapRegularPayment(470, "W"))
            .Returns(new RegularPayment()
            {
                Amount = 470, Frequency = "weekly"
            });
            expected.EarningsTotal          = 470;
            expected.EarningsTotalFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapRegularPayment(460, "F"))
            .Returns(new RegularPayment()
            {
                Amount = 460, Frequency = "fortnightly"
            });
            expected.BenefitsTotal          = 460;
            expected.BenefitsTotalFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapRegularPayment(230, "W"))
            .Returns(new RegularPayment()
            {
                Amount = 230, Frequency = "weekly"
            });
            expected.OtherIncome          = 230;
            expected.OtherincomeFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapOutgoing(270, "F", 280))
            .Returns(new Outgoing()
            {
                Amount = 270, ArrearsAmount = 280, Frequency = "fortnightly", InArrears = true
            });
            expected.Rental          = 270;
            expected.RentalArrears   = 280;
            expected.RentalFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapOutgoing(120, "F", 130))
            .Returns(new Outgoing()
            {
                Amount = 120, ArrearsAmount = 130, Frequency = "fortnightly", InArrears = true
            });
            expected.ChildMaintenance          = 120;
            expected.ChildMaintenanceArrears   = 130;
            expected.ChildMaintenanceFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapOutgoing(100, "M", 110))
            .Returns(new Outgoing()
            {
                Amount = 100, ArrearsAmount = 110, Frequency = "monthly", InArrears = true
            });
            expected.CouncilTax          = 100;
            expected.CouncilTaxArrears   = 110;
            expected.CouncilTaxFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapOutgoing(510, "M", 520))
            .Returns(new Outgoing()
            {
                Amount = 510, ArrearsAmount = 520, Frequency = "monthly", InArrears = true
            });
            expected.UtilitiesTotal          = 510;
            expected.UtilitiesTotalArrears   = 520;
            expected.UtilitiesTotalFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapOutgoing(400, "F", 410))
            .Returns(new Outgoing()
            {
                Amount = 400, ArrearsAmount = 410, Frequency = "fortnightly", InArrears = true
            });
            expected.Electricity          = 400;
            expected.ElectricityArrears   = 410;
            expected.ElectricityFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapOutgoing(420, "W", 430))
            .Returns(new Outgoing()
            {
                Amount = 420, ArrearsAmount = 430, Frequency = "weekly", InArrears = true
            });
            expected.Gas          = 420;
            expected.GasArrears   = 430;
            expected.GasFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapOutgoing(210, "F", 220))
            .Returns(new Outgoing()
            {
                Amount = 210, ArrearsAmount = 220, Frequency = "fortnightly", InArrears = true
            });
            expected.OtherUtilities          = 210;
            expected.OtherUtilitiesArrears   = 220;
            expected.OtherUtilitiesFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapOutgoing(190, "M", 200))
            .Returns(new Outgoing()
            {
                Amount = 190, ArrearsAmount = 200, Frequency = "monthly", InArrears = true
            });
            expected.Mortgage          = 190;
            expected.MortgageArrears   = 200;
            expected.MortgageFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapOutgoing(140, "W", 150))
            .Returns(new Outgoing()
            {
                Amount = 140, ArrearsAmount = 150, Frequency = "weekly", InArrears = true
            });
            expected.HomeContents          = 140;
            expected.HomeContentsArrears   = 150;
            expected.HomeContentsFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapOutgoing(290, "W", 300))
            .Returns(new Outgoing()
            {
                Amount = 290, ArrearsAmount = 300, Frequency = "weekly", InArrears = true
            });
            expected.Rent          = 290;
            expected.RentArrears   = 300;
            expected.RentFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapOutgoing(350, "F", 360))
            .Returns(new Outgoing()
            {
                Amount = 350, ArrearsAmount = 360, Frequency = "fortnightly", InArrears = true
            });
            expected.SecuredLoans          = 350;
            expected.SecuredloansArrears   = 360;
            expected.SecuredLoansFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapOutgoing(380, "M", 390))
            .Returns(new Outgoing()
            {
                Amount = 380, ArrearsAmount = 390, Frequency = "monthly", InArrears = true
            });
            expected.TvLicence          = 380;
            expected.TvLicenceArrears   = 390;
            expected.TvLicenceFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapOutgoing(440, "M", 450))
            .Returns(new Outgoing()
            {
                Amount = 440, ArrearsAmount = 450, Frequency = "monthly", InArrears = true
            });
            expected.Water          = 440;
            expected.WaterArrears   = 450;
            expected.WaterFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapRegularPayment(160, "M"))
            .Returns(new RegularPayment()
            {
                Amount = 160, Frequency = "monthly"
            });
            expected.Healthcare          = 160;
            expected.HealthcareFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapRegularPayment(180, "W"))
            .Returns(new RegularPayment()
            {
                Amount = 180, Frequency = "weekly"
            });
            expected.Leisure          = 180;
            expected.LeisureFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapRegularPayment(170, "F"))
            .Returns(new RegularPayment()
            {
                Amount = 170, Frequency = "fortnightly"
            });
            expected.Housekeeping          = 170;
            expected.HousekeepingFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapRegularPayment(260, "M"))
            .Returns(new RegularPayment()
            {
                Amount = 260, Frequency = "monthly"
            });
            expected.PensionInsurance          = 260;
            expected.PensionInsuranceFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapRegularPayment(240, "F"))
            .Returns(new RegularPayment()
            {
                Amount = 240, Frequency = "fortnightly"
            });
            expected.PersonalCosts          = 240;
            expected.PersonalCostsFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapRegularPayment(340, "M"))
            .Returns(new RegularPayment()
            {
                Amount = 340, Frequency = "monthly"
            });
            expected.ProfessionalCosts          = 340;
            expected.ProfessionalCostsFrequency = "monthly";

            _mapperHelper.Setup(x => x.MapRegularPayment(320, "F"))
            .Returns(new RegularPayment()
            {
                Amount = 320, Frequency = "fortnightly"
            });
            expected.SavingsContributions          = 320;
            expected.SavingsContributionsFrequency = "fortnightly";

            _mapperHelper.Setup(x => x.MapRegularPayment(330, "W"))
            .Returns(new RegularPayment()
            {
                Amount = 330, Frequency = "weekly"
            });
            expected.SchoolCosts          = 330;
            expected.SchoolCostsFrequency = "weekly";

            _mapperHelper.Setup(x => x.MapRegularPayment(370, "W"))
            .Returns(new RegularPayment()
            {
                Amount = 370, Frequency = "weekly"
            });
            expected.Travel          = 370;
            expected.TravelFrequency = "weekly";

            IncomeAndExpenditure result = _converter.Convert(source, destination, null);

            //Check that source hasn't been modified
            Assert.IsTrue(Utilities.DeepCompare(source, sourceCopy));

            //Check that result is as expected
            Assert.IsTrue(Utilities.DeepCompare(expected, result));
        }
예제 #12
0
        public async Task <PaymentOptionsVm> Build(IUserIdentity loggedInUser, IApplicationSessionState applicationSessionState, Guid lowellReferenceSurrogateKey, string caseflowUserId)
        {
            string lowellReference = applicationSessionState.GetLowellReferenceFromSurrogate(lowellReferenceSurrogateKey);
            AccountReferenceDto accountReferenceDto = new AccountReferenceDto()
            {
                LowellReference = lowellReference
            };
            PaymentOptionsDto paymentOptionsDto = await _apiGatewayProxy.GetPaymentOptions(accountReferenceDto);

            IncomeAndExpenditureApiModel incomeAndExpenditureDto = await _apiGatewayProxy.GetIncomeAndExpenditure(lowellReference);

            List <AccountSummary> accounts;

            if (caseflowUserId != null)
            {
                accounts = await _accountsService.GetAccounts(caseflowUserId);
            }
            else
            {
                accounts = await _accountsService.GetMyAccountsSummary(lowellReference);
            }

            var workingAccounts = accounts.Count(a => !a.AccountStatusIsClosed);

            if (workingAccounts == 0)
            {
                workingAccounts = 1;
            }

            var accountDetails = await _accountsService.GetAccount(caseflowUserId, lowellReference);

            string[] planMessages = accountDetails.PlanMessages;

            var paymentOptionsVm = new PaymentOptionsVm()
            {
                OutstandingBalance                  = paymentOptionsDto.OutstandingBalance,
                LowellReference                     = paymentOptionsDto.LowellReference,
                ClientName                          = paymentOptionsDto.ClientName,
                ExcludedAccountMessage              = paymentOptionsDto.ExcludedAccountMessage,
                PlanInPlace                         = paymentOptionsDto.PlanInPlace,
                PlanIsDirectDebit                   = paymentOptionsDto.PaymentPlanIsDirectDebit,
                WithLowellSolicitors                = paymentOptionsDto.WithLowellSolicitors,
                PaymentOptions                      = new List <PaymentOptionsSelectionsVm>(),
                DiscountPercentage                  = paymentOptionsDto.DiscountPercentage,
                DiscountAmount                      = paymentOptionsDto.DiscountAmount,
                DiscountExpiryDate                  = paymentOptionsDto.DiscountExpiryDate,
                DiscountedBalance                   = paymentOptionsDto.DiscountedBalance,
                DiscountBalanceAvailable            = paymentOptionsDto.DiscountBalanceAvailable,
                ProposedDiscountedBalanceIfAccepted = paymentOptionsDto.ProposedDiscountedBalanceIfAccepted,
                DiscountedBalancePreviouslyAccepted = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                ArrearsMessage                      = _arrearsDescriptionProcess.DeriveArrearsDetail(paymentOptionsDto.PaymentPlanArrearsAmount,
                                                                                                     paymentOptionsDto.PaymentPlanIsAutomated),
                StandingOrder           = paymentOptionsDto.StandingOrder,
                StandingOrderMessage    = paymentOptionsDto.StandingOrderMessage,
                VerifoneTransactionGuid = $"{paymentOptionsDto.LowellReference}_{Guid.NewGuid()}",
                DiscountAccepted        = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                PlanMessage             = planMessages != null && planMessages.Length > 0? planMessages[0]:string.Empty
            };

            if (loggedInUser.IsLoggedInUser)
            {
                paymentOptionsVm.DirectDebitEmailAddress = loggedInUser.EmailAddress;
            }
            else
            {
                paymentOptionsVm.DirectDebitIsEmailAddressFieldVisible = true;
            }

            // Logged in user has accept T&C defaulted and will be hidden.
            // Anon user has tick box displayed. Must be ticked.
            if (loggedInUser.IsLoggedInUser)
            {
                paymentOptionsVm.AcceptTermsAndConditions = true;
            }
            else
            {
                paymentOptionsVm.IsAcceptTermsAndConditionsFieldVisible = true;
            }

            // Work out amount that needs to be paid to clear balance
            if (paymentOptionsVm.DiscountedBalancePreviouslyAccepted)
            {
                paymentOptionsVm.FullPaymentBalance = paymentOptionsVm.DiscountedBalance;
            }
            else
            {
                paymentOptionsVm.FullPaymentBalance = paymentOptionsVm.OutstandingBalance;
            }

            // Customer has a plan but it isn't direct debit.
            // Used to display a message informing customer that they can change to a DD online.
            if (paymentOptionsDto.PlanInPlace && !paymentOptionsDto.PaymentPlanIsDirectDebit)
            {
                paymentOptionsVm.HasNonDirectDebitPlanInPlace = true;
            }

            if (paymentOptionsDto.WithLowellSolicitors)
            {
                paymentOptionsVm.LowellSolicitorsRedirectLink = _portalSetting.SolicitorsRedirectDataProtectionUrl;
            }

            // Shared list of options for partial / full
            paymentOptionsVm.SourceOfFunds = BuildSourceOfFundsSelections(paymentOptionsDto);

            // Direct Debit
            paymentOptionsVm.DirectDebitFrequency         = BuildFrequencyList(paymentOptionsDto.DirectDebitFrequencies);
            paymentOptionsVm.DirectDebitStartDateEarliest = paymentOptionsDto.DirectDebitStartDateEarliest;
            paymentOptionsVm.DirectDebitStartDateLatest   = paymentOptionsDto.DirectDebitStartDateLatest;

            // TODO: Wrap the code below in a strategy pattern
            if (paymentOptionsDto.CanMakeFullPayment)
            {
                paymentOptionsVm.PaymentOptions.Add(new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Card payment (Pay in Full)",
                    Value         = PaymentOptionsSelectionsVm.Values.FullPayment,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.FullPayment
                });
            }
            if (paymentOptionsDto.CanMakePartialPayment)
            {
                paymentOptionsVm.PaymentOptions.Add(new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Card payment (Partial amount)",
                    Value         = PaymentOptionsSelectionsVm.Values.PartialPayment,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.PartialPayment,
                    ClassValue    = "js-hide-option"        // script hides this
                });
            }
            if (paymentOptionsDto.CanSetupDirectDebit)
            {
                paymentOptionsVm.PaymentOptions.Add(new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Direct Debit plan",
                    Value         = PaymentOptionsSelectionsVm.Values.DirectDebit,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.DirectDebit
                });
            }

            // Only add 'please select' if there are options
            // Required because view checks for availability of payment options
            if (paymentOptionsVm.PaymentOptions.Count > 0)
            {
                paymentOptionsVm.PaymentOptions.Insert(0, new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Please Select",
                    Value         = PaymentOptionsSelectionsVm.Values.PleaseSelect,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.PleaseSelect
                });
            }

            paymentOptionsVm.LowellReferenceSurrogate = lowellReferenceSurrogateKey;

            paymentOptionsVm.IandENotAvailable = incomeAndExpenditureDto == null;

            paymentOptionsVm.IandELessThanOrIs12MonthsOld =
                (incomeAndExpenditureDto != null && incomeAndExpenditureDto.Created.AddMonths(12).Date >= DateTime.Now.Date);
            paymentOptionsVm.AverageMonthlyPayment   = _portalSetting.AverageMonthlyPaymentAmount;
            paymentOptionsVm.MonthlyDisposableIncome =
                (incomeAndExpenditureDto == null ? 0 : (incomeAndExpenditureDto.DisposableIncome * (_portalSetting.MonthlyDisposableIncomePlanSetupPercentage / 100)));

            paymentOptionsVm.AccountCount = workingAccounts;
            paymentOptionsVm.MonthlyDisposableIncomePerAccount = paymentOptionsVm.MonthlyDisposableIncome / workingAccounts;

            return(paymentOptionsVm);
        }