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); }
public void ShouldRequireValidAmigoId() { var command = new UpdateAmigoCommand { Id = 99, Nome = "João Teste" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <ActionResult> Update(int id, UpdateAmigoCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }