Ejemplo n.º 1
0
        public void ProduceOrderWithAmount_ShouldReturnCombinationWithSeveralQuantity()
        {
            var orderService = new OrderService();

            var product    = new Product("P1", "Name", 1.22m);
            var batchSizes = new BatchSize[] {
                new BatchSize("BS1", 60),
                new BatchSize("BS2", 100),
                new BatchSize("BS3", 120),
                new BatchSize("BS4", 30),
                new BatchSize("BS5", 20)
            };
            var productBatchSizes = new ProductBatchSize[] {
                new ProductBatchSize("P1", "BS1"),
                new ProductBatchSize("P1", "BS2"),
                new ProductBatchSize("P1", "BS3"),
                new ProductBatchSize("P1", "BS4"),
                new ProductBatchSize("P1", "BS5")
            };

            var result = orderService.ProduceOrders(product, batchSizes, productBatchSizes, 70).ToList();

            Assert.Equal(2, result.Count);
            Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 30));
            Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 20));
            Assert.Equal(2, result.SingleOrDefault(r => r.BatchSize == 20).BatchQuantity);
        }
Ejemplo n.º 2
0
        public void ProduceOrderWithAmount_ShouldReturnClosestBatchSizeFromBiggerBatches()
        {
            var orderService = new OrderService();

            var product    = new Product("P1", "Name", 1.22m);
            var batchSizes = new BatchSize[] {
                new BatchSize("BS1", 120),
                new BatchSize("BS2", 300),
                new BatchSize("BS3", 500),
                new BatchSize("BS4", 600),
                new BatchSize("BS5", 80),
                new BatchSize("BS6", 100)
            };
            var productBatchSizes = new ProductBatchSize[] {
                new ProductBatchSize("P1", "BS1"),
                new ProductBatchSize("P1", "BS2"),
                new ProductBatchSize("P1", "BS3"),
                new ProductBatchSize("P1", "BS4"),
                new ProductBatchSize("P1", "BS5"),
                new ProductBatchSize("P1", "BS6")
            };

            var result = orderService.ProduceOrders(product, batchSizes, productBatchSizes, 70).ToList();

            Assert.Single(result);
            Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 80));
        }
Ejemplo n.º 3
0
        public void ProduceOrderWithAmount_ShouldReturnDesiredBatchSize()
        {
            var orderService = new OrderService();

            var product           = new Product("P1", "Name", 1.22m);
            var batchSizes        = new BatchSize[] { new BatchSize("BS1", 70), new BatchSize("BS2", 30), new BatchSize("BS3", 40) };
            var productBatchSizes = new ProductBatchSize[] {
                new ProductBatchSize("P1", "BS1"),
                new ProductBatchSize("P1", "BS2"),
                new ProductBatchSize("P1", "BS3")
            };

            var result = orderService.ProduceOrders(product, batchSizes, productBatchSizes, 70).ToList();

            Assert.Single(result);
            Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 70));
        }
Ejemplo n.º 4
0
        public void ProduceOrderWithIncorrectDataShouldThrowException(int quantity, string productCode, int batchSize)
        {
            var batchQuantities = new BatchQuantity[]
            {
                new BatchQuantity(productCode, quantity)
            };

            var products = new Product[] { new Product(productCode, "name", 5.33m) };

            var batchSizes = new BatchSize[] { new BatchSize("BS123", batchSize) };

            var productBatchSizes = new ProductBatchSize[] { new ProductBatchSize(productCode, "BS123") };

            var orderService = new OrderService();

            Assert.Throws <ArgumentException>(() =>
                                              orderService.ProduceOrders(products, batchSizes, productBatchSizes, batchQuantities, false));
        }