public async Task GeEmployee_WithValidId_ReturnsCorrectEmployee() { int employeeId = 1; string employeeNameToValidate = "Bart"; float employeeSalaryToValidate = 144000; List <Employee> employees = new List <Employee>(); EmployeeBuilder employeeBuilder = new EmployeeBuilder(); employees.Add(employeeBuilder.WithId(1) .WithName("Bart") .WithHourlySalary(100) .Build()); employees.Add(employeeBuilder.WithId(2) .WithName("Lisa") .Build()); CalculateByHourlySalary calculateByHourlySalary = new CalculateByHourlySalary(); IEmployeeRepository.Setup(x => x.GetAll()).ReturnsAsync(employees); ICalculateAnnualSalaryFactory.Setup(x => x.GetCalculator(It.IsAny <Employee>())).ReturnsAsync(calculateByHourlySalary); var result = await IGetEmployeeByIdService.Get(employeeId); result.Should().NotBeNull(); result.Name.Should().Be(employeeNameToValidate); result.AnnualSalary.Should().Be(employeeSalaryToValidate); Verify(); }
public async Task <ActionResult> Get(int id) { try { if (id <= 0) { return(Ok()); } var employee = await getEmployeeByIdService.Get(id); var employeeDto = employee.Adapt <EmployeeDto>(); return(Ok(employeeDto)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = ex.Message })); } }