Пример #1
0
        public void IncreaseInventory_MultipleArticles_Success()
        {
            const decimal initialP1 = 3;
            const decimal initialP2 = 0;

            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Product1InteriorDoor, initialP1),
            };
            var items = new[]
            {
                new InventoryItem(Product1InteriorDoor, 5),
                new InventoryItem(Product2InteriorDoor, 6),
            };

            //act
            InventoryService.IncreaseInventory(items, shop);

            //assert
            var actualP1 = shop.Inventory.Of(Product1InteriorDoor).Amount;
            var actualP2 = shop.Inventory.Of(Product2InteriorDoor).Amount;

            Assert.That(actualP1, Is.EqualTo(initialP1 + items[0].Amount));
            Assert.That(actualP2, Is.EqualTo(initialP2 + items[1].Amount));
        }
Пример #2
0
        public void TransferInventory_Success()
        {
            decimal initialSource = 10;
            decimal initialTarget = 2;
            //arrange
            var source = ProductAssemblyShop.DeepCopy();

            source.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Product1InteriorDoor, initialSource)
            };
            var target = ProductStockpileShop.DeepCopy();

            target.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Product1InteriorDoor, initialTarget)
            };
            var item = new InventoryItem(Product1InteriorDoor, 2);

            //act
            InventoryService.Transfer(source, target, item);

            //assert
            var actualSource = source.Inventory.Of(Product1InteriorDoor).Amount;

            Assert.That(actualSource, Is.EqualTo(initialSource - item.Amount));

            var actualTarget = target.Inventory.Of(Product1InteriorDoor).Amount;

            Assert.That(actualTarget, Is.EqualTo(initialTarget + item.Amount));
        }
Пример #3
0
        public void ProduceInventory_FailFor_ArticleNotInStock()
        {
            decimal initialC1 = 5;
            decimal initialC2 = 8;
            // decimal initialC3 = 10;
            decimal initialP1 = 1;

            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Component1Vertical, initialC1),
                new InventoryItem(Component2Horizontal, initialC2),
                //  new InventoryItem(Component3MdfFiller, initialC3),
                new InventoryItem(Product1InteriorDoor, initialP1),
            };
            var item = new InventoryItem(Product1InteriorDoor, 2);

            //assert ()=> act
            var ex = Assert.Throws <DomainException>(() => InventoryService.Produce(shop, item, Product1Order));

            Assert.That(ex.Message,
                        Is.EqualTo(ArticleNotInStock(Component3MdfFiller, shop)));
        }
Пример #4
0
        public void ProduceInventory_FailFor_InsufficientInventory()
        {
            decimal initialC1 = 5;
            decimal initialC2 = 8;
            decimal initialC3 = 1;
            decimal initialP1 = 1;

            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Component1Vertical, initialC1),
                new InventoryItem(Component2Horizontal, initialC2),
                new InventoryItem(Component3MdfFiller, initialC3),
                new InventoryItem(Product1InteriorDoor, initialP1),
            };
            var item = new InventoryItem(Product1InteriorDoor, 2);

            //assert ()=> act
            var ex = Assert.Throws <DomainException>(() => InventoryService.Produce(shop, item, Product1Order));

            var input = Product1InteriorDoor.PrimaryBillOfMaterial.Input
                        .Of(Component3MdfFiller).Amount *item.Amount;

            Assert.That(ex.Message,
                        Is.EqualTo(InsufficientInventory(Component3MdfFiller, input, initialC3)));
        }
Пример #5
0
        public void ShipOrder_FailFor_OrderNotAtExitPoint()
        {
            //Arrange
            var order = new Order(Guid.NewGuid(), "Test order")
            {
                ItemsOrdered = new HashSet <InventoryItem>()
                {
                    new InventoryItem(Product1InteriorDoor, 5),
                },
                ItemsProduced = new HashSet <InventoryItem>()
                {
                    InventoryItem.Empty(Product1InteriorDoor),
                }
            };
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Orders = new HashSet <Order>()
            {
                order
            };
            order.Shop = shop;

            //Assert () => Act
            var ex = Assert.Throws <DomainException>(() => OrderService.ShipOrder(order));

            Assert.That(ex.Message, Is.EqualTo(OrderNotAtExitPoint(order)));
        }
Пример #6
0
        public void RemoveOrder_Success()
        {
            //Arrange
            var order = new Order(Guid.NewGuid(), "Test order")
            {
                ItemsOrdered = new HashSet <InventoryItem>()
                {
                    new InventoryItem(Product1InteriorDoor, 5),
                },
                ItemsProduced = new HashSet <InventoryItem>()
                {
                    InventoryItem.Empty(Product1InteriorDoor),
                }
            };
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Orders = new HashSet <Order>()
            {
                order
            };
            order.Shop = shop;

            //Act
            OrderService.RemoveOrder(order, shop);

            //Assert
            Assert.That(!shop.Orders.Contains(order), Is.True);
            Assert.That(order.Shop, Is.Null);
        }
Пример #7
0
        public void ReportSpoilage_Material_Success()
        {
            decimal initialC1 = 5;

            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Component1Vertical, initialC1),
            };
            var item  = new InventoryItem(Component1VerticalSpoiled, 2);
            var order = Product1Order.DeepCopy();

            //act
            InventoryService.ReportSpoilage(item, order, shop);

            //assert
            var actualS1 = shop.Inventory.Of(Component1VerticalSpoiled).Amount;

            Assert.That(actualS1, Is.EqualTo(item.Amount));

            var actualC1 = shop.Inventory.Of(Component1Vertical).Amount;

            Assert.That(actualC1, Is.EqualTo(initialC1 - item.Amount));
        }
Пример #8
0
        public void IncreaseInventory_FailFor_ArticleNotAllowed()
        {
            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory             = new HashSet <InventoryItem>();
            shop.ShopCategory          = shop.ShopCategory.DeepCopy();
            shop.ShopCategory.Articles = new HashSet <Article>();
            var item = new InventoryItem(Product1InteriorDoor, 5);

            //assert () => act
            Assert.Throws <DomainException>(() => InventoryService.IncreaseInventory(item, shop));
        }
Пример #9
0
        public void DecreaseInventory_FailFor_ArticleNotInStock()
        {
            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>();
            var item = new InventoryItem(Product1InteriorDoor, 5);

            //assert () => act
            var ex = Assert.Throws <DomainException>(() => InventoryService.DecreaseInventory(item, shop));

            Assert.That(ex.Message, Is.EqualTo(ArticleNotInStock(item.Article, shop)));
        }
Пример #10
0
        public void TransferInventory_FailFor_ArticleNotInStock()
        {
            //arrange
            var source = ProductAssemblyShop.DeepCopy();

            source.Inventory = new HashSet <InventoryItem>();
            var target = ProductStockpileShop.DeepCopy();
            var item   = new InventoryItem(Product1InteriorDoor, 2);

            //assert ()=> act
            var ex = Assert.Throws <DomainException>(() => InventoryService.Transfer(source, target, item));

            Assert.That(ex.Message, Is.EqualTo(ArticleNotInStock(Product1InteriorDoor, source)));
        }
Пример #11
0
        public void IncreaseInventory_ArticleWasNotInStockBefore_Success()
        {
            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>();
            var item = new InventoryItem(Product1InteriorDoor, 5);

            //act
            InventoryService.IncreaseInventory(item, shop);

            //assert
            var actual = shop.Inventory.Of(Product1InteriorDoor).Amount;

            Assert.That(actual, Is.EqualTo(item.Amount));
        }
