예제 #1
0
        public async Task ShouldUpdateAmigo()
        {
            var userId = await RunAsDefaultUserAsync();

            var amigoId = await SendAsync(new CreateAmigoCommand
            {
                Nome = "João Novo Nome"
            });

            var command = new UpdateAmigoCommand
            {
                Id   = amigoId,
                Nome = "João Nome Atualizado"
            };

            await SendAsync(command);

            var amigo = await FindAsync <Amigo>(amigoId);

            amigo.Nome.Should().Be(command.Nome);
            amigo.LastModifiedBy.Should().NotBeNull();
            amigo.LastModifiedBy.Should().Be(userId);
            amigo.LastModified.Should().NotBeNull();
            amigo.LastModified.Should().BeCloseTo(DateTime.Now, 1000);
        }
        public Task Handle(UpdateAmigoCommand message, CancellationToken cancellation)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Unit.Task);
            }

            //var Amigo = new Amigo(message.Id, message.Nome, message.Endereco);
            var amigo = _amigoRepository.GetById(message.Id);

            //if (existingAmigo != null && existingAmigo.Id != Amigo.Id)
            //{
            //    if (!existingAmigo.Equals(Amigo))
            //    {
            //        Bus.RaiseEvent(new DomainNotification(message.MessageType, "Erro ao realizar o update da entidade"));
            //        return Unit.Task;
            //    }
            //}

            amigo.Endereco = message.Endereco;
            amigo.Nome     = message.Nome;


            _amigoRepository.Update(amigo);

            if (Commit())
            {
                Bus.RaiseEvent(new AmigoUpdatedEvent(amigo.Id, amigo.Nome, amigo.Endereco));
            }

            return(Unit.Task);
        }
예제 #3
0
        public void ShouldRequireValidAmigoId()
        {
            var command = new UpdateAmigoCommand
            {
                Id   = 99,
                Nome = "João Teste"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
예제 #4
0
        public async Task <ActionResult> Update(int id, UpdateAmigoCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }