public void Test_CreateItem_FailCase() { var controller = new TodoController(_context); var result = controller.CreateItem(null); Assert.IsType <BadRequestResult>(result); }
public void Test_CreateItem_SuccessCase() { var controller = new TodoController(_context); var result = controller.CreateItem(new TodoItem { Name = "Test Create" }); var resultType = Assert.IsType <CreatedAtRouteResult>(result); var item = (TodoItem)resultType.Value; Assert.Equal("Test Create", item.Name); }
public void Test_Delete_SuccessCase() { var item = new TodoItem { Name = "Item to test delete" }; var controller = new TodoController(_context); item = (TodoItem)((CreatedAtRouteResult)controller.CreateItem(item)).Value; var deleteResult = controller.Delete(item.Id); Assert.IsType <NoContentResult>(deleteResult); var getResult = controller.GetById(item.Id); Assert.IsType <NotFoundResult>(getResult); }