Пример #12
0
        public void TransferInventory_FailFor_InsufficientInventory()
        {
            decimal initialP1 = 2;
            //arrange
            var source = ProductAssemblyShop.DeepCopy();

            source.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Product1InteriorDoor, initialP1)
            };
            var target = ProductStockpileShop.DeepCopy();
            var item   = new InventoryItem(Product1InteriorDoor, 10);

            //assert ()=> act
            var ex = Assert.Throws <DomainException>(() => InventoryService.Transfer(source, target, item));

            Assert.That(ex.Message, Is.EqualTo(InsufficientInventory(Product1InteriorDoor, item.Amount, initialP1)));
        }
Пример #13
0
        public void ReportSpoilage_Product_Success()
        {
            decimal initialC1 = 5;
            decimal initialC2 = 8;
            decimal initialC3 = 10;
            decimal initialP1 = 1;

            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Component1Vertical, initialC1),
                new InventoryItem(Component2Horizontal, initialC2),
                new InventoryItem(Component3MdfFiller, initialC3),
                new InventoryItem(Product1InteriorDoor, initialP1),
            };
            var item  = new InventoryItem(Product1InteriorDoorSpoiled, 2);
            var order = Product1Order.DeepCopy();

            //act
            InventoryService.ReportSpoilage(item, order, shop);

            //assert
            var actualP1 = shop.Inventory.Of(Product1InteriorDoor).Amount;

            Assert.That(actualP1, Is.EqualTo(initialP1));

            var actualS1 = shop.Inventory.Of(Product1InteriorDoorSpoiled).Amount;

            Assert.That(actualS1, Is.EqualTo(0 + item.Amount));

            AssertInput(initialC1, Component1Vertical);
            AssertInput(initialC2, Component2Horizontal);
            AssertInput(initialC3, Component3MdfFiller);

            void AssertInput(decimal initial, Article article)
            {
                var actual = shop.Inventory.Of(article).Amount;
                var input  = Product1InteriorDoor.PrimaryBillOfMaterial.Input.Of(article).Amount;

                Assert.That(actual, Is.EqualTo(initial - (input * item.Amount)));
            }
        }
Пример #14
0
        public void ProduceInventory_FailFor_ArticleNotInOrder()
        {
            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Component1Vertical, 5),
                new InventoryItem(Component2Horizontal, 8),
                new InventoryItem(Component3MdfFiller, 10),
                new InventoryItem(Product1InteriorDoor, 1),
            };
            var item = new InventoryItem(Product2InteriorDoor, 2);

            //assert ()=> act
            var ex = Assert.Throws <DomainException>(() => InventoryService.Produce(shop, item, Product1Order));

            Assert.That(ex.Message, Is.EqualTo(ArticleNotInOrder(Product1Order, item.Article)));
        }
Пример #15
0
        public void DecreaseInventory_SingleArticle_Success()
        {
            const decimal initial = 15;
            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Product1InteriorDoor, initial)
            };
            var item = new InventoryItem(Product1InteriorDoor, 5);

            //act
            InventoryService.DecreaseInventory(item, shop);

            //assert
            var actual = shop.Inventory.Of(Product1InteriorDoor).Amount;

            Assert.That(actual, Is.EqualTo(initial - item.Amount));
        }
