public Order CreateSubOrder(InventoryItem item, Order parent) { if (item.Article.ProductionShopCategory == null) { throw new DomainException(ArticleNotProducible(item.Article)); } var subOrder = new Order(Guid.NewGuid(), $"{item.Article.Name} suborder of {parent}") { ReferenceOrder = parent?.ReferenceOrder ?? parent, ParentOrder = parent, ItemsOrdered = item.Collect().ToHashSet(), ItemsProduced = InventoryItem.Empty(item.Article).Collect().ToHashSet(), Status = OrderStatus.New, Type = OrderType.Internal, Customer = parent.Customer, CreatedAt = DateTimeOffset.Now, ShipmentDeadline = _timeProvider.Subtract(parent.ShipmentDeadline, item.TimeToProduce) }; parent.SubOrders.Add(subOrder); parent.ReferenceOrder?.SubOrders.Add(subOrder); var shop = item.Article.ProductionShopCategory?.Shops .OrderBy(s => s.Orders.Min(o => o?.EstimatedCompletionAt)).FirstOrDefault() ?? item.Article?.ProductionShopCategory?.DefaultShop; if (shop != null) { AssignOrder(subOrder, shop); } return(subOrder); }
public async Task CalculateTimeOfCompletion_Success() { //arrange var now = DateTimeOffset.Now; var item = new InventoryItem(Product1InteriorDoor, 20); var spare = await InventoryRepo.FindSpareInventoryAsync(Product1InteriorDoor); var expected = TimeProvider.Add(now, new InventoryItem(item.Article, item.Amount - spare).TimeToProduce); //act var eta = await InventoryService.CalculateTimeOfCompletion(item.Collect()); //assert Assert.That(eta, Is.AtLeast(expected)); }