Exemplo n.º 1
0
        public async Task <ActionResult> UpdateLabel([FromRoute] int id, [FromBody] LabelUpdateDTO labelDto)
        {
            var request  = new UpdateLabelCommand(User.Identity?.Name, id, labelDto);
            var response = await _mediator.Send(request);

            return(response.Match <ActionResult>(
                       ok => NoContent(),
                       notFound => NotFound()
                       ));
        }
Exemplo n.º 2
0
        public async Task <OneOf <Ok, NotFound> > Handle(UpdateLabelCommand request, CancellationToken cancellationToken)
        {
            var userLabel = await _labelsRepository
                            .GetAsync(label => label.Id == request.Id && label.UserLogin == request.UserLogin);

            if (userLabel == null)
            {
                return(new NotFound());
            }

            userLabel.MapUpdateDTO(request.UpdateDTO);

            await _labelsRepository.SaveChangesAsync();

            return(new Ok());
        }
Exemplo n.º 3
0
        public async Task Handle_Success()
        {
            // Arrange
            var labelId = Guid.NewGuid();

            var command = new UpdateLabelCommand
            {
                Id          = labelId,
                Name        = "new-name",
                Description = "new-description",
                Color       = new UpdateLabelCommanColor
                {
                    Red   = 10,
                    Green = 11,
                    Blue  = 12,
                    Alpha = 13
                }
            };

            var label = new Label(labelId, "test-name", "test-description", new Color(1, 2, 3, 4));

            _labelRepository
            .Setup(x => x.FindByIdAsync(labelId))
            .ReturnsAsync(label);

            // Act
            await _handler.Handle(command, CancellationToken.None);

            // Assert
            _labelRepository.Verify(x => x.UpdateAsync(label), Times.Once);
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Once);

            Assert.That(label.Name, Is.EqualTo("new-name"));
            Assert.That(label.Description, Is.EqualTo("new-description"));
            Assert.That(label.Color, Is.EqualTo(new Color(10, 11, 12, 13)));
        }