public void calculatePayslip() { String stringPayslipPeriod = "Dec 2015"; uint annualSalary = 18000; uint superRate = 8; decimal expectedGrossIncome = 1500; decimal expectedIncomeTax = 0.00M; uint expectedNetIncome = 1500; uint expectedSuper = 120; Calculator calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); uint grossIncome = calc.getGrossIncome(); decimal netIncome = calc.getNetIncome(); decimal incomeTax = calc.getIncomeTax(); decimal super = calc.getSuper(); // this will appear in the output of the testes, // we could as well use log4net for that with the // console setup Console.WriteLine("grossIncome = {0}", grossIncome); Console.WriteLine("netIncome = {0}", netIncome); Console.WriteLine("incomeTax = {0}", incomeTax); Console.WriteLine("super = {0}", super); Assert.AreEqual(expectedGrossIncome, grossIncome); Assert.AreEqual(expectedNetIncome, netIncome); Assert.AreEqual(expectedIncomeTax, incomeTax); Assert.AreEqual(expectedSuper, super); Console.WriteLine("test passed ok"); }
// net income is the gross income minus income tax public void calculateNetIncomeTest() { String stringPayslipPeriod = "Dec 2015"; uint annualSalary = 80000; uint superRate = 2; // this is 80000/12 - 1462 = 5205 decimal expectedNetIncome = 5205; Calculator calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); decimal netIncome = calc.getNetIncome(); Console.WriteLine("annualSalary = {0} expected net Income = {1}, actual net Income = {2}", annualSalary, expectedNetIncome, netIncome); Assert.AreEqual(expectedNetIncome, netIncome); // we should check boundary condition as well, // when the tax threshold changes, here just one annualSalary = 180000; // this is 15000 gross - 4546 tax expectedNetIncome = 10454; calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); netIncome = calc.getNetIncome(); Console.WriteLine("annualSalary = {0} expected net Income = {1}, actual net Income = {2}", annualSalary, expectedNetIncome, netIncome); Assert.AreEqual(expectedNetIncome, netIncome); Console.WriteLine("test passed ok"); }
private Payslip calculateThePaySlip() { Payslip payslip = new Payslip(); //set the user details, say header of the payslip payslip.stringFirstName = this.stringFirstName; payslip.stringLastName = this.stringLastName; payslip.stringPayslipPeriod = this.dateTimePickerPaysleepPeriod.Value.ToString("MMM yyyy"); // set the calculated values // this is mm yyyy // we should get the number of days after the start date of employment // here we assume the employee has been working the full month // and we don't check the employment start date Calculator calculator = new Calculator(stringPayslipPeriod, uintAnnualSalary, uintSuperRate); payslip.decimalGrossIncome = calculator.getGrossIncome(); payslip.decimalIncomeTax = calculator.getIncomeTax(); payslip.decimalNetIncome = calculator.getNetIncome(); payslip.decimalSuper = calculator.getSuper(); // ready for display return payslip; }