DeleteTodoItem() public méthode

public DeleteTodoItem ( int id ) : HttpResponseMessage,
id int
Résultat HttpResponseMessage,
        public async Task OkDeleteTodoItemTest()
        {
            var targetId = itemlist[0].Id;
            var item     = itemlist[0];

            var result = await controller.DeleteTodoItem(targetId);

            Assert.Equal(2, itemlist.Count);
            Assert.DoesNotContain <TodoItem>(item, itemlist);
        }
        public async Task OkDeleteTodoItemTest()
        {
            var targetId = itemlist[0].Id;
            var item     = itemlist[0];

            var result = await controller.DeleteTodoItem(targetId);

            await PrintData();

            Assert.Equal(2, context.TodoItems.Count());
            Assert.DoesNotContain <TodoItem>(item, await context.TodoItems.ToListAsync());
        }
        public async Task DeleteTodoItem_ReturnsNotFound_WhenTodoItemIsNull()
        {
            long testId         = 5;
            var  mockRepository = new Mock <ITodoItemRepository>();

            mockRepository.Setup(repo => repo.GetItemByIdAsync(testId))
            .ReturnsAsync((TodoItem)null)
            .Verifiable();
            var controller = new TodoController(mockRepository.Object);

            var result = await controller.DeleteTodoItem(testId);

            Assert.IsType <NotFoundResult>(result);
            mockRepository.Verify();
        }
Exemple #4
0
        public async Task DeleteTodoItem_WithValidId_ShouldReturnNoContent()
        {
            // Arrange
            var expectedTodoItemDTO = CreateFakeTodoItemDTO(1);
            var mockService         = new Mock <ITodoItemService>();

            mockService.Setup(service => service.DeleteTodoItemAsync(1))
            .ReturnsAsync(expectedTodoItemDTO);

            var controller = new TodoController(mockService.Object);

            // Act
            var result = await controller.DeleteTodoItem(1);

            // Assert
            var viewResult      = Assert.IsType <ActionResult <TodoItemDTO> >(result);
            var noContentResult = Assert.IsType <NoContentResult>(viewResult.Result);

            Assert.Equal((int)HttpStatusCode.NoContent, noContentResult.StatusCode);
        }
Exemple #5
0
        public async Task DeleteTodoItem_WithInvalidId_ShouldReturnNotFound()
        {
            // Arrange
            var todoItemDTO = CreateFakeTodoItemDTO(1);
            var mockService = new Mock <ITodoItemService>();

            mockService.Setup(service => service.DeleteTodoItemAsync(1))
            .ThrowsAsync(new ArgumentException("Invalid id", "id"));

            var controller = new TodoController(mockService.Object);

            // Act
            var result = await controller.DeleteTodoItem(1);

            // Assert
            var viewResult     = Assert.IsType <ActionResult <TodoItemDTO> >(result);
            var notFoundResult = Assert.IsType <NotFoundResult>(viewResult.Result);

            Assert.Equal((int)HttpStatusCode.NotFound, notFoundResult.StatusCode);
        }
        public async Task DeleteTodoItem_ReturnsNoContent()
        {
            long testId       = 1;
            var  testTodoItem = new TodoItem
            {
                Id         = testId,
                Name       = "test name",
                IsComplete = true
            };
            var mockRepository = new Mock <ITodoItemRepository>();

            mockRepository.Setup(repo => repo.GetItemByIdAsync(testId))
            .ReturnsAsync(testTodoItem)
            .Verifiable();
            var controller = new TodoController(mockRepository.Object);

            var result = await controller.DeleteTodoItem(testId);

            Assert.IsAssignableFrom <IActionResult>(result);
            Assert.IsType <NoContentResult>(result);
            mockRepository.Verify();
        }