public async Task <IActionResult> Index()
        {
            // TODO: Is this correct ??!! You are adding Session ID to Lowell Ref!
            Guid id = ApplicationSessionState.AddLowellReferenceSurrogateKey(ApplicationSessionState.SessionId);

            ApplicationSessionState.IandELaunchedExternally = true;

            IncomeAndExpenditure incomeAndExpenditure = ApplicationSessionState.GetIncomeAndExpenditure(id);

            HouseholdStatusVm vm = new HouseholdStatusVm
            {
                ExternallyLaunched = true,
                SavedIAndE         = false,
                AdultsInHousehold  = 1
            };

            if (incomeAndExpenditure != null)
            {
                vm = _mapper.Map <HouseholdStatusVm>(incomeAndExpenditure);

                vm.ExternallyLaunched = true;
                vm.SavedIAndE         = false;
                vm.AdultsInHousehold  = 1;
                ApplicationSessionState.SaveIncomeAndExpenditure(incomeAndExpenditure, id);
            }

            _gtmService.RaiseBudgetCalculatorStartedEvent(vm, LoggedInUserId);
            await _webActivityService.LogBudgetCalculatorIncome(ApplicationSessionState.GetLowellReferenceFromSurrogate(id), LoggedInUserId);

            RouteData.Values.Add("id", id);

            return(View("HouseholdStatus", vm));
        }
        public async Task <IActionResult> Save()
        {
            var id = RouteData.Values["id"];

            if (id == null)
            {
                return(RedirectToAction("Index", "MyAccounts"));
            }

            ApplicationSessionState.CheckSessionStatus(id.ToString());
            Guid guid = Guid.Parse(id.ToString());

            IncomeAndExpenditure incomeAndExpenditure = ApplicationSessionState.GetIncomeAndExpenditure(guid);
            string lowellReference = ApplicationSessionState.GetLowellReferenceFromSurrogate(guid);

            var budgetSummary = GetBudgetSummary(incomeAndExpenditure, guid);

            await SaveBudgetSummary(incomeAndExpenditure, lowellReference);

            budgetSummary.LoggedInUserId = LoggedInUserId;
            budgetSummary.IsSaved        = true;

            if (incomeAndExpenditure != null)
            {
                budgetSummary.HousingStatus    = incomeAndExpenditure.HousingStatus;
                budgetSummary.EmploymentStatus = incomeAndExpenditure.EmploymentStatus;
            }

            return(View("BudgetSummary", budgetSummary));
        }
        public async Task BillsAndOutgoingsPostTest()
        {
            string id = Guid.NewGuid().ToString();

            this._controller.RouteData.Values.Add("id", id);
            this._portalSettings.Features.EnablePartialSave = true;

            IncomeAndExpenditure iAndE           = new IncomeAndExpenditure();
            BillsAndOutgoingsVm  vm              = new BillsAndOutgoingsVm();
            MonthlyIncome        monthlyIncome   = new MonthlyIncome();
            MonthlyIncomeVm      monthlyIncomeVm = new MonthlyIncomeVm();

            this._sessionState.Setup(x => x.CheckSessionStatus(id));
            this._sessionState.Setup(x => x.GetIncomeAndExpenditure(Guid.Parse(id)))
            .Returns(iAndE);
            this._mapper.Setup(x => x.Map(vm, iAndE)).Returns(iAndE);
            this._sessionState.Setup(x => x.SaveIncomeAndExpenditure(iAndE, Guid.Parse(id)));
            this._calculatorService.Setup(x => x.CalculateMonthlyIncome(iAndE)).Returns(monthlyIncome);

            string lowellReference = "123456789";

            this._sessionState.Setup(x => x.GetLowellReferenceFromSurrogate(Guid.Parse(id)))
            .Returns(lowellReference);

            RedirectToActionResult result = (RedirectToActionResult)await this._controller
                                            .BillsAndOutgoingsPost(vm, "testing");

            Assert.AreEqual("Expenditure", result.ActionName);
            Assert.AreEqual(id, result.RouteValues["id"]);
            Assert.IsTrue(vm.EnabledPartialSave);
        }
        public MonthlyOutgoings CalculateMonthlyOutgoings(IncomeAndExpenditure iAndE)
        {
            decimal householdBills = 0.00M;
            decimal arrears        = 0.00M;

            if (iAndE != null)
            {
                householdBills = CalculateMonthlyBillsAndOutgoings(iAndE);
                arrears        = AddArrears(iAndE);

                decimal expenditure = CalculateMonthlyExpenditure(iAndE);


                decimal total = householdBills + expenditure + arrears;

                return(new MonthlyOutgoings()
                {
                    HouseholdBills = householdBills + arrears,
                    Expenditures = expenditure,
                    Total = total
                });
            }

            return(new MonthlyOutgoings()
            {
                HouseholdBills = householdBills + arrears,
                Total = householdBills + arrears
            });
        }
