public async Task VerifyDetailsActionReturns404IfIdIsNull() { var employeeRepository = new Mock<IEmployeeRepository>(); var employeeController = new EmployeeController(employeeRepository.Object); var actionResult = await employeeController.Details(null); var result = actionResult as HttpStatusCodeResult; Assert.NotNull(result); Assert.Equal(404, result.StatusCode); }
public async Task VerifyDetailsActionReturns404IfIdNotExists() { var employeeRepository = new Mock<IEmployeeRepository>(); employeeRepository.Setup(rep => rep.Get(It.IsAny<Guid?>())) .Returns(Task.FromResult(default(Employee))); var employeeController = new EmployeeController(employeeRepository.Object); var actionResult = await employeeController.Details(Guid.Empty); var result = actionResult as HttpStatusCodeResult; Assert.NotNull(result); Assert.Equal(404, result.StatusCode); }
public async Task VerifyDetailsActionReturnsEmployee() { var employeeId = Guid.NewGuid(); var employee = new Employee(); employee.Id = employeeId; employee.Name = "Employee"; employee.Designation = "Lead"; employee.JoiningDate = DateTime.UtcNow; employee.Remarks = "Remarks for employee"; var employeeRepository = new Mock<IEmployeeRepository>(); employeeRepository.Setup(rep => rep.Get(It.IsAny<Guid?>())) .Returns(Task.FromResult(employee)); var employeeController = new EmployeeController(employeeRepository.Object); var actionResult = await employeeController.Details(employeeId); var result = actionResult as ViewResult; Assert.NotNull(result); var model = result.ViewData.Model as Employee; Assert.Equal(employee.Name, model.Name); Assert.Equal(employee.Designation, model.Designation); Assert.Equal(employee.JoiningDate, model.JoiningDate); Assert.Equal(employee.Remarks, model.Remarks); }