public void EmployeeSalaryCannotBeMoreThanWageBudget(BonusPoolTestData testData) { var calculator = new BonusPoolCalculator(testData.WageBudget, testData.BonusPoolValue); Action calculate = () => calculator.CalculateBonusAllocation(testData.EmployeeSalary); Assert.ThrowsException <ArgumentOutOfRangeException>(calculate, "Employee salary cannot be greater than the wage budget"); }
public void BonusIsGivenToTwoDecimalPlaces(BonusPoolTestData testData) { var calculator = new BonusPoolCalculator(testData.WageBudget, testData.BonusPoolValue); decimal bonus = calculator.CalculateBonusAllocation(testData.EmployeeSalary); decimal bonusRounded = Decimal.Round(bonus, 2); Assert.AreEqual(bonusRounded, bonus); }
public void BonusPercentageOfPoolEqualsSalaryPercentageOfWageBudget(BonusPoolTestData testData) { var calculator = new BonusPoolCalculator(testData.WageBudget, testData.BonusPoolValue); decimal basePercentage = testData.WageBudget != 0 ? testData.EmployeeSalary / testData.WageBudget : 0; decimal expectedBonus = Math.Floor(basePercentage * testData.BonusPoolValue * 100) / 100; decimal bonus = calculator.CalculateBonusAllocation(testData.EmployeeSalary); Assert.AreEqual(expectedBonus, bonus); }
public ActionResult Calculate(BonusPoolCalculatorModel model) { int selectedEmployeeId = model.SelectedEmployeeId; int totalBonusPool = model.BonusPoolAmount; //load the details of the selected employee using the ID HrEmployee hrEmployee = _hrEmployeeRepository.Get(selectedEmployeeId); int employeeSalary = hrEmployee.Salary; //get the total salary budget for the company int totalSalary = _hrEmployeeRepository.GetSumOfSalaries(); //calculate the bonus allocation for the employee BonusPoolCalculator calculator = new BonusPoolCalculator(totalSalary, totalBonusPool); decimal bonusAllocation = calculator.CalculateBonusAllocation(employeeSalary); BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel(); result.hrEmployee = hrEmployee; result.bonusPoolAllocation = bonusAllocation; return(View(result)); }