Exemple #1
0
        public Stock(ProcessProduct processProduct)
        {
            CheckNullArgument(processProduct);

            productList         = new Dictionary <string, Product>();
            this.processProduct = processProduct;
        }
Exemple #2
0
        public void RemoveWhenProductExistAndThereIsAtLeast10ProductsLeftShouldReturnTrueAndRemoveQuantity()
        {
            bool notificationSent = false;

            Action <Product> notification =
                product =>
            {
                // Notification will not be sent at any given moment
                notificationSent = true;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            Product testProduct = new Product("apricot", 16);

            stockTest.Add(testProduct);

            Product productToRemove = new Product("apricot", 6);

            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(10, stockTest.Check(testProduct));
            Assert.False(notificationSent);
        }
Exemple #3
0
        public void RemoveWhenProductExistAndThereIsNotEnoughProductsShouldReturnFalse()
        {
            Product testProduct = new Product("apricot", 16);

            bool notificationSent = false;

            Action <Product> notification =
                product =>
            {
                // Notification will not be sent at any given moment
                notificationSent = true;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            stockTest.Add(testProduct);

            Product productToRemove = new Product("apricot", 20);

            Assert.False(stockTest.Remove(productToRemove));

            Assert.Equal(16, stockTest.Check(new Product("apricot", 0)));
            Assert.False(notificationSent);
        }
        public void VerfiyParsingAndProcessing()
        {
            var productproces = new ProcessProduct();
            var result        = productproces.Process("LearningToSkiVideo");

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result.Contains(TypeOfActionAgainstOrder.AddFreeAidVideoToPackagingSlip));
        }
Exemple #5
0
        private static void ProcessOrder(string rule)
        {
            Console.WriteLine($"Order Process Successfully For {rule}");
            var processProduct = new ProcessProduct();
            var actions        = processProduct.Process(rule);

            OrderProcessResult(actions);
        }
Exemple #6
0
        public void StockWhenAnyShouldCreateEmptyStock()
        {
            bool notificationSent = false;

            Action <Product> notification =
                product =>
            {
                // Notification will not be sent at any given moment
                notificationSent = true;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            Assert.Empty(stockTest);
            Assert.False(notificationSent);
        }
Exemple #7
0
        public void StockWhenNullProcessProductShouldThrowException()
        {
            bool notificationSent = false;

            Action <Product> notification =
                product =>
            {
                // Notification will not be sent at any given moment
                notificationSent = true;
            };

            ProcessProduct testNotification = null;

            Stock stockTest;

            Assert.Throws <ArgumentNullException>(() => stockTest = new Stock(testNotification));
            Assert.False(notificationSent);
        }
        static void RunRuleAndGenerateActions(string product)
        {
            var productproces = new ProcessProduct();
            var actions       = productproces.Process(product);

            Console.WriteLine($"For product {product} below actions were taken -");

            foreach (var action in actions)
            {
                switch (action)
                {
                case TypeOfActionAgainstOrder.ActivateMembership:
                    Console.WriteLine("Activating the membership");
                    break;

                case TypeOfActionAgainstOrder.AddFreeAidVideoToPackagingSlip:
                    Console.WriteLine("Adding free “First Aid” video to the packing slip ");
                    break;


                case TypeOfActionAgainstOrder.DuplicatePackaingSlip:
                    Console.WriteLine("Creating a duplicate packing slip for the royalty department.");
                    break;

                case TypeOfActionAgainstOrder.GenerateCommission:
                    Console.WriteLine("Generating a commission payment to the agent.");
                    break;

                case TypeOfActionAgainstOrder.GeneratePackagingSlip:
                    Console.WriteLine("Generating a packing slip for shipping.");
                    break;

                case TypeOfActionAgainstOrder.SendEmail:
                    Console.WriteLine("Sending email for activation/upgrade.");
                    break;

                case TypeOfActionAgainstOrder.UpgradeMembership:
                    Console.WriteLine("Upgrading the membership.");
                    break;
                }
            }
            Console.WriteLine(Environment.NewLine);
        }
Exemple #9
0
        public void CheckWhenProductNoExistShouldReturnMinus1()
        {
            Product testProduct = new Product("apricot", 8);

            bool notificationSent = false;

            Action <Product> notification =
                product =>
            {
                // Notification will not be sent at any given moment
                notificationSent = true;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            Assert.Equal(-1, stockTest.Check(testProduct));
            Assert.False(notificationSent);
        }
Exemple #10
0
        public void RemoveWhenProductNoExistShouldReturnFalse()
        {
            bool notificationSent = false;

            Action <Product> notification =
                product =>
            {
                // Notification will not be sent at any given moment
                notificationSent = true;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            Product productToRemove = new Product("apricot", 6);

            Assert.False(stockTest.Remove(productToRemove));
            Assert.False(notificationSent);
        }
Exemple #11
0
        public void AddWhenProductExistShouldIncreaseQuantity()
        {
            bool notificationSent = false;

            Action <Product> notification =
                product =>
            {
                // Notification will not be sent at any given moment
                notificationSent = true;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            Product testProduct = new Product("apricot", 8);

            stockTest.Add(testProduct);
            stockTest.Add(testProduct);

            Assert.Equal(16, stockTest.Check(testProduct));
            Assert.False(notificationSent);
        }
Exemple #12
0
        public void RemoveWhenThereIsBeetwen1and0ProductsLeftShouldSendNotificationOnce()
        {
            Product testProduct = new Product("apricot", 2);

            string notifiedProduct       = null;
            int    notifiedQuantity      = -1;
            int    numberOfNotifications = 0;

            Action <Product> notification =
                product =>
            {
                notifiedProduct  = product.Name;
                notifiedQuantity = product.Quantity;
                numberOfNotifications++;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            stockTest.Add(testProduct);

            Product productToRemove = new Product("apricot", 1);

            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(1, stockTest.Check(testProduct));
            Assert.Equal(testProduct.Name, notifiedProduct);
            Assert.Equal(1, notifiedQuantity);
            Assert.Equal(1, numberOfNotifications);

            // Second Remove, no notification sent
            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(0, stockTest.Check(testProduct));
            Assert.Equal(testProduct.Name, notifiedProduct);
            Assert.Equal(1, notifiedQuantity);
            Assert.Equal(1, numberOfNotifications);
        }
Exemple #13
0
        public void RemoveWhenDifferentNotificationsTriggeredShouldSendEachNotificationOnce()
        {
            Product initialtestProduct = new Product("apricot", 10);

            string notifiedProduct       = null;
            int    notifiedQuantity      = -1;
            int    numberOfNotifications = 0;

            Action <Product> notification =
                product =>
            {
                notifiedProduct  = product.Name;
                notifiedQuantity = product.Quantity;
                numberOfNotifications++;
            };

            ProcessProduct testNotification = new ProcessProduct(notification);

            Stock stockTest = new Stock(testNotification);

            stockTest.Add(initialtestProduct);

            Product productToRemove = new Product("apricot", 1);

            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(9, stockTest.Check(initialtestProduct));
            Assert.Equal(initialtestProduct.Name, notifiedProduct);
            Assert.Equal(9, notifiedQuantity);
            Assert.Equal(1, numberOfNotifications);

            // Second Remove, no notification sent
            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(8, stockTest.Check(initialtestProduct));
            Assert.Equal(initialtestProduct.Name, notifiedProduct);
            Assert.Equal(9, notifiedQuantity);
            Assert.Equal(1, numberOfNotifications);

            // Third Remove, second notification sent (less than 5 products)
            productToRemove.Quantity = 4;

            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(4, stockTest.Check(initialtestProduct));
            Assert.Equal(initialtestProduct.Name, notifiedProduct);
            Assert.Equal(4, notifiedQuantity);
            Assert.Equal(2, numberOfNotifications);

            // Fourth Remove, no notification sent
            productToRemove.Quantity = 2;

            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(2, stockTest.Check(initialtestProduct));
            Assert.Equal(initialtestProduct.Name, notifiedProduct);
            Assert.Equal(4, notifiedQuantity);
            Assert.Equal(2, numberOfNotifications);

            // Fifth Remove, third notification sent (less than 2 products)
            productToRemove.Quantity = 1;

            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(1, stockTest.Check(initialtestProduct));
            Assert.Equal(initialtestProduct.Name, notifiedProduct);
            Assert.Equal(1, notifiedQuantity);
            Assert.Equal(3, numberOfNotifications);

            // Fourth Remove, no notification sent
            Assert.True(stockTest.Remove(productToRemove));
            Assert.Equal(0, stockTest.Check(initialtestProduct));
            Assert.Equal(initialtestProduct.Name, notifiedProduct);
            Assert.Equal(1, notifiedQuantity);
            Assert.Equal(3, numberOfNotifications);
        }