Пример #1
0
        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");

        }
Пример #2
0
        // this should test the formula for calculating the super, which is:
        // grossIncome * superRate / 100;
        // however this is encapsultaed in the Calculator, 
        // so we let the calculator to do it then check the result
        public void calculateSuperTest()
        {
            String stringPayslipPeriod = "Dec 2015";
            uint annualSalary = 80000;
            uint superRate = 2;

            // this is 80000/12 - 1462 = 5205
            decimal expectedSuper = 133;
            Calculator calc = new Calculator(stringPayslipPeriod, annualSalary, superRate);
            decimal super = calc.getSuper();
            Console.WriteLine("annualSalary = {0} expected super = {1}, actual super = {2}",
                                    annualSalary, expectedSuper, super);
            Assert.AreEqual(expectedSuper, super);

            // we should do more tests, like for 0%, 100%, over 100%

            Console.WriteLine("test passed ok");
        }
Пример #3
0
        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;
        }