示例#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);
        }
示例#2
0
        public INotification FactoryNotifier(string TypeOfNotifier, VegetableTracker vegetableTracker)
        {
            switch (TypeOfNotifier)
            {
            case "SMS":
                return(new NotifierThroughSms(vegetableTracker));

            case "Email":
                return(new NotifierThroughEmail(vegetableTracker));

            default:
                throw new System.NotImplementedException();
            }
        }
示例#3
0
        public void PlaceOrderTest()
        {
            var refrigerator = new Refrigerator();
            var tracker      = new VegetableTracker();
            var tomato       = new Tomato();

            refrigerator.AddVegetable(tomato, 5);
            refrigerator.SetMinimumVegetableQuantity(tomato, 4);
            refrigerator.SetMaximumRefillLimit(tomato, 10);
            tracker.PlaceOrder(refrigerator);

            var expected = new List <KeyValuePair <Vegetable, int> >()
            {
                new KeyValuePair <Vegetable, int>(tomato, 5)
            };
            var actual = refrigerator.GetVegetableQuantity();

            Assert.Equal(expected, actual);
        }
示例#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);
        }
示例#7
0
 public NotifierThroughSms(VegetableTracker vegetableTracker)
 {
     this.vegetableTracker = vegetableTracker;
 }
 public NotificationFactory(string notifiacationType,VegetableTracker vegetableTracker)
 {
     this.vegetableTracker = vegetableTracker;
     this.notifiacationType = notifiacationType;
 }
 public Notifier(VegetableTracker vegetableTracker)
 {
     this.vegetableTracker = vegetableTracker;
 }