public ViewModelToDomainMappingProfile() { CreateMap <UsuarioRequestViewModel, RegistrarUsuarioCommand>() .ConstructUsing(vm => new RegistrarUsuarioCommand(vm.Nome, vm.Email, vm.Senha)); CreateMap <LoginViewModel, ApplicationUser>() .ForMember(usu => usu.Email, opt => opt.MapFrom(vm => vm.Email)) .ForMember(usu => usu.PasswordHash, opt => opt.MapFrom(vm => vm.Senha)); CreateMap <EnderecoViewModel, RegistrarEnderecoCommand>() .ConstructUsing(vm => new RegistrarEnderecoCommand(vm.Email, vm.CEP, vm.Rua, vm.Numero, vm.Complemento, vm.Bairro, vm.Cidade, vm.Estado)); CreateMap <ProdutoViewModel, CadastrarProdutoCommand>() .ConstructUsing(vm => new CadastrarProdutoCommand(vm.Nome, vm.Pontuacao, vm.Categoria)); CreateMap <ExtratoViewModel, CadastrarExtratoCommand>() .ConstructUsing(vm => new CadastrarExtratoCommand(vm.Pontos, vm.Email, vm.Estabelecimento)); CreateMap <PedidoRequestViewModel, RealizarPedidoCommand>() .ConstructUsing((s, ctx) => { var command = new RealizarPedidoCommand(s.Email); s.Itens?.ForEach(tr => command.AdicionarItem(new PedidoItem(tr.ProdutoId, tr.Quantidade))); return(command); }); }
public Task Handle(RealizarPedidoCommand message) { //_bus.Send(new RealizarPedidoCommand{AggregateRoot = message.AggregateRoot}).Wait(); // Realiza processamento de negocio! Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Pedido Realizado!"); Console.ForegroundColor = ConsoleColor.Black; _bus.Publish(new PedidoRealizadoEvent { AggregateRoot = message.AggregateRoot }).Wait(); Data.PedidoRealizado = true; ProcessoSaga(); return(Task.CompletedTask); }
public void RealizarPedidoCommand_Sucesso() { var email = "*****@*****.**"; var command = new RealizarPedidoCommand(email); var endereco = new Endereco.Endereco(email, "14801-320", "Rua Goiás", 23, "", "Centro", "Araraquara", "SP"); _enderecoQueryRepositoryMock.Setup(x => x.ObterPorEmail(email)).Returns(endereco); var pedido = new Pedido.Pedido("*****@*****.**", Enums.StatusEntrega.AGUARDANDOENVIO, DateTime.Now, new List <PedidoItem>(), endereco); _pedidoCommandRepositoryMock.Setup(x => x.Adicionar(pedido)); var evento = new PedidoRealizadoEvent(pedido); _mediatorHandlerMock.Setup(x => x.PublicarEvento(evento)); var result = pedidoCommandHandler.Handle(command, new System.Threading.CancellationToken()); _pedidoQueryRepositoryMock.Verify(); _enderecoQueryRepositoryMock.Verify(); }
public async Task <IActionResult> AdicionarPedido(RealizarPedidoCommand pedido) { pedido.ClienteId = _user.ObterUserId(); return(CustomResponse(await _mediator.EnviarComando(pedido))); }