예제 #5
0
        public void CalculateMonthlyIncomeTest()
        {
            IncomeAndExpenditure iAndE = new IncomeAndExpenditure()
            {
                Salary                 = 2500,
                SalaryFrequency        = "monthly",
                BenefitsTotal          = 250,
                BenefitsTotalFrequency = "monthly",
                Pension                = 100,
                PensionFrequency       = "fortnightly",
                OtherIncome            = 1000,
                OtherincomeFrequency   = "annually"
            };

            MonthlyIncome expected = new MonthlyIncome()
            {
                Salary   = 2500,
                Benefits = 250,
                Other    = 83.33M,
                Pension  = 217,
                Total    = 3050.33M
            };

            MonthlyIncome result = this._calculatorService.CalculateMonthlyIncome(iAndE);

            Assert.IsTrue(Utilities.DeepCompare(expected, result));
        }
        public async Task ExpenditurePostTest()
        {
            string id = Guid.NewGuid().ToString();

            this._controller.RouteData.Values.Add("id", id);
            this._portalSettings.Features.EnablePartialSave = true;

            ExpendituresVm       vm    = new ExpendituresVm();
            IncomeAndExpenditure iAndE = new IncomeAndExpenditure();

            this._sessionState.Setup(x => x.CheckSessionStatus(id));
            this._sessionState.Setup(x => x.GetIncomeAndExpenditure(Guid.Parse(id))).Returns(iAndE);
            this._mapper.Setup(x => x.Map(vm, iAndE)).Returns(iAndE);
            this._sessionState.Setup(x => x.SaveIncomeAndExpenditure(iAndE, Guid.Parse(id)));

            string lowellReference = "123456789";

            this._sessionState.Setup(x => x.GetLowellReferenceFromSurrogate(Guid.Parse(id)))
            .Returns(lowellReference);

            this._webActivityService.Setup(x => x.LogBudgetCalculatorCompleted(lowellReference, this._caseflowUserId))
            .Returns(Task.CompletedTask);

            RedirectToActionResult result = (RedirectToActionResult)await this._controller
                                            .ExpenditurePost(vm, "testing");

            Assert.IsTrue(vm.EnabledPartialSave);
            Assert.AreEqual("BudgetSummary", result.ActionName);
            Assert.AreEqual(id, result.RouteValues["id"]);
        }
        public async Task <IActionResult> HouseholdStatusPost(HouseholdStatusVm viewModel)
        {
            var id = RouteData.Values["id"];

            if (id == null)
            {
                return(RedirectToAction("Index", "MyAccounts"));
            }

            ApplicationSessionState.CheckSessionStatus(id.ToString());

            if (!ModelState.IsValid)
            {
                return(View("HouseholdStatus", viewModel));
            }

            Guid guid = Guid.Parse(id.ToString());

            IncomeAndExpenditure incomeAndExpenditure = ApplicationSessionState.GetIncomeAndExpenditure(guid);

            incomeAndExpenditure = _mapper.Map(viewModel, incomeAndExpenditure);
            ApplicationSessionState.SaveIncomeAndExpenditure(incomeAndExpenditure, guid);

            await _webActivityService.LogBudgetCalculatorIncome(ApplicationSessionState.GetLowellReferenceFromSurrogate(guid), LoggedInUserId);

            return(RedirectToAction("YourIncome", new { id }));
        }
        public async Task ExpenditurePostTest_InvalidModelState()
        {
            string id = Guid.NewGuid().ToString();

            this._controller.RouteData.Values.Add("id", id);
            this._controller.ModelState.AddModelError("testing", "testing");
            this._portalSettings.Features.EnablePartialSave = true;

            ExpendituresVm       vm                 = new ExpendituresVm();
            IncomeAndExpenditure iAndE              = new IncomeAndExpenditure();
            MonthlyIncome        monthlyIncome      = new MonthlyIncome();
            MonthlyIncomeVm      monthlyIncomeVm    = new MonthlyIncomeVm();
            MonthlyOutgoings     monthlyOutgoings   = new MonthlyOutgoings();
            MonthlyOutgoingsVm   monthlyOutgoingsVm = new MonthlyOutgoingsVm();

            this._sessionState.Setup(x => x.CheckSessionStatus(id));
            this._sessionState.Setup(x => x.GetIncomeAndExpenditure(Guid.Parse(id))).Returns(iAndE);
            this._mapper.Setup(x => x.Map(vm, iAndE)).Returns(iAndE);
            this._sessionState.Setup(x => x.SaveIncomeAndExpenditure(iAndE, Guid.Parse(id)));

            this._calculatorService.Setup(x => x.CalculateMonthlyIncome(iAndE)).Returns(monthlyIncome);
            this._calculatorService.Setup(x => x.CalculateMonthlyOutgoings(iAndE)).Returns(monthlyOutgoings);
            this._mapper.Setup(x => x.Map <MonthlyIncome, MonthlyIncomeVm>(monthlyIncome))
            .Returns(monthlyIncomeVm);
            this._mapper.Setup(x => x.Map <MonthlyOutgoings, MonthlyOutgoingsVm>(monthlyOutgoings))
            .Returns(monthlyOutgoingsVm);

            ViewResult result = (ViewResult)await this._controller.ExpenditurePost(vm, "testing");

            Assert.AreEqual("Expenditure", result.ViewName);
            Assert.AreEqual(vm, result.Model);
            Assert.AreEqual(vm.IncomeVmSummary, monthlyIncomeVm);
            Assert.AreEqual(vm.OutgoingsVmSummary, monthlyOutgoingsVm);
            Assert.IsTrue(vm.EnabledPartialSave);
        }
        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);
        }
        public void CreateOtherDebtsTest_All()
        {
            IncomeAndExpenditure iAndE = new IncomeAndExpenditure()
            {
                CourtFines          = 111.11M,
                CourtFinesArrears   = 100,
                CourtFinesFrequency = "monthly",
                CCJs                      = 222.22M,
                CCJsArrears               = 200,
                CCJsFrequency             = "weekly",
                OtherExpenditure          = 333.33M,
                OtherExpenditureFrequency = "fortnightly",
            };

            List <SaveOtherDebtsApiModel> result = _helper.CreateOtherDebts(iAndE);

            Assert.AreEqual(3, result.Count);

            Assert.AreEqual(111.11M, result[0].Amount);
            Assert.AreEqual(100, result[0].Arrears);
            Assert.AreEqual(false, result[0].CountyCourtJudgement);
            Assert.AreEqual("M", result[0].Frequency);

            Assert.AreEqual(222.22M, result[1].Amount);
            Assert.AreEqual(200, result[1].Arrears);
            Assert.AreEqual(true, result[1].CountyCourtJudgement);
            Assert.AreEqual("W", result[1].Frequency);

            Assert.AreEqual(333.33M, result[2].Amount);
            Assert.AreEqual(0, result[2].Arrears);
            Assert.AreEqual(false, result[2].CountyCourtJudgement);
            Assert.AreEqual("F", result[2].Frequency);
        }
