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 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 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)); }
public async Task BillsAndOutgoingsPostTest_SaveForLater() { 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); this._budgetCalculatorService.Setup(x => x.PartiallySaveIncomeAndExpenditure( iAndE, lowellReference, Guid.Parse(this._caseflowUserId))).Returns(Task.FromResult(true)); ViewResult result = (ViewResult)await this._controller .BillsAndOutgoingsPost(vm, "saveforlater"); Assert.AreEqual("BillsAndOutgoings", result.ViewName); Assert.AreEqual(vm, result.Model); Assert.IsTrue(vm.EnabledPartialSave); Assert.IsTrue(vm.PartialSavedEvent); Assert.IsTrue(vm.PartialSavedIAndE); Assert.IsFalse(vm.HasErrorPartialSavedIAndE); }
public void ConvertTest_DestinationNull() { IncomeAndExpenditure source = new IncomeAndExpenditure() { Mortgage = 100, MortgageArrears = 10, MortgageFrequency = "monthly", Rental = 150, RentalArrears = 0, RentalFrequency = "weekly", Electricity = 200, ElectricityArrears = 20, ElectricityFrequency = "fortnightly", CCJs = 250, CCJsArrears = 0, CCJsFrequency = "monthly", ChildMaintenance = 300, ChildMaintenanceArrears = 30, ChildMaintenanceFrequency = "weekly", CouncilTax = 350, CouncilTaxArrears = 0, CouncilTaxFrequency = "fortnightly", CourtFines = 400, CourtFinesArrears = 40, CourtFinesFrequency = "monthly", Gas = 450, GasArrears = 0, GasFrequency = "weekly", OtherUtilities = 500, OtherUtilitiesArrears = 50, OtherUtilitiesFrequency = "fortnightly", Rent = 550, RentArrears = 0, RentFrequency = "monthly", SecuredLoans = 600, SecuredloansArrears = 60, SecuredLoansFrequency = "weekly", TvLicence = 650, TvLicenceArrears = 0, TvLicenceFrequency = "fortnightly", Water = 700, WaterArrears = 70, WaterFrequency = "monthly", AdultsInHousehold = 1, ChildrenUnder16 = 2, Children16to18 = 3, HasArrears = true, UtilitiesTotal = 750, UtilitiesTotalArrears = 0, UtilitiesTotalFrequency = "weekly", User = "******", Created = DateTime.Now.Date, Healthcare = 800, HealthcareFrequency = "fortnightly", HomeContents = 850, HomeContentsArrears = 0, HomeContentsFrequency = "monthly", EmploymentStatus = "student", Housekeeping = 900, HousekeepingFrequency = "monthly", HousingStatus = "homeowner", DisposableIncome = 999.99M, BenefitsTotal = 888.88M, BenefitsTotalFrequency = "monthly", Leisure = 50, LeisureFrequency = "weekly", OtherDebts = new List <SaveOtherDebts>(), OtherExpenditure = 60, OtherExpenditureFrequency = "fortnightly", OtherIncome = 500, OtherincomeFrequency = "monthly", LowellReference = "123456789", EarningsTotal = 10000, EarningsTotalFrequency = "monthly", PersonalCosts = 225, PersonalCostsFrequency = "monthly", Pension = 400, PensionFrequency = "monthly", Salary = 9999, SalaryFrequency = "monthly", SavingsContributions = 55, SavingsContributionsFrequency = "weekly", SchoolCosts = 5, SchoolCostsFrequency = "weekly", Travel = 45, TravelFrequency = "fortnightly", ProfessionalCosts = 123, ProfessionalCostsFrequency = "monthly", IncomeTotal = 1234.56M, PensionInsurance = 75, PensionInsuranceFrequency = "monthly", ExpenditureTotal = 1000 }; //Create a copy of source for later IncomeAndExpenditure sourceCopy = Utilities.DeepCopy(source); 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 = 123, HouseholdBills = 456, Total = 789 }; BillsAndOutgoingsVm destination = null; BillsAndOutgoingsVm expected = new BillsAndOutgoingsVm(); expected.Mortgage = new OutgoingSourceVm() { Amount = 100, ArrearsAmount = 10, Frequency = "monthly", InArrears = true }; expected.ApplianceOrFurnitureRental = new OutgoingSourceVm() { Amount = 150, ArrearsAmount = 0, Frequency = "weekly", InArrears = false }; expected.Electric = new OutgoingSourceVm() { Amount = 200, ArrearsAmount = 20, Frequency = "fortnightly", InArrears = true }; expected.Ccjs = new OutgoingSourceVm() { Amount = 250, ArrearsAmount = 0, Frequency = "monthly", InArrears = false }; expected.ChildMaintenance = new OutgoingSourceVm() { Amount = 300, ArrearsAmount = 30, Frequency = "weekly", InArrears = true }; expected.CouncilTax = new OutgoingSourceVm() { Amount = 350, ArrearsAmount = 0, Frequency = "fortnightly", InArrears = false }; expected.CourtFines = new OutgoingSourceVm() { Amount = 400, ArrearsAmount = 40, Frequency = "monthly", InArrears = true }; expected.Gas = new OutgoingSourceVm() { Amount = 450, ArrearsAmount = 0, Frequency = "weekly", InArrears = false }; expected.OtherFuel = new OutgoingSourceVm() { Amount = 500, ArrearsAmount = 50, Frequency = "fortnightly", InArrears = true }; expected.Rent = new OutgoingSourceVm() { Amount = 550, ArrearsAmount = 0, Frequency = "monthly", InArrears = false }; expected.SecuredLoan = new OutgoingSourceVm() { Amount = 600, ArrearsAmount = 60, Frequency = "weekly", InArrears = true }; expected.TvLicense = new OutgoingSourceVm() { Amount = 650, ArrearsAmount = 0, Frequency = "fortnightly", InArrears = false }; expected.Water = new OutgoingSourceVm() { Amount = 700, ArrearsAmount = 70, Frequency = "monthly", InArrears = true }; expected.IncomeSummary = monthlyIncomeVm; expected.OutgoingSummary = monthlyOutgoingsVm; _calculatorService.Setup(x => x.CalculateMonthlyIncome(source)).Returns(monthlyIncome); _calculatorService.Setup(x => x.CalculateMonthlyOutgoings(source)).Returns(monthlyOutgoings); _mapper.Setup(x => x.Map <MonthlyIncomeVm>(monthlyIncome)).Returns(monthlyIncomeVm); _mapper.Setup(x => x.Map <MonthlyOutgoingsVm>(monthlyOutgoings)).Returns(monthlyOutgoingsVm); BillsAndOutgoingsVm 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)); }
public void ConvertTest_SourceNull() { IncomeAndExpenditure source = null; BillsAndOutgoingsVm destination = Utilities.CreateDefaultTestBillsAndOutgoingsVm(); BillsAndOutgoingsVm expected = Utilities.DeepCopy(destination); MonthlyIncome monthlyIncome = new MonthlyIncome(); MonthlyIncomeVm monthlyIncomeVm = new MonthlyIncomeVm() { Benefits = 100, Other = 200, Salary = 300, Pension = 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.ApplianceOrFurnitureRental.Amount = 0; expected.ApplianceOrFurnitureRental.ArrearsAmount = 0; expected.ApplianceOrFurnitureRental.Frequency = null; expected.ApplianceOrFurnitureRental.InArrears = false; expected.Ccjs.Amount = 0; expected.Ccjs.ArrearsAmount = 0; expected.Ccjs.Frequency = null; expected.Ccjs.InArrears = false; expected.ChildMaintenance.Amount = 0; expected.ChildMaintenance.ArrearsAmount = 0; expected.ChildMaintenance.Frequency = null; expected.ChildMaintenance.InArrears = false; expected.CouncilTax.Amount = 0; expected.CouncilTax.ArrearsAmount = 0; expected.CouncilTax.Frequency = null; expected.CouncilTax.InArrears = false; expected.CourtFines.Amount = 0; expected.CourtFines.ArrearsAmount = 0; expected.CourtFines.Frequency = null; expected.CourtFines.InArrears = false; expected.Electric.Amount = 0; expected.Electric.ArrearsAmount = 0; expected.Electric.Frequency = null; expected.Electric.InArrears = false; expected.Gas.Amount = 0; expected.Gas.ArrearsAmount = 0; expected.Gas.Frequency = null; expected.Gas.InArrears = false; expected.IncomeSummary = monthlyIncomeVm; expected.OutgoingSummary = monthlyOutgoingsVm; expected.Mortgage.Amount = 0; expected.Mortgage.ArrearsAmount = 0; expected.Mortgage.Frequency = null; expected.Mortgage.InArrears = false; expected.OtherFuel.Amount = 0; expected.OtherFuel.ArrearsAmount = 0; expected.OtherFuel.Frequency = null; expected.OtherFuel.InArrears = false; expected.Rent.Amount = 0; expected.Rent.ArrearsAmount = 0; expected.Rent.Frequency = null; expected.Rent.InArrears = false; expected.SecuredLoan.Amount = 0; expected.SecuredLoan.ArrearsAmount = 0; expected.SecuredLoan.Frequency = null; expected.SecuredLoan.InArrears = false; expected.TvLicense.Amount = 0; expected.TvLicense.ArrearsAmount = 0; expected.TvLicense.Frequency = null; expected.TvLicense.InArrears = false; expected.Water.Amount = 0; expected.Water.ArrearsAmount = 0; expected.Water.Frequency = null; expected.Water.InArrears = false; BillsAndOutgoingsVm result = _converter.Convert(source, destination, null); //Check result is as expected Assert.IsTrue(Utilities.DeepCompare(expected, result)); }