public void GetAllFilterByCurrent_Test() { // Arrange var mockService = new Mock <IEmployeeJobService>(); var controller = new EmployeeJobController(mockService.Object); // Act IQueryable <EmployeeJobModel> response = controller.GetAll(); Assert.AreEqual(response.Where(x => x.IsCurrent).Count(), response.Count()); }
public void GetById_NotFound_Test() { // Arrange var mockService = new Mock <IEmployeeJobService>(); var controller = new EmployeeJobController(mockService.Object); // Act IHttpActionResult actionResult = controller.GetById(-1); // Assert Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void GetAll_Test() { // Arrange var mockService = new Mock <IEmployeeJobService>(); var controller = new EmployeeJobController(mockService.Object); // Act IQueryable <EmployeeJobModel> response = controller.GetAll(); // Assert Assert.IsNotNull(response); }
public void Delete_Test() { // Arrange var mockService = new Mock <IEmployeeJobService>(); var controller = new EmployeeJobController(mockService.Object); int id = 10; int userId = 1; // Act IHttpActionResult actionResult = controller.Delete(id, userId); // Assert Assert.IsInstanceOfType(actionResult, typeof(OkResult)); }
public void Post_Test() { // Arrange var mockService = new Mock <IEmployeeJobService>(); var controller = new EmployeeJobController(mockService.Object); EmployeeJobModel model = GetDemoItem(true); int userId = 1; // Act IHttpActionResult actionResult = controller.Post(model, userId); var createdResult = actionResult as OkNegotiatedContentResult <int>; // Assert Assert.IsNotNull(createdResult); //Assert.AreEqual("DefaultApi", createdResult.RouteName); Assert.IsTrue(createdResult.Content >= 0); }
public void Put_Test() { // Arrange var mockService = new Mock <IEmployeeJobService>(); var controller = new EmployeeJobController(mockService.Object); EmployeeJobModel model = GetDemoItem(false); int userId = 1; // Act IHttpActionResult actionResult = controller.Put(model, userId); var contentResult = actionResult as NegotiatedContentResult <EmployeeJobModel>; // Assert Assert.IsNotNull(contentResult); Assert.AreEqual(HttpStatusCode.Accepted, contentResult.StatusCode); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(model.Id, contentResult.Content.Id); }
public void GetById_Test() { int id = 1; // Arrange var mockService = new Mock <IEmployeeJobService>(); mockService.Setup(x => x.GetById(id)) .Returns(new EmployeeJobModel { Id = id }); var controller = new EmployeeJobController(mockService.Object); // Act IHttpActionResult actionResult = controller.GetById(id); var contentResult = actionResult as OkNegotiatedContentResult <EmployeeJobModel>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(id, contentResult.Content.Id); }