コード例 #1
0
        public void ReturnsBonusPoolCalculation()
        {
            // arrange
            var serviceMock      = new Mock <IBonusPoolService>();
            var allStubEmployees = _stubEmployees;

            var bonusPoolCalculatorResultModel = new BonusPoolCalculatorResultDomainModel
            {
                BonusPoolAllocation = 100,
                HrEmployee          = allStubEmployees.Last()
            };

            serviceMock
            .Setup(s => s.Calculate(It.IsAny <BonusPoolCalculatorDomainModel>()))
            .Returns(bonusPoolCalculatorResultModel);

            // act
            var result = new BonusPoolController(serviceMock.Object, new MappingHelper <ApiMapperProfile>())
                         .Calculate(new BonusPoolCalculatorViewModel
            {
                BonusPoolAmount    = 100,
                SelectedEmployeeId = allStubEmployees.Last().Id
            })
                         as ViewResult;

            var actual = result?.Model as BonusPoolCalculatorResultViewModel;

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(Json.Encode(bonusPoolCalculatorResultModel.BonusPoolAllocation), Json.Encode(actual.BonusPoolAllocation));
        }
コード例 #2
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);
        }
コード例 #3
0
        public void ReturnsBonusPoolCalculation()
        {
            var sut = _testHelper.GetBonusPoolService(populateRepository: true);


            const int employeeId = 3;
            var       actual     = sut.Calculate(
                new BonusPoolCalculatorDomainModel
            {
                BonusPoolAmount    = 500,
                SelectedEmployeeId = employeeId
            });

            var expected = new BonusPoolCalculatorResultDomainModel
            {
                BonusPoolAllocation = 62,
                HrEmployee          = new MappingHelper <DomainMapperProfile>()
                                      .Map <EmployeeDomainModel>(_testHelper.GetStubEmployees().FirstOrDefault(x => x.Id == employeeId))
            };

            Assert.AreEqual(Json.Encode(expected), Json.Encode(actual));
        }