public async Task Calculate() { var employee = _fixture.Create <HrEmployee>(); _mockedEmployeeService.Setup(svc => svc.GetEmployeeByIdAsync(It.IsAny <int>())) .ReturnsAsync(employee); var totalSalary = 100000; _mockedEmployeeService.Setup(svc => svc.GetTotalSalaryOfAllEmployees()) .ReturnsAsync(totalSalary); var bonusShare = 30; _mockedBonusCalculator.Setup(svc => svc.GetBonusForEmployee(It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <decimal>())) .Returns(bonusShare); var request = new BonusPoolCalculatorModel { SelectedEmployeeId = 2, BonusPoolAmount = 10000 }; var result = await SUT.Calculate(request); _mockedEmployeeService.Verify(svc => svc.GetEmployeeByIdAsync(request.SelectedEmployeeId), Times.Once); _mockedEmployeeService.Verify(svc => svc.GetTotalSalaryOfAllEmployees(), Times.Once); _mockedBonusCalculator.Verify(svc => svc.GetBonusForEmployee(employee.Salary, totalSalary, request.BonusPoolAmount)); var viewResult = result.ShouldBeAssignableTo <ViewResult>(); var resultModel = viewResult.Model.ShouldBeAssignableTo <BonusPoolCalculatorResultModel>(); resultModel.HrEmployee.ShouldBe(employee); resultModel.BonusPoolAllocation.ShouldBe(bonusShare); }
public void Calculate_Throws_An_Exception_When_The_Employye_Is_Not_Found() { // Arrange var sut = new BonusPoolController(_bonusCalculatorService.Object, _hrEmployeeRepository.Object); // Assert Assert.ThrowsException <Exception>(() => sut.Calculate(NewBonusPoolCalculatorModel())); }
public void Calculate_Uses_Calculate_From_IBonusCalculatorService_To_Calculate_The_Bonus() { // Arrange _hrEmployeeRepository.Setup(r => r.GetById(It.IsAny <int>())).Returns(NewHrEmployee()); var sut = new BonusPoolController(_bonusCalculatorService.Object, _hrEmployeeRepository.Object); // Act sut.Calculate(NewBonusPoolCalculatorModel()); // Assert _bonusCalculatorService.Verify(s => s.Calculate(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once); }
public void Should_call_CalculateBonusForEmployee_for_Calculate() { _controller.Calculate(null); _mockCalculatorService.Received(1).CalculateBonusForEmployee(null); }