Beispiel #1
0
 public async Task PostCreateSubOrdersAsync(Guid id)
 {
     var command = new CreateSubOrders()
     {
         OrderId     = id,
         InitiatorId = Guid.NewGuid()
     };
     await _commandInvoker.Execute(command);
 }
Beispiel #2
0
        public async Task CreateSubOrders_Success()
        {
            //adhere
            var subOrdersInitial   = Product1Order.SubOrders.DeepCopy();
            var assemblyShopOrders = ProductAssemblyShop.Orders.DeepCopy();
            var timberShopOrders   = TimberComponentShop.Orders.DeepCopy();
            var mdfShopOrders      = MdfComponentShop.Orders.DeepCopy();

            //arrange
            var amount  = Product1Order.ItemsOrdered.Of(Product1InteriorDoor).Amount;
            var command = new CreateSubOrders
            {
                OrderId     = Product1Order.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new CreateSubOrdersHandler(EntityRepository, InventoryRepo, OrderService, EventTransmitter);

            //act
            await handler.HandleAsync(command);

            //assert
            var entities = GetRecordedEntities <Order>(EntityRepository, nameof(EntityRepository.AddAsync));

            Assert.That(entities.Count, Is.EqualTo(4));

            var doorsOrder = entities.Single(o => o.ItemsOrdered.Any(i => i.Article == Product1InteriorDoor));

            Assert.That(doorsOrder.ItemsOrdered.Count, Is.EqualTo(1));
            Assert.That(doorsOrder.ItemsProduced.Count, Is.EqualTo(1));
            Assert.That(doorsOrder.ItemsOrdered.Of(Product1InteriorDoor).Amount, Is.EqualTo(amount));
            Assert.That(doorsOrder.ItemsProduced.Of(Product1InteriorDoor).Amount, Is.Zero);
            Assert.That(doorsOrder.Customer, Is.EqualTo(Product1Order.Customer));
            Assert.That(doorsOrder.ParentOrder, Is.EqualTo(Product1Order));
            Assert.That(doorsOrder.ReferenceOrder, Is.EqualTo(Product1Order));
            var deadline = TimeProvider.Subtract(doorsOrder.ParentOrder.ShipmentDeadline,
                                                 doorsOrder.ItemsOrdered.Single().TimeToProduce);

            Assert.That(doorsOrder.ShipmentDeadline, Is.EqualTo(deadline));
            Assert.That(doorsOrder.ShippedAt, Is.Null);
            Assert.That(doorsOrder.Status, Is.EqualTo(OrderStatus.New));
            Assert.That(doorsOrder.Type, Is.EqualTo(OrderType.Internal));
            Assert.That(doorsOrder.Shop, Is.EqualTo(ProductAssemblyShop));
            Assert.That(doorsOrder.WorkStartedAt, Is.Null);
            Assert.That(doorsOrder.SubOrders, Is.Not.Empty);

            var verticalOrder = entities.Single(o => o.ItemsOrdered.Any(i => i.Article == Component1Vertical));

            Assert.That(verticalOrder.ItemsOrdered.Count, Is.EqualTo(1));
            Assert.That(verticalOrder.ItemsProduced.Count, Is.EqualTo(1));
            var verticalAmount =
                Product1InteriorDoor.PrimaryBillOfMaterial.Input.Of(Component1Vertical).Amount *amount
                - await InventoryRepo.FindSpareInventoryAsync(Component1Vertical);

            Assert.That(verticalOrder.ItemsOrdered.Of(Component1Vertical).Amount, Is.EqualTo(verticalAmount));
            Assert.That(verticalOrder.ItemsProduced.Of(Component1Vertical).Amount, Is.Zero);
            Assert.That(verticalOrder.Customer, Is.EqualTo(Product1Order.Customer));
            Assert.That(verticalOrder.ParentOrder, Is.EqualTo(doorsOrder));
            Assert.That(verticalOrder.ReferenceOrder, Is.EqualTo(Product1Order));
            deadline = TimeProvider.Subtract(verticalOrder.ParentOrder.ShipmentDeadline,
                                             verticalOrder.ItemsOrdered.Single().TimeToProduce);
            Assert.That(verticalOrder.ShipmentDeadline, Is.EqualTo(deadline));
            Assert.That(verticalOrder.ShippedAt, Is.Null);
            Assert.That(verticalOrder.Status, Is.EqualTo(OrderStatus.New));
            Assert.That(verticalOrder.Type, Is.EqualTo(OrderType.Internal));
            Assert.That(verticalOrder.Shop, Is.EqualTo(TimberComponentShop));
            Assert.That(verticalOrder.WorkStartedAt, Is.Null);
            Assert.That(verticalOrder.SubOrders, Is.Empty);

            var horizontalOrder = entities.Single(o => o.ItemsOrdered.Any(i => i.Article == Component2Horizontal));

            Assert.That(horizontalOrder.ItemsOrdered.Count, Is.EqualTo(1));
            Assert.That(horizontalOrder.ItemsProduced.Count, Is.EqualTo(1));
            var horizontalAmount = Product1InteriorDoor.PrimaryBillOfMaterial.Input.Of(Component2Horizontal).Amount *
                                   amount - await InventoryRepo.FindSpareInventoryAsync(Component1Vertical);

            Assert.That(horizontalOrder.ItemsOrdered.Of(Component2Horizontal).Amount, Is.EqualTo(horizontalAmount));
            Assert.That(horizontalOrder.ItemsProduced.Of(Component2Horizontal).Amount, Is.Zero);
            Assert.That(horizontalOrder.Customer, Is.EqualTo(Product1Order.Customer));
            Assert.That(horizontalOrder.ParentOrder, Is.EqualTo(doorsOrder));
            Assert.That(horizontalOrder.ReferenceOrder, Is.EqualTo(Product1Order));
            deadline = TimeProvider.Subtract(horizontalOrder.ParentOrder.ShipmentDeadline,
                                             horizontalOrder.ItemsOrdered.Single().TimeToProduce);
            Assert.That(horizontalOrder.ShipmentDeadline, Is.EqualTo(deadline));
            Assert.That(horizontalOrder.ShippedAt, Is.Null);
            Assert.That(horizontalOrder.Status, Is.EqualTo(OrderStatus.New));
            Assert.That(horizontalOrder.Type, Is.EqualTo(OrderType.Internal));
            Assert.That(horizontalOrder.Shop, Is.EqualTo(TimberComponentShop));
            Assert.That(horizontalOrder.WorkStartedAt, Is.Null);
            Assert.That(horizontalOrder.SubOrders, Is.Empty);

            var mdfOrder = entities.Single(o => o.ItemsOrdered.Any(i => i.Article == Component3MdfFiller));

            Assert.That(mdfOrder.ItemsOrdered.Count, Is.EqualTo(1));
            Assert.That(mdfOrder.ItemsProduced.Count, Is.EqualTo(1));
            var mdfAmount = Product1InteriorDoor.PrimaryBillOfMaterial.Input.Of(Component3MdfFiller).Amount *amount
                            - await InventoryRepo.FindSpareInventoryAsync(Component1Vertical);

            Assert.That(mdfOrder.ItemsOrdered.Of(Component3MdfFiller).Amount, Is.EqualTo(mdfAmount));
            Assert.That(mdfOrder.ItemsProduced.Of(Component3MdfFiller).Amount, Is.Zero);
            Assert.That(mdfOrder.Customer, Is.EqualTo(Product1Order.Customer));
            Assert.That(mdfOrder.ReferenceOrder, Is.EqualTo(Product1Order));
            Assert.That(mdfOrder.ParentOrder, Is.EqualTo(doorsOrder));
            deadline = TimeProvider.Subtract(mdfOrder.ParentOrder.ShipmentDeadline,
                                             mdfOrder.ItemsOrdered.Single().TimeToProduce);
            Assert.That(mdfOrder.ShipmentDeadline, Is.EqualTo(deadline));
            Assert.That(mdfOrder.ShippedAt, Is.Null);
            Assert.That(mdfOrder.Status, Is.EqualTo(OrderStatus.New));
            Assert.That(mdfOrder.Type, Is.EqualTo(OrderType.Internal));
            Assert.That(mdfOrder.Shop, Is.EqualTo(MdfComponentShop));
            Assert.That(mdfOrder.WorkStartedAt, Is.Null);
            Assert.That(mdfOrder.SubOrders, Is.Empty);

            Assert.That(GetRecordedEvents <DomainEvent <Order> >().Count, Is.EqualTo(4));

            //annul
            Product1Order.SubOrders    = subOrdersInitial;
            ProductAssemblyShop.Orders = assemblyShopOrders;
            TimberComponentShop.Orders = timberShopOrders;
            MdfComponentShop.Orders    = mdfShopOrders;
        }