Exemplo n.º 1
0
        public void CanAllocateFromOneWarehouse()
        {
            List <PickList> pickLists = _service.AllocateInventory(
                Guid.NewGuid(),
                new List <OrderLine>
            {
                new OrderLine
                {
                    Customer = _clinic,
                    Product  = _procrit,
                    Quantity = 3
                }
            });

            Assert.AreEqual(1, pickLists.Count);
            Assert.AreEqual(11190, pickLists[0].Product.Id);
            Assert.AreEqual(3, pickLists[0].Quantity);
        }
        public void HandleMessage(PlaceOrder message)
        {
            if (_pickListService.GetPickLists(message.OrderId)
                .Any())
            {
                return;
            }

            Console.WriteLine("Place order.");
            Customer customer = _customerService
                                .GetCustomer(
                message.CustomerName,
                message.CustomerAddress);

            List <OrderLine> orderLines = message.Lines
                                          .Select(line => new OrderLine
            {
                Customer = customer,
                Product  = _productService
                           .GetProduct(
                    line.ProductNumber),
                Quantity = line.Quantity
            })
                                          .ToList();

            List <PickList> pickLists =
                _inventoryAllocationService
                .AllocateInventory(
                    message.OrderId,
                    orderLines);

            _pickListService.SavePickLists(pickLists);

            var orderShippedEvent = new OrderShipped
            {
                OrderId         = message.OrderId,
                OrderDate       = message.OrderDate,
                CustomerName    = message.CustomerName,
                CustomerAddress = message.CustomerAddress,
                Shipments       = pickLists
                                  .Select(p => new Messages.Shipment
                {
                    ProductNumber  = p.Product.ProductNumber,
                    Quantity       = p.Quantity,
                    TrackingNumber = "123-45"
                })
                                  .ToList()
            };

            _subscriptionRegistry.Publish(orderShippedEvent);
        }