public void GetTaskByID_ExistingIDPassed_ReturnsRightTask() { //Arrange var testTasks = TasksCRUD.getInstance().getTaskById(1); //Act var okResponse = controller.GetTaskById(1) as OkObjectResult; var result = okResponse.Value as Tasks; //Assert Assert.IsType <OkObjectResult>(okResponse); Assert.Equal("Contact Plumber", result.title); }
public ActionResult GetTaskById(int id) { Tasks task = TasksCRUD.getInstance().getTaskById(id); if (task is null) { return(NotFound(new { status = HttpStatusCode.NotFound, error = string.Format("No task found with ID = {0}", id) })); } else { return(Ok(task)); } }
public ActionResult Delete(int id) { Boolean status = TasksCRUD.getInstance().DeleteTask(id); if (status is true) { return(Ok(new { message = "Successfully deleted" })); } else { return(NotFound(new { status = HttpStatusCode.NotFound, error = string.Format("No task found with ID = {0}", id) })); } }
public ActionResult Update(int id, [FromBody] Tasks request) { Tasks updatedTask = TasksCRUD.getInstance().UpdateTask(request, id); if (updatedTask is null) { return(NotFound(new { status = HttpStatusCode.NotFound, error = string.Format("No task found with ID = {0}", id) })); } else { return(Ok(new { message = "Successfully updated", details = updatedTask })); } }
public ActionResult PostNewTask([FromBody] Tasks request) { //Checking if any required fields are missing if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PostTaskResponse response = new PostTaskResponse(); response = TasksCRUD.getInstance().AddTask(request); if (response is null) { return(BadRequest(new { status = HttpStatusCode.BadRequest, error = (string.Format("Task with id {0} is already found", request.id)), })); } return(CreatedAtAction("GetTaskById", new { id = response.details.id }, response)); }
//Get api/Tasks public List <Tasks> GetAllTasks() { List <Tasks> taskList = TasksCRUD.getInstance().getAllTasks(); return(taskList); }