예제 #11
0
        public void CalculateMonthlyExpenditureTest()
        {
            IncomeAndExpenditure iAndE = new IncomeAndExpenditure()
            {
                Housekeeping           = 100,
                HousekeepingFrequency  = "monthly",
                PersonalCosts          = 50,
                PersonalCostsFrequency = "weekly",
                Leisure                       = 75,
                LeisureFrequency              = "fortnightly",
                Travel                        = 30,
                TravelFrequency               = "weekly",
                Healthcare                    = 1200,
                HealthcareFrequency           = "annually",
                PensionInsurance              = 100,
                PensionInsuranceFrequency     = "quarterly",
                SchoolCosts                   = 600,
                SchoolCostsFrequency          = "quarterly",
                ProfessionalCosts             = 15,
                ProfessionalCostsFrequency    = "monthly",
                SavingsContributions          = 250,
                SavingsContributionsFrequency = "monthly",
                OtherExpenditure              = 125,
                OtherExpenditureFrequency     = "monthly"
            };

            Assert.AreEqual(1332.48M, this._calculatorService.CalculateMonthlyExpenditure(iAndE));
        }
        public async Task ExpenditurePostTest_SaveForLater()
        {
            string id = Guid.NewGuid().ToString();

            this._controller.RouteData.Values.Add("id", id);
            this._portalSettings.Features.EnablePartialSave = true;

            ExpendituresVm       vm    = new ExpendituresVm();
            IncomeAndExpenditure iAndE = new IncomeAndExpenditure();

            this._sessionState.Setup(x => x.CheckSessionStatus(id));
            this._sessionState.Setup(x => x.GetIncomeAndExpenditure(Guid.Parse(id))).Returns(iAndE);
            this._mapper.Setup(x => x.Map(vm, iAndE)).Returns(iAndE);
            this._sessionState.Setup(x => x.SaveIncomeAndExpenditure(iAndE, Guid.Parse(id)));

            string lowellReference = "123456789";

            this._sessionState.Setup(x => x.GetLowellReferenceFromSurrogate(Guid.Parse(id)))
            .Returns(lowellReference);

            this._webActivityService.Setup(x => x.LogBudgetCalculatorCompleted(lowellReference, this._caseflowUserId))
            .Returns(Task.CompletedTask);

            this._budgetCalculatorService.Setup(x => x.PartiallySaveIncomeAndExpenditure(
                                                    iAndE, lowellReference, Guid.Parse(this._caseflowUserId))).Returns(Task.FromResult(true));

            ViewResult result = (ViewResult)await this._controller
                                .ExpenditurePost(vm, "saveforlater");

            Assert.IsTrue(vm.EnabledPartialSave);
            Assert.IsTrue(vm.PartialSavedIAndE);
            Assert.IsFalse(vm.HasErrorPartialSavedIAndE);
            Assert.AreEqual("Expenditure", result.ViewName);
            Assert.AreEqual(vm, result.Model);
        }
