Exemplo n.º 1
0
        public void Debe_actualizar_pedidoEngine_cuando_cancela_pedidoCommand_es_enviado()
        {
            var pedidoEngine = new PedidoYClientesRepository();
            var bus          = new FakeBus();

            CompositionRootHelper.BuildTheWriteModelHexagon(pedidoEngine, pedidoEngine, bus, bus);

            var pizzeriaId    = 1;
            var cantidad      = 1;
            var clienteId     = "*****@*****.**";
            var pedidoCommand = new PedidoCommand(
                clienteId: clienteId,
                pizzaNombre: "Malcriada",
                pizzeriaId: pizzeriaId,
                cantidad: cantidad,
                fechaDeEntrega: Constants.MyFavoriteSaturdayIn2019);

            bus.Send(pedidoCommand);

            Check.That(pedidoEngine.GetPedidoDe(clienteId)).HasSize(1);
            var deliveryGuid = pedidoEngine.GetPedidoDe(clienteId).First().PedidoId;

            var cancelDeliveryCommand = new CancelarPedidoCommand(deliveryGuid, clienteId);

            bus.Send(cancelDeliveryCommand);

            // Pedido is still there, but canceled
            Check.That(pedidoEngine.GetPedidoDe(clienteId)).HasSize(1);
            Check.That(pedidoEngine.GetPedidoDe(clienteId).First().EsCancelado).IsTrue();
        }
Exemplo n.º 2
0
 public async Task <IActionResult> CalcularPedido([FromBody] PedidoCommand pedidoCommand)
 {
     try
     {
         var Result = _calculoHandler.Calcular(pedidoCommand);
         return(await Response(Result));
     }
     catch (Exception ex)
     {
         return(await base.Errors(ex));
     }
 }
Exemplo n.º 3
0
        public void Debe_actualizar_buscar_pizza_cuando_cancelaPedidoCommand_es_enviado()
        {
            // Initialize Read-model side
            var bus = new FakeBus(synchronousPublication: true);
            var pizzeriasAdapter = new PizzeriasYPizzasAdapter(Constants.RelativePathForPizzaIntegrationFiles, bus);
            var pedidoAdapter    = new ReservaAdapter(bus);

            pizzeriasAdapter.LoadPizzaFile("Malcriada-availabilities.json");

            // Initialize Write-model side
            var bookingRepository = new PedidoYClientesRepository();

            CompositionRootHelper.BuildTheWriteModelHexagon(bookingRepository, bookingRepository, bus, bus);

            var readFacade = CompositionRootHelper.BuildTheReadModelHexagon(pizzeriasAdapter, pizzeriasAdapter, pedidoAdapter, bus);

            // Search Pizzas availabilities
            var fechaEntrega = Constants.MyFavoriteSaturdayIn2019;

            var searchQuery    = new BuscarPedidoOpciones(fechaEntrega, direccion: "Cercado", nombrePizza: "peperoni", cantidad: 2);
            var pedidoOpciones = readFacade.BuscarPedidoOpciones(searchQuery);

            // We should get 1 pedido option with 13 available pizzas in it.
            Check.That(pedidoOpciones).HasSize(1);

            var pedidoOpcion        = pedidoOpciones.First();
            var initialPizzaNumbers = 13;

            Check.That(pedidoOpcion.DisponiblesPizzasConPrecios).HasSize(initialPizzaNumbers);

            // Now, let's request that pizza!
            var firstPizzaOfThisPedidoOption = pedidoOpcion.DisponiblesPizzasConPrecios.First();
            var clientId      = "*****@*****.**";
            var pedidoCommand = new PedidoCommand(clienteId: clientId, pizzeriaId: pedidoOpcion.Pizzeria.Identificador, pizzaNombre: "MalcriadaC", cantidad: firstPizzaOfThisPedidoOption.Cantidad, fechaDeEntrega: fechaEntrega);

            // We send the PedirPizza command
            bus.Send(pedidoCommand);

            // We check that both the PedidoRepository (Write model) and the available pizzas (Read model) have been updated.
            Check.That(bookingRepository.GetPedidoDe(clientId).Count()).IsEqualTo(1);
            var pedidoId = bookingRepository.GetPedidoDe(clientId).First().PedidoId;

            // Fetch pizzas availabilities now. One pizza should have disappeared from the search result
            pedidoOpciones = readFacade.BuscarPedidoOpciones(searchQuery);
            Check.That(pedidoOpciones).HasSize(1);
            Check.That(pedidoOpcion.DisponiblesPizzasConPrecios).As("available matching pizzas").HasSize(initialPizzaNumbers - 1);
        }
