Ejemplo n.º 1
0
        public BonusPoolCalculatorResultDomainModel Calculate(BonusPoolCalculatorDomainModel domainModel)
        {
            if (domainModel == null)
            {
                throw new ArgumentNullException("viewModel model to calculate was null");
            }

            var selectedEmployeeId = domainModel.SelectedEmployeeId;
            var totalBonusPool     = domainModel.BonusPoolAmount;

            //load the details of the selected employee using the ID
            var hrEmployee = _repository.Get(selectedEmployeeId);

            if (hrEmployee == null)
            {
                throw new EmployeeNotFoundException();
            }

            var employeeSalary = hrEmployee.Salary;

            //get the total salary budget for the company
            var totalSalary = _repository.GetAll().Sum(item => item.Salary);

            //calculate the bonus allocation for the employee
            var bonusPercentage = employeeSalary / (decimal)totalSalary;
            var bonusAllocation = (uint)(bonusPercentage * totalBonusPool);

            var result = new BonusPoolCalculatorResultDomainModel
            {
                HrEmployee          = _mappingHelper.Map <EmployeeDomainModel>(hrEmployee),
                BonusPoolAllocation = bonusAllocation
            };

            return(result);
        }
        public void CalculationWhereUserNotFoundThrowsEmployeeNotFoundException()
        {
            var sut = _testHelper.GetBonusPoolService(populateRepository: true);

            var bonusPoolCalculatorDomainModel = new BonusPoolCalculatorDomainModel()
            {
                BonusPoolAmount    = 500,
                SelectedEmployeeId = 100
            };

            sut.Calculate(bonusPoolCalculatorDomainModel);
        }