Example #1
0
        public void PopulateEmployeePayShouldSucceed()
        {
            var employee = GetEmployee(1);

            PayAndBenifitCalculator.PopulateEmployeePay(employee);

            employee.PayPerPeriod.Should().Be(AppConstants.DefaultPayPerPeriod);
        }
Example #2
0
        public void PopulateBenefitCostWithDiscountShouldSucceed()
        {
            var employee = GetEmployee(1);

            employee.FirstName = AppConstants.FirstLetterDiscountLetter;

            employee.Dependents.First().FirstName = AppConstants.FirstLetterDiscountLetter;

            var payPerPeriod = round(AppConstants.DefaultPayPerPeriod);

            var payPerYear = round(payPerPeriod * AppConstants.NumberOfPayPeriods);

            var dependentTotalCostPerYear = round(AppConstants.DependentCost * AppConstants.FirstLetterDiscountAmount);

            var employeeTotalCostPerYear = round(AppConstants.EmployeeCost * AppConstants.FirstLetterDiscountAmount);

            var employeeAndDependentsTotalCostPerYear = dependentTotalCostPerYear + employeeTotalCostPerYear;

            var employeeTotalCostPerPayPeriod = round(employeeTotalCostPerYear / AppConstants.NumberOfPayPeriods);

            var dependentTotalCostPerPeriod = round(dependentTotalCostPerYear / AppConstants.NumberOfPayPeriods);

            var employeeAndDependentsTotalCostPerPayPeriod = employeeTotalCostPerPayPeriod + dependentTotalCostPerPeriod;

            var netPayPerYear = payPerYear - employeeAndDependentsTotalCostPerYear;

            var netPayPerPeriod = payPerPeriod - employeeAndDependentsTotalCostPerPayPeriod;

            var lessCostForLastPayPeriod = round((round(employeeTotalCostPerPayPeriod * AppConstants.NumberOfPayPeriods) - employeeTotalCostPerYear) + (round(dependentTotalCostPerPeriod * AppConstants.NumberOfPayPeriods) - dependentTotalCostPerYear));

            PayAndBenifitCalculator.PopulateEmployeePay(employee);

            PayAndBenifitCalculator.PopulateBenifitCost(employee);

            employee.PayPerPeriod.Should().Be(payPerPeriod);

            employee.PayPerYear.Should().Be(payPerYear);

            employee.EmployeeAndDependentsTotalCostPerYear.Should().Be(employeeAndDependentsTotalCostPerYear);

            employee.EmployeeAndDependentsTotalCostPerPayPeriod.Should().Be(employeeAndDependentsTotalCostPerPayPeriod);

            employee.EmployeeTotalCostPerPayPeriod.Should().Be(employeeTotalCostPerPayPeriod);

            employee.EmployeeTotalCostPerYear.Should().Be(employeeTotalCostPerYear);

            employee.NetPayPerPeriod.Should().Be(netPayPerPeriod);

            employee.NetPayPerYear.Should().Be(netPayPerYear);

            employee.LessCostForLastPayPeriod.Should().Be(lessCostForLastPayPeriod);

            employee.Dependents.First().DependentTotalCostPerPayPeriod.Should().Be(dependentTotalCostPerPeriod);

            employee.Dependents.First().DependentTotalCostPerYear.Should().Be(dependentTotalCostPerYear);
        }
        public async Task <int> UpdateEmployeeAsync(Employee employee)
        {
            PayAndBenifitCalculator.PopulateEmployeePay(employee);

            PayAndBenifitCalculator.PopulateBenifitCost(employee);

            _employeeValidator.ValidateAndThrow(employee);

            return(await _repository.UpdateEmployeeAsync(_mapper.Map <Repository.Models.Employee>(employee)));
        }
        public async Task <Employee> AddEmployeeAsync(Employee employee)
        {
            PayAndBenifitCalculator.PopulateEmployeePay(employee);

            PayAndBenifitCalculator.PopulateBenifitCost(employee);

            _employeeValidator.ValidateAndThrow(employee);

            var result = await _repository.AddEmployeeAsync(_mapper.Map <Repository.Models.Employee>(employee));

            return(_mapper.Map <Employee>(result));
        }