public async Task DeleteEmployee_ShouldReturnNotFound() { var employeeLogic = new Mock <IEmployeeLogic>(); var controller = new EmployeesController(employeeLogic.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; var response = await controller.DeleteEmployeeByIdAsync(It.IsAny <string>()); Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound); }
public async Task DeleteEmployee_ShouldReturnException() { var employeeLogic = new Mock <IEmployeeLogic>(); employeeLogic.Setup(x => x.DeleteEmployeeByIdAsync(It.IsAny <string>())) .ThrowsAsync(new Exception()); var controller = new EmployeesController(employeeLogic.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; var response = await controller.DeleteEmployeeByIdAsync(It.IsAny <string>()); Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest); Assert.IsInstanceOfType(response, typeof(HttpResponseMessage)); }
public async Task DeleteEmployee_ShouldDeleteEMployeeById() { var employeeBOL = new EmployeeBOL { EmployeeId = "21-12344", FirstName = "xyz", LastName = "abc", Department = "IT", Salary = 20000 }; var employeeLogic = new Mock <IEmployeeLogic>(); employeeLogic.Setup(x => x.DeleteEmployeeByIdAsync("21-12344")) .Returns(Task.FromResult(employeeBOL)); var controller = new EmployeesController(employeeLogic.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; var response = await controller.DeleteEmployeeByIdAsync("21-12344"); Assert.IsNotNull(response); Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); Assert.IsTrue(response.TryGetContentValue(out employeeBOL)); Assert.AreEqual("21-12344", employeeBOL.EmployeeId); }