public void CalculateEmployeeBonusTest2() { // Arrange Fixture fixture = new Fixture(); fixture.Customizations.Add( new TypeRelay( typeof(IHrEmployee), typeof(HrEmployee))); IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); EmployeeService employeeService = new EmployeeService(unitOfWork); int bonusPool = 70000; IHrEmployee employee = fixture.Create <HrEmployee>(); employee.Salary = 30000; List <IHrEmployee> employees = fixture.CreateMany <IHrEmployee>(3).ToList(); employees[0].Salary = 30000; employees[1].Salary = 35000; employees[2].Salary = 35000; // 30000 + 35000 + 35000 = 100000 // 30000 is 30% of 120000 // 30 % of 70000 is 21000 // Act decimal result = employeeService.CalculateEmployeeBonus(bonusPool, employee, employees); // Asset int expectedResult = 21000; Assert.AreEqual(expectedResult, result); }
public decimal CalculateEmployeeBonus(int totalBonusPool, IHrEmployee employee, List <IHrEmployee> employees) { int totalSalary = employees.Sum(x => x.Salary); decimal bonusPercentage = (decimal)employee.Salary / (decimal)totalSalary; decimal bonusPoolAllocation = (decimal)totalBonusPool * (decimal)bonusPercentage; return(bonusPoolAllocation); }
public ActionResult Calculate(BonusPoolCalculatorModel model) { int.TryParse(model.SelectedEmployeeId_Enc.Decrypt(), out int selectedEmployeeId); int totalBonusPool = model.BonusPoolAmount; IHrEmployee hrEmployee = _employeeService.GetHrEmployee(selectedEmployeeId); decimal bonusAllocation = _employeeService.CalculateEmployeeBonus(totalBonusPool, hrEmployee, _employeeService.GetHrEmployees()); HrEmployeeViewModel hrEmployeeViewModel = new HrEmployeeViewModel() { ID_Enc = hrEmployee.HrDepartmentId.ToString() , Full_Name = hrEmployee.Full_Name }; BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel { hrEmployee = hrEmployee, bonusPoolAllocation = bonusAllocation }; return(View(result)); }
/// <summary> /// Initializes a new instance of the <see cref="HrEmployeeController" /> class. /// </summary> /// <param name="hremployee"></param> public HrEmployeeController(IHrEmployee hremployee) { _hremployee = hremployee; }
public IHrEmployee GetHrEmployee(int employeeId) { IHrEmployee employee = _unitOfWork.EmployeeRepository.Get(x => x.ID == employeeId).FirstOrDefault <IHrEmployee>(); return(employee); }