Ejemplo n.º 1
0
        public async Task DeleteAsync_Should_Throw_Exception_If_List_Does_Not_Exist_Anymore()
        {
            // Arrange
            _todoItemRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoItem, bool> > >()).ReturnsNull();

            // Act
            Func <Task> callDeleteAsync = async() => await _sut.DeleteAsync(Guid.NewGuid());

            // Assert
            callDeleteAsync.Should().Throw <NotFoundException>().WithMessage("Todo item does not exist anymore");
            await _todoItemRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoItem, bool> > >());
        }
Ejemplo n.º 2
0
        public async Task TestDeleteAsync_CheckException()
        {
            // Arrange
            var mock       = new Mock <ITodoItemAsyncRepository>();
            int inputValue = 12345;

            mock.Setup(serv => serv.DeleteAsync(inputValue)).Returns(async() => { throw new Exception(); });
            var todoItemService = new TodoItemService(mock.Object);

            // Act & Assert
            await Assert.ThrowsAsync <Exception>(() => todoItemService.DeleteAsync(inputValue));
        }
    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>());
    }
Ejemplo n.º 4
0
        public async Task TestDeleteAsync_CheckTodoItem()
        {
            // Arrange
            var      mock       = new Mock <ITodoItemAsyncRepository>();
            int      inputValue = 1;
            TodoItem todoItem   = new TodoItem {
                Completed = false, Id = 1, Text = "Learn"
            };

            mock.Setup(serv => serv.DeleteAsync(inputValue)).Returns(async() => { return(todoItem); });
            var todoItemService = new TodoItemService(mock.Object);

            // Act
            var result = await todoItemService.DeleteAsync(inputValue);

            // Assert
            Assert.IsType <TodoItemDTO>(result);
        }