Esempio n. 1
0
        public void GetSalaryByEmployeeId_ThrowException_WhenEmployeeNotFound()
        {
            //Arrange
            var employee = new Employee()
            {
                Id       = 1,
                SalaryId = 2
            };

            List <Employee> lstEmp = new List <Employee>();

            _actionFactoryMock     = new Mock <IActionFactory>();
            _repositoryFactoryMock = new Mock <IRepositoryFactory>();
            HelperSer = new Mock <HelperSer>();


            _actionFactoryMock.Setup(action => action.EmployeeService.GetAllEmployees()).Returns(lstEmp);

            SalaryService = new SalaryService(_actionFactoryMock.Object, _repositoryFactoryMock.Object, HelperSer.Object);

            //Act
            SalaryService.GetSalaryByEmployeeId(employee.Id);

            //Assert
            _actionFactoryMock.Verify(action => action.EmployeeService.GetAllEmployees(), Times.Once);
        }
Esempio n. 2
0
        public void GetSalaryByEmployeeIdAndCalulateGrossSalary()
        {
            //Arrange
            var salary = new Salary()
            {
                Incentives = 20_0,
                Basic      = 30_0,
                Bonus      = 10_0,
            };
            var employee = new Employee()
            {
                Id       = 1,
                SalaryId = 2
            };

            List <Employee> lstEmp = new List <Employee>
            {
                employee
            };

            _actionFactoryMock     = new Mock <IActionFactory>();     //Interface mocking
            _repositoryFactoryMock = new Mock <IRepositoryFactory>(); //Interface mocking
            HelperSer = new Mock <HelperSer>();                       //class mocking

            _actionFactoryMock.Setup(action => action.EmployeeService.GetAllEmployees()).Returns(lstEmp);

            _repositoryFactoryMock.Setup(repo => repo.GetRepository <Salary>().GetById(It.IsAny <int>())).Returns(salary);

            SalaryService = new SalaryService(_actionFactoryMock.Object, _repositoryFactoryMock.Object, HelperSer.Object);

            //Act
            SalaryService.GetSalaryByEmployeeId(employee.Id);

            //Assert
            _actionFactoryMock.Verify(action => action.EmployeeService.GetAllEmployees(), Times.Once);
            _repositoryFactoryMock.Verify(x => x.GetRepository <Salary>().GetById(employee.SalaryId), Times.Once);
            Assert.AreEqual(salary.GrossSalary, 600);
        }