public void DeleteLabel_ShouldCallDeleteLabel() { // Arrange var input = new DeleteLabelDto(); // Act controller.DeleteLabel(input); // Assert todoItemLogic.Verify(u => u.DeleteLabel(1, input)); }
public void DeleteLabel_ShouldCallDeleteLabel() { // Arrange var input = new DeleteLabelDto(); // Act logic.DeleteLabel(1, input); // Assert todoItemRepository.Verify(t => t.DeleteLabel(1, input)); }
public void DeleteLabel_ShouldReturnBadRequestWhenDeleteLabelReturnsFalse() { // Arrange var input = new DeleteLabelDto(); // Act var result = controller.DeleteLabel(input); // Assert Assert.IsType <BadRequestObjectResult>(result); var response = (result as BadRequestObjectResult).Value as ErrorResponse; Assert.Equal("Item or label not found in the database.", response.Message); }
public void DeleteLabel_ShouldReturnFalseIfItemIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(DeleteLabel_ShouldReturnFalseIfItemIsNotFound)); var repository = new TodoItemRepository(dbContext); var input = new DeleteLabelDto { ParentId = 30 }; // Act var result = repository.DeleteLabel(3, input); // Assert Assert.False(result); }
public void DeleteLabel_ShouldDeleteLabel() { // Arrange var dbContext = SetupDatabase(nameof(DeleteLabel_ShouldDeleteLabel)); var repository = new TodoItemRepository(dbContext); var input = new DeleteLabelDto { ParentId = 1, Label = "Today" }; // Act var result = repository.DeleteLabel(1, input); // Assert Assert.True(result); var item = dbContext.Labels.FirstOrDefault(t => t.Id == 1); Assert.Null(item); }
public void DeleteLabel_ShouldReturnTrueOnSuccessfulDeletion() { // Arrange var input = new DeleteLabelDto { ParentId = 3, Label = "testlabel" }; todoItemLogic.Setup(u => u.DeleteLabel(1, input)).Returns(true); // Act var result = controller.DeleteLabel(input); // Assert Assert.IsType <OkObjectResult>(result); var response = (result as OkObjectResult).Value as Response <string>; Assert.True(response.Status); Assert.Equal("Label testlabel deleted for item with id 3.", response.Model); }
/// <summary> /// Deletes a label for todo item. /// </summary> /// <param name="userId">User id</param> /// <param name="deleteDto">Delete Dto</param> /// <returns>True if delete was successful</returns> public bool DeleteLabel(int userId, DeleteLabelDto deleteDto) { var existingItem = dbContext.TodoItems .Include(l => l.Labels) .FirstOrDefault(u => u.Id == userId && u.Id == deleteDto.ParentId); if (existingItem == null) { return(false); } var existingLabel = existingItem.Labels?.FirstOrDefault(l => l.Name == deleteDto.Label); if (existingLabel == null) { return(false); } dbContext.Remove(existingLabel); dbContext.SaveChanges(); return(true); }
public IActionResult DeleteLabel(DeleteLabelDto deleteDto) { int userId = int.Parse(httpContextAccessor.HttpContext.User.FindFirst(Constants.UserIdClaim)?.Value); var deleteResult = todoItemLogic.DeleteLabel(userId, deleteDto); if (deleteResult) { return(Ok(new Response <string> { Status = true, Model = $"Label {deleteDto.Label} deleted for item with id {deleteDto.ParentId}." })); } else { return(BadRequest(new ErrorResponse { Status = false, Message = "Item or label not found in the database." })); } }
public bool DeleteItemLabel(DeleteLabelDto deleteDto) { var userId = CheckAuthentication(); return(todoItemRepository.DeleteLabel(userId, deleteDto)); }
/// <summary> /// Deletes a label for todo item. /// </summary> /// <param name="userId">User id</param> /// <param name="deleteDto">Delete Dto</param> /// <returns>True if delete was successful</returns> public bool DeleteLabel(int userId, DeleteLabelDto deleteDto) { return(todoItemRepository.DeleteLabel(userId, deleteDto)); }