Esempio n. 1
0
        public void VegetableTrackerTest()
        {
            VegetableTracker     vegetableTracker     = new VegetableTracker();
            ConfigurationManager configurationManager = new ConfigurationManager(StorageFactory.GetStorage("inMemory"));
            Tomato     tomato     = new Tomato();
            Cabbage    cabbage    = new Cabbage();
            LadyFinger ladyFinger = new LadyFinger();


            var vegetableQuantity = new List <KeyValuePair <Vegetable, int> >();

            vegetableQuantity.Add(new KeyValuePair <Vegetable, int>(tomato, 25));
            vegetableQuantity.Add(new KeyValuePair <Vegetable, int>(cabbage, 3));
            vegetableQuantity.Add(new KeyValuePair <Vegetable, int>(ladyFinger, 2));

            configurationManager.SetMinimumQuantity(tomato, 5);
            configurationManager.SetMinimumQuantity(cabbage, 5);
            configurationManager.SetMinimumQuantity(ladyFinger, 5);

            var expectedInsufficientVegetables = new List <KeyValuePair <Vegetable, int> >();

            expectedInsufficientVegetables.Add(new KeyValuePair <Vegetable, int>(cabbage, 3));
            expectedInsufficientVegetables.Add(new KeyValuePair <Vegetable, int>(ladyFinger, 2));

            var actualInsufficientVegetables = vegetableTracker.GetInsufficientVegetableQuantity(vegetableQuantity, configurationManager);

            Assert.Equal(expectedInsufficientVegetables, actualInsufficientVegetables);
        }
        public string SendNotification()
        {
            var vegetableList = vegetableTracker.GetInsufficientVegetableQuantity();

            if (vegetableList.Count != 0)
            {
                return("Required To Order");
            }
            return("No order required");
        }
Esempio n. 3
0
        public string NotifyUser()
        {
            var OrderDetails = vegetableTracker.GetInsufficientVegetableQuantity();

            if (OrderDetails.Count != 0)
            {
                return("Need to order the vegetables Through Email");
            }
            else
            {
                return("Sufficient");
            }
        }
Esempio n. 4
0
        public void GetInsufficientVegetableQuantityTest()
        {
            var     inMemoryStorage = new InMemoryStorage();
            var     config          = new ConfigurationManager(inMemoryStorage);
            var     vegetableTray   = new VegetableTray();
            Tomato  tomato          = new Tomato();
            Cabbage cabbage         = new Cabbage();

            config.SetMinimumQuantity(tomato, 3);
            config.SetMinimumQuantity(cabbage, 1);

            vegetableTray.Add(tomato, 5);
            vegetableTray.Add(cabbage, 3);

            vegetableTray.TakeOut(tomato, 3);

            VegetableTracker vegetableTracker = new VegetableTracker(vegetableTray, config);

            Assert.AreEqual(1, vegetableTracker.GetInsufficientVegetableQuantity().Count);
        }
        public void PlaceOrder()
        {
            Tomato  tomato  = new Tomato();
            Cabbage cabbage = new Cabbage();

            VegetableTray tray = new VegetableTray();

            tray.Add(tomato, 5000);
            tray.Add(cabbage, 4000);


            IStorage storage = new InMemoryStorage();

            ConfigurationManager configurationManager = new ConfigurationManager(storage);

            configurationManager.SetMinimumQuantity(tomato, 2000);
            configurationManager.SetMinimumQuantity(cabbage, 2000);

            tray.TakeOut(tomato, 4000);

            VegetableTracker vegetableTracker = new VegetableTracker(configurationManager, tray);
            var insufficientVegetables        = vegetableTracker.GetInsufficientVegetableQuantity();

            Order order = new Order(vegetableTracker, configurationManager, tray);

            order.PlaceOrder();

            List <KeyValuePair <Vegetable, int> > cartItems = new List <KeyValuePair <Vegetable, int> >()
            {
                new KeyValuePair <Vegetable, int>(new Tomato(), 2000),
                new KeyValuePair <Vegetable, int>(new Cabbage(), 4000)
            };

            var trayVegetables = tray.GetVegetableQuantity();

            for (int i = 0; i < cartItems.Count; i++)
            {
                Assert.Equal(cartItems[i].Value, trayVegetables[i].Value);
            }
        }
        public void InsufficientQauntity()
        {
            Tomato  tomato  = new Tomato();
            Cabbage cabbage = new Cabbage();

            VegetableTray tray = new VegetableTray();

            tray.Add(tomato, 5000);
            tray.Add(cabbage, 4000);
            tray.TakeOut(tomato, 4000);

            IStorage storage = new InMemoryStorage();

            ConfigurationManager configurationManager = new ConfigurationManager(storage);

            configurationManager.SetMinimumQuantity(tomato, 2000);
            configurationManager.SetMinimumQuantity(cabbage, 2000);

            VegetableTracker vegetableTracker = new VegetableTracker(configurationManager, tray);
            var insufficientVegetables        = vegetableTracker.GetInsufficientVegetableQuantity();

            Assert.Equal(tomato.Name, insufficientVegetables[0].Key.Name);
        }