예제 #13
0
        public void ConvertTest_SourceNull()
        {
            IncomeAndExpenditure source      = null;
            HouseholdStatusVm    destination = new HouseholdStatusVm()
            {
                AdultsInHousehold = Int32.MaxValue,
                ChildrenOver16    = Int32.MaxValue,
                ChildrenUnder16   = Int32.MaxValue,
                HousingStatus     = "test",
                GtmEvents         = new List <GtmEvent>()
                {
                    new GtmEvent()
                    {
                        account_ref = "test"
                    }
                },
                EmploymentStatus   = "test",
                ExternallyLaunched = true,
                PartialSavedIAndE  = true,
                SavedIAndE         = true
            };

            HouseholdStatusVm expected = Utilities.DeepCopy(destination);

            expected.AdultsInHousehold = 0;
            expected.ChildrenOver16    = 0;
            expected.ChildrenUnder16   = 0;
            expected.EmploymentStatus  = null;
            expected.HousingStatus     = null;

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

            //Check result is as expected
            Assert.IsTrue(Utilities.DeepCompare(expected, 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 IndexTest()
        {
            string sessionId       = Guid.NewGuid().ToString();
            Guid   id              = Guid.NewGuid();
            string lowellReference = "123456789";

            IncomeAndExpenditure iAndE = new IncomeAndExpenditure();
            HouseholdStatusVm    vm    = new HouseholdStatusVm();

            this._sessionState.Setup(x => x.SessionId).Returns(sessionId);
            this._sessionState.Setup(x => x.AddLowellReferenceSurrogateKey(sessionId)).Returns(id);
            this._sessionState.SetupSet(x => x.IandELaunchedExternally = true);

            this._sessionState.Setup(x => x.GetIncomeAndExpenditure(id)).Returns(iAndE);
            this._mapper.Setup(x => x.Map <HouseholdStatusVm>(iAndE)).Returns(vm);

            this._sessionState.Setup(x => x.SaveIncomeAndExpenditure(iAndE, id));
            this._gtmService.Setup(x => x.RaiseBudgetCalculatorStartedEvent(vm, this._caseflowUserId));

            this._sessionState.Setup(x => x.GetLowellReferenceFromSurrogate(id)).Returns(lowellReference);
            this._webActivityService.Setup(x => x.LogBudgetCalculatorIncome(lowellReference, this._caseflowUserId))
            .Returns(Task.CompletedTask);

            ViewResult result = (ViewResult)await this._controller.Index();

            Assert.AreEqual(id, this._controller.RouteData.Values["id"]);
            Assert.AreEqual(vm, result.Model);
            Assert.AreEqual("HouseholdStatus", result.ViewName);

            Assert.AreEqual(true, vm.ExternallyLaunched);
            Assert.AreEqual(false, vm.SavedIAndE);
            Assert.AreEqual(1, vm.AdultsInHousehold);
        }
        public MonthlyIncome CalculateMonthlyIncome(IncomeAndExpenditure iAndE)
        {
            if (iAndE != null)
            {
                var salary   = ConvertToMonthly(iAndE.Salary, iAndE.SalaryFrequency);
                var benefits = ConvertToMonthly(iAndE.BenefitsTotal, iAndE.BenefitsTotalFrequency);
                var pension  = ConvertToMonthly(iAndE.Pension, iAndE.PensionFrequency);
                var other    = ConvertToMonthly(iAndE.OtherIncome, iAndE.OtherincomeFrequency);

                var total = salary + benefits + other + pension;

                return(new MonthlyIncome()
                {
                    Salary = salary,
                    Benefits = benefits,
                    Other = other,
                    Pension = pension,
                    Total = total,
                });
            }

            return(new MonthlyIncome()
            {
                Salary = 0.00M,
                Benefits = 0.00M,
                Other = 0.00M,
                Pension = 0.00M,
                Total = 0.00M
            });
        }
        public void MakePaymentTest()
        {
            Guid id = Guid.NewGuid();

            IncomeAndExpenditure iAndE = new IncomeAndExpenditure()
            {
                HousingStatus    = "housing-status",
                EmploymentStatus = "employment-status"
            };

            BudgetSummary   budgetSummary   = new BudgetSummary();
            BudgetSummaryVm budgetSummaryVm = new BudgetSummaryVm();

            this._sessionState.Setup(x => x.GetIncomeAndExpenditure(id)).Returns(iAndE);
            this._budgetCalculatorService.Setup(x => x.GetBudgetSummary(
                                                    iAndE, id, this._caseflowUserId)).Returns(budgetSummary);
            this._mapper.Setup(x => x.Map <BudgetSummary, BudgetSummaryVm>(budgetSummary)).Returns(budgetSummaryVm);

            this._gtmService.Setup(x => x.RaiseBudgetCalculatorContinuedToPaymentEvent(
                                       budgetSummaryVm, this._caseflowUserId, "employment-status", "housing-status"));

            RedirectToActionResult result = (RedirectToActionResult)this._controller.MakePayment(id);

            Assert.AreEqual("Index", result.ActionName);
            Assert.AreEqual("PaymentOptions", result.ControllerName);
            Assert.AreEqual(id, result.RouteValues["id"]);
        }
        public void ConvertTest_SourceNull()
        {
            ExpendituresVm       source      = null;
            IncomeAndExpenditure destination = Utilities.CreateDefaultTestIAndE();
            IncomeAndExpenditure expected    = Utilities.DeepCopy(destination);

            expected.Healthcare                    = 0;
            expected.HealthcareFrequency           = null;
            expected.Leisure                       = 0;
            expected.LeisureFrequency              = null;
            expected.Housekeeping                  = 0;
            expected.HousekeepingFrequency         = null;
            expected.OtherExpenditure              = 0;
            expected.OtherExpenditureFrequency     = null;
            expected.PensionInsurance              = 0;
            expected.PensionInsuranceFrequency     = null;
            expected.PersonalCosts                 = 0;
            expected.PersonalCostsFrequency        = null;
            expected.ProfessionalCosts             = 0;
            expected.ProfessionalCostsFrequency    = null;
            expected.SavingsContributions          = 0;
            expected.SavingsContributionsFrequency = null;
            expected.SchoolCosts                   = 0;
            expected.SchoolCostsFrequency          = null;
            expected.Travel          = 0;
            expected.TravelFrequency = null;

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

            //Check result is as expected
            Assert.IsTrue(Utilities.DeepCompare(expected, result));
        }
        public IActionResult BillsAndOutgoings(BillsAndOutgoingsVm viewModel)
        {
            var id = RouteData.Values["id"];

            if (id == null)
            {
                return(RedirectToAction("Index", "MyAccounts"));
            }

            Guid guid = Guid.Parse(id.ToString());

            ApplicationSessionState.CheckSessionStatus(id.ToString());
            viewModel.EnabledPartialSave = _portalSettings.Features.EnablePartialSave && LoggedInUser.IsLoggedInUser;

            IncomeAndExpenditure incomeAndExpenditure = ApplicationSessionState.GetIncomeAndExpenditure(guid);

            if (incomeAndExpenditure == null)
            {
                return(View(viewModel));
            }

            viewModel = _mapper.Map(incomeAndExpenditure, viewModel);

            string housingStatus    = incomeAndExpenditure.HousingStatus;
            string employmentStatus = incomeAndExpenditure.EmploymentStatus;

            _gtmService.RaiseBudgetCalculatorIncomeEvent(viewModel, LoggedInUserId, employmentStatus, housingStatus, viewModel.IncomeSummary.Total);

            return(View(viewModel));
        }
        public void YourIncomeTest()
        {
            string id = Guid.NewGuid().ToString();

            this._controller.RouteData.Values.Add("id", id);
            this._portalSettings.Features.EnablePartialSave = true;

            this._sessionState.Setup(x => x.CheckSessionStatus(id));

            IncomeAndExpenditure iAndE = new IncomeAndExpenditure()
            {
                HousingStatus    = "housing-status",
                EmploymentStatus = "employment-status"
            };

            IncomeVm vm = new IncomeVm();

            this._sessionState.Setup(x => x.GetIncomeAndExpenditure(Guid.Parse(id))).Returns(iAndE);
            this._gtmService.Setup(x => x.RaiseBudgetCalculatorHouseholdDetailsEvent(
                                       vm, this._caseflowUserId, "housing-status", "employment-status"));

            this._mapper.Setup(x => x.Map(iAndE, vm)).Returns(vm);


            ViewResult result = (ViewResult)this._controller.YourIncome(vm);

            Assert.AreEqual(vm, result.Model);
            Assert.AreEqual(true, vm.EnabledPartialSave);
        }
예제 #21
0
        public async Task CreateCustomerSummaryTest()
        {
            List <AccountSummary> accountSummaries = new List <AccountSummary>()
            {
                new AccountSummary()
                {
                    AccountReference = "11111111"
                },
                new AccountSummary()
                {
                    AccountReference = "22222222"
                },
                new AccountSummary()
                {
                    AccountReference = "33333333"
                },
                new AccountSummary()
                {
                    AccountReference = "44444444"
                },
                new AccountSummary()
                {
                    AccountReference = "55555555"
                },
            };

            Dictionary <string, Guid> surrogateKeysByLowellReference = new Dictionary <string, Guid>()
            {
                { "11111111", Guid.NewGuid() },
                { "22222222", Guid.NewGuid() },
                { "33333333", Guid.NewGuid() },
                { "44444444", Guid.NewGuid() },
                { "55555555", Guid.NewGuid() },
            };

            string lowellRef = "12345678";

            IncomeAndExpenditure incomeAndExpenditure = new IncomeAndExpenditure()
            {
                Created          = DateTime.Now,
                DisposableIncome = 999.99M
            };

            _budgetCalculatorService.Setup(x => x.GetSavedIncomeAndExpenditure(lowellRef))
            .Returns(Task.FromResult(incomeAndExpenditure));

            CustomerSummary expected = new CustomerSummary()
            {
                Accounts                       = accountSummaries,
                IncomeAndExpenditure           = incomeAndExpenditure,
                SurrogateKeysByLowellReference = surrogateKeysByLowellReference
            };

            CustomerSummary result = await _service.CreateCustomerSummary(accountSummaries, lowellRef, surrogateKeysByLowellReference);

            string expectedStr = JsonConvert.SerializeObject(expected);
            string resultStr   = JsonConvert.SerializeObject(result);

            Assert.AreEqual(expectedStr, resultStr);
        }
        public void ConvertTest_SourceNull()
        {
            IncomeAndExpenditure source      = null;
            ExpendituresVm       destination = Utilities.CreateDefaultTestExpendituresVm();
            ExpendituresVm       expected    = Utilities.DeepCopy(destination);

            MonthlyIncome   monthlyIncome   = new MonthlyIncome();
            MonthlyIncomeVm monthlyIncomeVm = new MonthlyIncomeVm()
            {
                Benefits = 100,
                Other    = 200,
                Pension  = 300,
                Salary   = 400,
                Total    = 1000
            };

            MonthlyOutgoings   monthlyOutgoings   = new MonthlyOutgoings();
            MonthlyOutgoingsVm monthlyOutgoingsVm = new MonthlyOutgoingsVm()
            {
                Expenditures   = 1000,
                HouseholdBills = 2000,
                Total          = 3000
            };

            _calculatorService.Setup(x => x.CalculateMonthlyIncome(It.IsAny <IncomeAndExpenditure>()))
            .Returns(monthlyIncome);
            _mapper.Setup(x => x.Map <MonthlyIncomeVm>(monthlyIncome)).Returns(monthlyIncomeVm);
            _calculatorService.Setup(x => x.CalculateMonthlyOutgoings(It.IsAny <IncomeAndExpenditure>()))
            .Returns(monthlyOutgoings);
            _mapper.Setup(x => x.Map <MonthlyOutgoingsVm>(monthlyOutgoings)).Returns(monthlyOutgoingsVm);

            expected.CareAndHealthCosts.Amount          = 0;
            expected.CareAndHealthCosts.Frequency       = null;
            expected.CommunicationsAndLeisure.Amount    = 0;
            expected.CommunicationsAndLeisure.Frequency = null;
            expected.FoodAndHouseKeeping.Amount         = 0;
            expected.FoodAndHouseKeeping.Frequency      = null;
            expected.IncomeVmSummary                = monthlyIncomeVm;
            expected.Other.Amount                   = 0;
            expected.Other.Frequency                = null;
            expected.OutgoingsVmSummary             = monthlyOutgoingsVm;
            expected.PensionsAndInsurance.Amount    = 0;
            expected.PensionsAndInsurance.Frequency = null;
            expected.PersonalCosts.Amount           = 0;
            expected.PersonalCosts.Frequency        = null;
            expected.Professional.Amount            = 0;
            expected.Professional.Frequency         = null;
            expected.Savings.Amount                 = 0;
            expected.Savings.Frequency              = null;
            expected.SchoolCosts.Amount             = 0;
            expected.SchoolCosts.Frequency          = null;
            expected.TravelAndTransport.Amount      = 0;
            expected.TravelAndTransport.Frequency   = null;

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

            //Check result is as expected
            Assert.IsTrue(Utilities.DeepCompare(expected, result));
        }
예제 #23
0
        public void SaveIncomeAndExpenditure(IncomeAndExpenditure incomeAndExpenditure, Guid surrogateLowellReference)
        {
            string key = $"{SessionKey.IncomeAndExpenditure}_{surrogateLowellReference}";

            if (key != null)
            {
                _session.SetString(key, JsonConvert.SerializeObject(incomeAndExpenditure));
            }
        }
        public decimal CalculateOtherDebts(IncomeAndExpenditure iAndE)
        {
            if (iAndE.OtherDebts != null && iAndE.OtherDebts.Any())
            {
                return(CalculateOtherDebts(iAndE.OtherDebts));
            }

            return(0.00M);
        }
예제 #25
0
        public void ConvertTest()
        {
            IncomeVm source = new IncomeVm()
            {
                BenefitsAndTaxCredits = new IncomeSourceVm()
                {
                    Amount = 100, Frequency = "weekly"
                },
                Earning = new IncomeSourceVm()
                {
                    Amount = 3000, Frequency = "monthly"
                },
                Pension = new IncomeSourceVm()
                {
                    Amount = 125, Frequency = "fortnightly"
                },
                Other = new IncomeSourceVm()
                {
                    Amount = 50, Frequency = "weekly"
                },
                GtmEvents = new List <GtmEvent>()
                {
                    new GtmEvent()
                    {
                        account_ref = "123456789"
                    }
                },
                EnabledPartialSave        = true,
                HasErrorPartialSavedIAndE = true,
                PartialSavedEvent         = true,
                PartialSavedIAndE         = true
            };

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

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

            expected.BenefitsTotal          = 100;
            expected.BenefitsTotalFrequency = "weekly";
            expected.Salary               = 3000;
            expected.SalaryFrequency      = "monthly";
            expected.OtherIncome          = 50;
            expected.OtherincomeFrequency = "weekly";
            expected.Pension              = 125;
            expected.PensionFrequency     = "fortnightly";

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

            //Check that the result is as expected
            Assert.IsTrue(Utilities.DeepCompare(expected, result));

            //Check that source hasn't been modified
            Assert.IsTrue(Utilities.DeepCompare(source, sourceCopy));
        }
예제 #26
0
        public BudgetSummary GetBudgetSummary(IncomeAndExpenditure incomeAndExpenditure, Guid lowellReferenceSurrogateKey, string loggedInUserId)
        {
            var monthlyIncome    = _calculatorService.CalculateMonthlyIncome(incomeAndExpenditure);
            var monthlyExpenses  = _calculatorService.CalculateMonthlyOutgoings(incomeAndExpenditure);
            var disposableIncome = _calculatorService.CalculateDisposableIncome(monthlyIncome.Total, monthlyExpenses.Total);

            var budgetSummary = CreateBudgetSummary(monthlyIncome, monthlyExpenses, disposableIncome, incomeAndExpenditure, string.IsNullOrEmpty(loggedInUserId));

            return(budgetSummary);
        }
예제 #27
0
        public async Task SaveIncomeAndExpenditure(IncomeAndExpenditure incomeAndExpenditure, string lowellReference)
        {
            incomeAndExpenditure.LowellReference = lowellReference;
            var incomeAndExpenditureDto =
                _mapper.Map <IncomeAndExpenditure, IncomeAndExpenditureApiModel>(incomeAndExpenditure);

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

            await _restClient.PostNoResponseAsync(innerUrl, incomeAndExpenditureDto);
        }
예제 #28
0
        public void ConvertTest_SourceNull()
        {
            IncomeAndExpenditure destination = new IncomeAndExpenditure();

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

            Assert.AreEqual(null, result);

            //Check that destination hasn't been modified
            Assert.IsTrue((Utilities.DeepCompare(new IncomeAndExpenditure(), destination)));
        }
        public async Task <IActionResult> HouseholdStatus(HouseholdStatusVm viewModel)
        {
            ModelState.Clear();
            ApplicationSessionState.IandELaunchedExternally = false;

            var id = RouteData.Values["id"];

            if (id == null)
            {
                return(RedirectToAction("Index", "MyAccounts"));
            }

            ApplicationSessionState.CheckSessionStatus(id.ToString());
            Guid guid = Guid.Parse(id.ToString());

            string lowellReference = ApplicationSessionState.GetLowellReferenceFromSurrogate(guid);

            Guid caseflowUserId = LoggedInUser.IsLoggedInUser ? Guid.Parse(GetCaseflowUserId()) : Guid.NewGuid();

            IncomeAndExpenditure savedIAndE = await _budgetCalculatorService.GetSavedIncomeAndExpenditure(lowellReference);

            IncomeAndExpenditure partialSavedIAndE = viewModel.PartialSavedIAndE ? await _budgetCalculatorService.GetPartiallySavedIncomeAndExpenditure(LoggedInUserId, caseflowUserId) : null;

            IncomeAndExpenditure iAndE = partialSavedIAndE != null ? partialSavedIAndE : savedIAndE;

            if (iAndE == null)
            {
                //See if there is a cached I & E from OpenWrks
                iAndE = this.ApplicationSessionState.GetIncomeAndExpenditure(guid);
            }

            if (iAndE != null)
            {
                iAndE.BudgetSource = "";

                ApplicationSessionState.SaveIncomeAndExpenditure(iAndE, guid);
                await _webActivityService.LogBudgetCalculatorReplayed(ApplicationSessionState.GetLoggedInLowellRef(), LoggedInUserId);

                viewModel                   = _mapper.Map(iAndE, viewModel);
                viewModel.SavedIAndE        = true;
                viewModel.PartialSavedIAndE = partialSavedIAndE != null;
            }

            await _webActivityService.LogBudgetCalculatorHouseholdDetails(lowellReference, LoggedInUserId);

            _gtmService.RaiseBudgetCalculatorStartedEvent(viewModel, LoggedInUserId);

            if (viewModel.AdultsInHousehold == null)
            {
                viewModel.AdultsInHousehold = 1;
            }

            return(View(viewModel));
        }
예제 #30
0
        public List <SaveOtherDebtsApiModel> CreateOtherDebts(IncomeAndExpenditure iAndE)
        {
            var otherDebts = new List <SaveOtherDebtsApiModel>();

            if (iAndE.OtherDebts != null && iAndE.OtherDebts.Any())
            {
                iAndE.OtherDebts.ForEach(i =>
                {
                    otherDebts.Add(new SaveOtherDebtsApiModel()
                    {
                        Amount               = i.Amount,
                        Arrears              = i.Arrears,
                        Frequency            = i.Frequency,
                        CountyCourtJudgement = false
                    });
                });
            }


            if (iAndE.CourtFines > 0.00M)
            {
                otherDebts.Add(new SaveOtherDebtsApiModel()
                {
                    Amount               = iAndE.CourtFines,
                    Arrears              = iAndE.CourtFinesArrears,
                    Frequency            = ConvertFrequencyToInitial(iAndE.CourtFinesFrequency),
                    CountyCourtJudgement = false
                });
            }

            if (iAndE.CCJs > 0.00M)
            {
                otherDebts.Add(new SaveOtherDebtsApiModel()
                {
                    Amount               = iAndE.CCJs,
                    Arrears              = iAndE.CCJsArrears,
                    Frequency            = ConvertFrequencyToInitial(iAndE.CCJsFrequency),
                    CountyCourtJudgement = true
                });
            }

            if (iAndE.OtherExpenditure > 0.00M)
            {
                otherDebts.Add(new SaveOtherDebtsApiModel()
                {
                    Amount               = iAndE.OtherExpenditure,
                    Arrears              = 0.00M,
                    Frequency            = ConvertFrequencyToInitial(iAndE.OtherExpenditureFrequency),
                    CountyCourtJudgement = false
                });
            }

            return(otherDebts);
        }