コード例 #1
0
        public async Task <IActionResult> DeleteTodoItem(long id)
        {
            var todoItem = await _todoItemRepository.GetByIdAsync(id);

            if (todoItem == null)
            {
                return(NotFound());
            }
            await _todoItemRepository.DeleteAsync(todoItem);

            return(NoContent());
        }
コード例 #2
0
    public async Task DeleteAsync_Should_Delete_Entity_From_Database()
    {
        // Arrange
        var todoItem = Builder <TodoItem> .CreateNew().With(c => c.Id = Guid.NewGuid()).Build();

        TodoItemRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoItem, bool> > >()).Returns(todoItem);
        TodoItemRepository.DeleteAsync(Arg.Any <TodoItem>()).Returns(todoItem);

        // Act
        var result = await _sut.DeleteAsync(Guid.NewGuid());

        // Assert
        result.Id.Should().Be(todoItem.Id);
        await TodoItemRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoItem, bool> > >());

        await TodoItemRepository.Received().DeleteAsync(Arg.Any <TodoItem>());
    }