Exemplo n.º 4
0
        public void DebeActualizar_readmodel_usuario_reservacion_cuando_CancelarPedidoCommand_is_enviadot()
        {
            var pedidoEngine = new PedidoYClientesRepository();
            var bus          = new FakeBus(synchronousPublication: true);

            CompositionRootHelper.BuildTheWriteModelHexagon(pedidoEngine, pedidoEngine, bus, bus);

            var pizzeriasYPizzasAdapter = new PizzeriasYPizzasAdapter(Constants.RelativePathForPizzaIntegrationFiles, bus);

            pizzeriasYPizzasAdapter.LoadAllPizzaFiles();
            var reservationAdapter = new ReservaAdapter(bus);

            CompositionRootHelper.BuildTheReadModelHexagon(pizzeriasYPizzasAdapter, pizzeriasYPizzasAdapter, reservationAdapter, bus);

            var clienteId = "*****@*****.**";

            Check.That(reservationAdapter.GetReservacionesDe(clienteId)).IsEmpty();

            var pizzeriaId    = 2;
            var cantidad      = 2;
            var pedidoCommand = new PedidoCommand(clienteId: clienteId, pizzeriaId: pizzeriaId, pizzaNombre: "Peperoni", cantidad: 2, fechaDeEntrega: Constants.MyFavoriteSaturdayIn2019);

            bus.Send(pedidoCommand);

            var pedidoGuid = pedidoEngine.GetPedidoDe(clienteId).First().PedidoId;

            Check.That(reservationAdapter.GetReservacionesDe(clienteId)).HasSize(1);

            var reservation = reservationAdapter.GetReservacionesDe(clienteId).First();

            Check.That(reservation.Cantidad).IsEqualTo(cantidad);
            Check.That(reservation.PizzeriaId).IsEqualTo(pizzeriaId);

            var cancelCommand = new CancelarPedidoCommand(pedidoGuid, clienteId);

            bus.Send(cancelCommand);

            Check.That(reservationAdapter.GetReservacionesDe(pedidoGuid, clienteId)).HasSize(0);
        }
Exemplo n.º 5
0
        public static PedidoDto Calcular(PedidoCommand pedidoCommand, IIngredienteRepository ingredientesRepository, ILancheRepository lancheRepository)
        {
            var pedido = new PedidoDto();

            try
            {
                var AssemblyCurrent   = Assembly.GetExecutingAssembly();
                var promocoes         = AssemblyCurrent.GetTypes().Where(x => x.IsSubclassOf(typeof(CalculoBase)));
                var listaIngredientes = ingredientesRepository.GetAll();

                pedido.Lanche = lancheRepository.GetById(pedidoCommand.IdLanche).Nome;
                pedido.Valor  = pedidoCommand.ItensPedido.Sum(x => (listaIngredientes.FirstOrDefault(y => y.Id == x.IdIngrediente).Valor *x.Quantidade));
                var valorDesconto = 0.0m;

                foreach (var item in promocoes)
                {
                    var parametros = new List <object>()
                    {
                        pedidoCommand, listaIngredientes
                    };
                    var instancia = (CalculoBase)Activator.CreateInstance(item, parametros.ToArray());
                    valorDesconto += instancia.Calcular(pedido.Valor);
                }

                pedido.Desconto   = valorDesconto;
                pedido.ValorFinal = (pedido.Valor - valorDesconto);
                return(pedido);
            }
            catch (Exception)
            {
                return(new PedidoDto()
                {
                    ValorFinal = -1
                });
            }
        }
Exemplo n.º 6
0
 public CalculoBase(PedidoCommand pedido, List <IngredienteEntity> ingredientes)
 {
     this.Pedido       = pedido;
     this.Ingredientes = ingredientes;
 }
Exemplo n.º 7
0
 public MuitaCarneQueijo(PedidoCommand pedido, List <IngredienteEntity> ingredientes) : base(pedido, ingredientes)
 {
 }
Exemplo n.º 8
0
 public IDtoResult Calcular(PedidoCommand pedidoCommand)
 {
     return(CalculoCore.Calcular(pedidoCommand, this._ingredienteRepository, this._lancheRepository));
 }
Exemplo n.º 9
0
 public Light(PedidoCommand pedido, List <IngredienteEntity> ingredientes) : base(pedido, ingredientes)
 {
 }