public void Create_AddNewEmployee_AddEmployee() { // Arrange Employee employeeAdded = null; var mockRepository = new Mock<IRepository>(); mockRepository.Setup(i => i.Add(It.IsAny<Employee>())).Callback<Employee>(i => employeeAdded = i); var handler = new EmployeeHandler(mockRepository.Object); var employeeDto = new EmployeeDto { Id = 1 }; // Act handler.Create(employeeDto); // Assert Assert.AreEqual(employeeDto.Id, employeeAdded.Id); }
public void Delete_DeleteEmployee_DeleteOneEmployee() { // Arrange var employees = new List<Employee> { new Employee { Id = 1 } }; var mockRepository = new Mock<IRepository>(); mockRepository.Setup(i => i.Get<Employee>(It.IsAny<int>())).Returns(employees.First(x => x.Id == 1)); mockRepository.Setup(i => i.Delete(It.IsAny<Employee>())).Callback<Employee>(i => employees.Remove(i)); var handler = new EmployeeHandler(mockRepository.Object); var employeeDto = new EmployeeDto { Id = 1 }; // Act handler.Delete(employeeDto.Id); // Assert Assert.IsEmpty(employees); }
public void Update_UpdateEmployee_UpdateEmployee() { // Arrange var employee = new Employee { Name = "Test name" }; var mockRepository = new Mock<IRepository>(); mockRepository.Setup(i => i.Get<Employee>(It.IsAny<int>())).Returns(employee); var handler = new EmployeeHandler(mockRepository.Object); var employeeDto = new EmployeeDto { Name = "Test neme new" }; // Act handler.Update(employeeDto); // Assert Assert.AreEqual(employeeDto.Name, employee.Name); }