コード例 #1
0
        public void GivenAnId_WhenGetGetEmployees_ThenGetsEmployeeData()
        {
            //Given
            int      id       = 1;
            Employee employee = new Employee
            {
                ContractTypeName = ContractType.MonthlySalaryEmployee.ToString(),
                MonthlySalary    = 3000,
                Id              = 1,
                Name            = "Test Name",
                RoleDescription = "Test Rol",
                RoleId          = 1,
                RoleName        = "Tester"
            };

            DTO.MonthlySalaryEmployee employeeDTO = new DTO.MonthlySalaryEmployee
            {
                ContractTypeName = ContractType.MonthlySalaryEmployee,
                MonthlySalary    = 3000,
                Id              = 1,
                Name            = "Test Name",
                RoleDescription = "Test Rol",
                RoleId          = 1,
                RoleName        = "Tester"
            };

            IEnumerable <Employee> employees = new List <Employee> {
                employee
            };
            List <DTO.Employee> employeeDTOs = new List <DTO.Employee> {
                employeeDTO
            };

            _masGlobalEmployeeApiServiceMock.Setup(x => x.GetEmployees()).Returns(Task.FromResult(employees));
            _employeeMapperFactoryMock.Setup(x => x.GetEmployee(It.IsAny <Employee>())).Returns(employeeDTO);

            //When
            var result = _masGlobalEmployeeService.GetEmployees();

            //Then
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Result.Count());
            Assert.AreSame(result.Result.ToArray()[0], employeeDTO);
            _masGlobalEmployeeApiServiceMock.Setup(x => x.GetEmployeeById(id)).Verifiable();
            _employeeMapperFactoryMock.Setup(x => x.GetEmployee(employee)).Verifiable();
        }
コード例 #2
0
        public async Task <IActionResult> GetEmployees()
        {
            var employees = await _masGlobalEmployeeService.GetEmployees();

            return(new ObjectResult(employees));
        }