Пример #16
0
        private void InitShopCategories()
        {
            TimberComponentShopCategory.Shops = TimberComponentShop.CollectToHashSet();
            TimberComponentShopCategory.Articles.Add(Material1Timber);
            TimberComponentShopCategory.Articles.Add(Material2Foil);
            TimberComponentShopCategory.Articles.Add(Component1Vertical);
            TimberComponentShopCategory.Articles.Add(Component2Horizontal);

            MdfComponentShopCategory.Shops = MdfComponentShop.CollectToHashSet();
            MdfComponentShopCategory.Articles.Add(Material3Mdf);
            MdfComponentShopCategory.Articles.Add(Material2Foil);
            MdfComponentShopCategory.Articles.Add(Component3MdfFiller);

            GlassComponentShopCategory.Articles.Add(Material4TintedGlass);
            GlassComponentShopCategory.Articles.Add(Component4GlassFiller);
            GlassComponentShopCategory.Shops = GlassComponentShop.CollectToHashSet();

            ProductAssemblyShopCategory.Articles.Add(Component1Vertical);
            ProductAssemblyShopCategory.Articles.Add(Component2Horizontal);
            ProductAssemblyShopCategory.Articles.Add(Component3MdfFiller);
            ProductAssemblyShopCategory.Articles.Add(Component4GlassFiller);
            ProductAssemblyShopCategory.Articles.Add(Product1InteriorDoor);
            ProductAssemblyShopCategory.Articles.Add(Product2InteriorDoor);
            ProductAssemblyShopCategory.Articles.Add(Component1VerticalSpoiled);
            ProductAssemblyShopCategory.Articles.Add(Product1InteriorDoorSpoiled);
            ProductAssemblyShopCategory.Shops = ProductAssemblyShop.CollectToHashSet();

            MaterialStockpileShopCategory.Articles.Add(Material1Timber);
            MaterialStockpileShopCategory.Articles.Add(Material2Foil);
            MaterialStockpileShopCategory.Articles.Add(Material3Mdf);
            MaterialStockpileShopCategory.Articles.Add(Material4TintedGlass);
            MaterialStockpileShopCategory.Shops = MaterialStockpileShop.CollectToHashSet();

            ProductStockpileShopCategory.Articles.Add(Product1InteriorDoor);
            ProductStockpileShopCategory.Articles.Add(Product2InteriorDoor);
            ProductStockpileShopCategory.Shops = ProductStockpileShop.CollectToHashSet();

            ShopCategoryToArchive.Shops = ShopToRemove.CollectToHashSet();
            ShopCategoryToArchive.Articles.Add(ArticleToArchive);
        }
Пример #17
0
        public void AssignOrder_FailFor_ArticleNotAllowed()
        {
            //Arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Orders = new HashSet <Order>();
            shop.ShopCategory.Articles = new HashSet <Article>();
            var order = new Order(Guid.NewGuid(), "Test order")
            {
                ItemsOrdered = new HashSet <InventoryItem>()
                {
                    new InventoryItem(Product1InteriorDoor, 5),
                },
                ItemsProduced = new HashSet <InventoryItem>()
                {
                    InventoryItem.Empty(Product1InteriorDoor),
                }
            };

            //Assert () => Act
            var ex = Assert.Throws <DomainException>(() => OrderService.AssignOrder(order, shop));

            Assert.That(ex.Message, Is.EqualTo(ArticleNotAllowedInShop(Product1InteriorDoor, shop)));
        }
Пример #18
0
        public void ProduceInventory_FailFor_ProductionRequestExceedsRequirements()
        {
            decimal initialP1 = 1;
            //arrange
            var shop = ProductAssemblyShop.DeepCopy();

            shop.Inventory = new HashSet <InventoryItem>()
            {
                new InventoryItem(Component1Vertical, 5),
                new InventoryItem(Component2Horizontal, 8),
                new InventoryItem(Component3MdfFiller, 10),
                new InventoryItem(Product1InteriorDoor, initialP1),
            };
            var yetRequired = Product1Order.ItemsOrdered.Single(i => i.Article == Product1InteriorDoor).Amount -
                              Product1Order.ItemsProduced.Single(i => i.Article == Product1InteriorDoor).Amount;
            var item = new InventoryItem(Product1InteriorDoor, yetRequired * 2);

            //assert ()=> act
            var ex = Assert.Throws <DomainException>(() => InventoryService.Produce(shop, item, Product1Order));

            Assert.That(ex.Message,
                        Is.EqualTo(ProductionRequestExceedsRequirements(Product1Order, yetRequired, item.Article,
                                                                        item.Amount)));
        }