Пример #1
0
        public void TestEmployeeDeduction()
        {
            var employee1 = new Employee("John", "Smith");
            var cost      = DeductionCalculator.CalculateDeductionCost(employee1);

            Assert.IsTrue(cost == 1000.0M);
        }
Пример #2
0
        public void TestEmployeeDeductionWithDiscount()
        {
            var employee1 = new Employee("Anna", "Jones");
            var cost1     = DeductionCalculator.CalculateDeductionCost(employee1);

            Assert.IsTrue(cost1 == (decimal.Multiply(employeeDeduction, .10M)));
        }
Пример #3
0
        public void TestEmployeeDeductionWithDependents()
        {
            decimal cost;
            var     employee1 = new Employee("Anna", "Jones");

            cost = DeductionCalculator.CalculateDeductionCost(employee1);
            Assert.IsTrue(employeeDeduction * .10M == cost);
            employee1.AddDependent(new Dependent(DependentType.Spouse, "John", "Doe"));

            DependentDeductionCalculator d = new DependentDeductionCalculator();

            cost = employeeDeduction * .10M + d.CalculateDeduction("John");

            Assert.IsTrue(cost == DeductionCalculator.CalculateDeductionCost(employee1));
        }
Пример #4
0
        public void TestEmployeeDeductionWithMultipleDependents()
        {
            decimal cost;
            decimal cost1;
            decimal cost2;
            DependentDeductionCalculator d = new DependentDeductionCalculator();
            var employee1 = new Employee("Anna", "Jones");

            cost = DeductionCalculator.CalculateDeductionCost(employee1);
            Assert.IsTrue(employeeDeduction * .10M == cost);
            employee1.AddDependent(new Dependent(DependentType.Spouse, "Amy", "Doe"));
            cost1 = d.CalculateDeduction("Amy");

            employee1.AddDependent(new Dependent(DependentType.Spouse, "Antoine", "Doe"));
            cost2 = d.CalculateDeduction("Antoine");


            Assert.IsTrue((employeeDeduction * .10M) + (2 * (dependentDeduction * .10M)) == DeductionCalculator.CalculateDeductionCost(employee1));
        }
Пример #5
0
        public ActionResult CalculateEmployeeDeductions(EmployeeEditViewModel employeeViewModel)
        {
            Employee employee = new Employee(employeeViewModel.FirstName, employeeViewModel.LastName);

            if (employeeViewModel.Dependents != null)
            {
                employeeViewModel.Dependents.ForEach(d => employee.AddDependent(new Dependent(d.DependentType, d.FirstName, d.LastName)));
            }

            decimal cost      = DeductionCalculator.CalculateDeductionCost(employee);
            decimal finalCost = DeductionCalculator.Compute(employee.GetSalary(), cost);

            return(Json(new
            {
                Salary = employee.GetSalary().ToString("C"),
                Deduction = $"{cost.ToString("C")}",
                Total = $"{finalCost.ToString("C")}"
            }));
        }