public void PostMethod_should_return_OkResult() { //Arrange ChecklistBacklog checklist = new ChecklistBacklog() { ChecklistId = 2, Status = false, ChecklistName = "Login" }; var mockService = new Mock <ICheckListService>(); mockService.Setup(m => m.Add_Checklist(checklist)); var controller = new ChecklistController(mockService.Object); // Act IActionResult actionResult = controller.Post(checklist); var contentResult = actionResult as ObjectResult; // Assert Assert.Equal(200, contentResult.StatusCode); Assert.NotNull(contentResult); }
public void Post_Should_Return_BadRequest_When_Exception() { //Arrange ChecklistBacklog checklist = new ChecklistBacklog() { ChecklistId = 123 }; var mockservice = new Mock <ICheckListService>(); mockservice.Setup(m => m.Add_Checklist(checklist)).Throws(new Exception()); ChecklistController floorController = new ChecklistController(mockservice.Object); //Act var result = floorController.Post(checklist); var contentResult = result as StatusCodeResult; //Assert Assert.Equal(500, contentResult.StatusCode); Assert.NotNull(result); }