public void Handle_WithNullGetTodoItemQuery_ShouldTrowException()
        {
            // Arrange
            GetTodoItemQuery query = null;

            // Assert
            Assert.Throws <ArgumentNullException>(() => _todoItemsQueryHandler.Handle(query));
        }
Exemple #2
0
        public void Handle_GivenInvalidId_ThrowsException()
        {
            var query = new GetTodoItemQuery
            {
                Id = 99
            };

            var sut = new GetTodoItemQuery.GetTodoItemQueryHandler(_context, _mapper);

            Should.ThrowAsync <NotFoundException>(() =>
                                                  sut.Handle(query, CancellationToken.None));
        }
        public TodoItemDto Handle(GetTodoItemQuery query)
        {
            var todoItem = this._todoRepository.GetTodo(query.Id);

            if (todoItem == null || todoItem.IsDiscarded)
            {
                return(null);
            }

            var todoItemDto = this._mapper.Map(todoItem);

            return(todoItemDto);
        }
Exemple #4
0
        public async Task Handle_GivenValidId_ReturnsCorrectVm()
        {
            var query = new GetTodoItemQuery
            {
                Id = 1
            };

            var sut = new GetTodoItemQuery.GetTodoItemQueryHandler(_context, _mapper);

            var result = await sut.Handle(query, CancellationToken.None);

            result.ShouldBeOfType <TodoItemVm>();
            result.Id.ShouldBe(1);
        }
        public void Handle_WithNonNullQuery_ShouldReturnTodoItem()
        {
            // Arrange
            TodoItem         expected = _fixture.Create <TodoItem>();
            GetTodoItemQuery query    = new GetTodoItemQuery()
            {
                Id = expected.Id
            };

            _mockTodoRepository.Setup(s => s.Get <TodoItem>(It.IsAny <string>())).Returns(expected);

            // Act
            var result = _todoItemsQueryHandler.Handle(query);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expected.Id, result.Id);
            Assert.Equal(expected.Title, result.Title);
            Assert.Equal(expected.Completed, result.Completed);
        }
        public TodoItemDto Handle(GetTodoItemQuery query)
        {
            if (query == null)
            {
                throw new System.ArgumentNullException("GetTodoItemQuery is required");
            }

            var result = _todoRepository.Get <TodoItem>(query.Id);

            if (result == null)
            {
                return(null);
            }

            return(new TodoItemDto()
            {
                Id = result.Id,
                Title = result.Title,
                Completed = result.Completed,
                CreatedAt = result.CreatedAt,
                UpdatedAt = result.UpdatedAt
            });
        }