public void TestOrderItem()
        {
            VendingItem item       = new VendingItem(1, "Coke", V, 5);
            var         helperMock = new Mock <IHelper>();

            helperMock.Setup(x => x.PopulateItems()).Returns(new Dictionary <int, VendingItem>()
            {
                { 1, item }
            });

            BlOrders order = new BlOrders();

            try {
                order.CheckAmount(7, helperMock.Object.PopulateItems()[1], 4); Assert.Fail();
            }
            catch (Exception e) {
                Assert.AreEqual("Error ocured in ordering Amount not OK!", e.Message + " " + e.InnerException.Message);
            }
        }
        public void Buy_DenialOfPaymentSystem_ThrowsException()
        {
            DeliverySystemSubstitute deliverySystem = new DeliverySystemSubstitute();

            deliverySystem.ResultOfIsItemPresent  = true;
            deliverySystem.ResultOfTryDeliverItem = true;

            VendingMachine vendingMachine = new VendingMachine(deliverySystem);

            VendingItem item = new VendingItem(new VendingItemId(0), ItemType.Drink, "Water", 1);

            vendingMachine.AddItemToCatalogue(item);

            PaymentSystemSubstitute paymentSystem = new PaymentSystemSubstitute();

            paymentSystem.ResultOfWithholdOfPayment = false;

            Assert.Catch(() => vendingMachine.BuyItem(item, paymentSystem));
        }
Example #3
0
    static void Main(string[] args)
    {
        List <VendingItem> stockCatalog = CatalogueData();

        // Show the catalog to the user
        stockCatalog.ForEach(i => {
            Console.WriteLine($"Snack: {i.name}, Code: {i.code}, Price: £{i.price}");
        });
        // Get an item selection from the user
        VendingItem selection = GetSelection(stockCatalog);

        // Get a quantity from the user
        Console.WriteLine("How many of this item would you like?");
        int    numOfItem  = int.Parse(Console.ReadLine());
        double totalValue = selection.price * numOfItem;

        Console.WriteLine($"Your total cost is {totalValue}.");

        Console.ReadLine();
    }
Example #4
0
    static void Main(string[] args)
    {
        Dictionary <string, VendingItem> stockDictionary = CatalogDataDictionary();

        // Show the catalog to the user
        foreach (KeyValuePair <string, VendingItem> i in stockDictionary)
        {
            Console.WriteLine($"Snack: {i.Value.name}, Code: {i.Value.code}, Price: £{i.Value.price}");
        }
        // Get an item selection from the user
        VendingItem selection = GetSelection(stockDictionary);

        // Get a quantity from the user
        Console.WriteLine("How many of this item would you like?");
        int    numOfItem  = int.Parse(Console.ReadLine());
        double totalValue = selection.price * numOfItem;

        Console.WriteLine($"Your total cost is {totalValue}.");

        Console.ReadLine();
    }
Example #5
0
        private void AddProduct()
        {
            //Create object to hold transaction data
            VendingItem item = new VendingItem();

            //Category Table
            item.CategoryName = "TestCategory";
            item.Noise        = "Test Munch Crumble Pop, Yuck!";

            //Product Table
            item.ProductName = "Nasty Bites";
            item.Price       = 5.00;

            //Inventory Table
            item.Qty    = 1;
            item.Row    = 6;
            item.Column = 1;

            //Call method to insert rows in the three tables
            _db.AddVendingItem(item);
        }
        public void Catalogue_SetCatalogue_CatalogueChanged()
        {
            VendingMachine vendingMachine = new VendingMachine(new DeliverySystemSubstitute());

            var stateBeforeInit = vendingMachine.GetCatalogue();

            VendingItem[] catalogue = new VendingItem[]
            {
                new VendingItem(new VendingItemId(0), ItemType.Drink, "Water", 1),
                new VendingItem(new VendingItemId(1), ItemType.Food, "Bread", 1),
                new VendingItem(new VendingItemId(2), ItemType.Weapon, "CheyTac M200", 12500)
            };

            vendingMachine.SetCatalogue(catalogue);

            var stateAfterInit = vendingMachine.GetCatalogue();

            VendingItem[] receivedCatalogue = stateAfterInit.ToArray();

            Assert.AreNotEqual(stateBeforeInit, stateAfterInit);
            Assert.AreEqual(catalogue, receivedCatalogue);
        }
        public List <VendingItem> GetVendingItems()
        {
            List <VendingItem> items = new List <VendingItem>();

            try
            {
                foreach (InventoryItem item in _inventoryItems.Values.ToList())
                {
                    VendingItem vendingItem = new VendingItem();
                    vendingItem.Inventory = item.Clone();
                    vendingItem.Product   = _productItems[item.ProductId].Clone();
                    vendingItem.Category  = _categoryItems[vendingItem.Product.CategoryId].Clone();
                    items.Add(vendingItem);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Mock database is corrupt. All inventory slots must contain a " +
                                    "reference to a product and all products must contain a reference to a category.", ex);
            }

            return(items);
        }
        public void Buy_ControlPassedToDeliverySystem()
        {
            DeliverySystemSubstitute deliverySystem = new DeliverySystemSubstitute();

            deliverySystem.ResultOfIsItemPresent  = true;
            deliverySystem.ResultOfTryDeliverItem = true;

            VendingMachine vendingMachine = new VendingMachine(deliverySystem);

            VendingItem item = new VendingItem(new VendingItemId(0), ItemType.Drink, "Water", 1);

            vendingMachine.AddItemToCatalogue(item);

            PaymentSystemSubstitute paymentSystem = new PaymentSystemSubstitute();

            paymentSystem.ResultOfWithholdOfPayment = true;

            vendingMachine.BuyItem(item, paymentSystem);

            bool controlPassed = deliverySystem.ControlPassedIsItemPresent && deliverySystem.ControlPassedTryDeliverItem;

            Assert.IsTrue(controlPassed);
        }
Example #9
0
        public TransactionResult WithdrawVendingItem(VendingItem item, IEnumerable <VendingCoin> insertedCoins)
        {
            TransactionResult result = new TransactionResult();

            IEnumerable <VendingCoin> coinInventorySnapshot = null;

            try
            {
                if (item == null)
                {
                    throw new ArgumentNullException("Item is null");
                }

                if (insertedCoins == null || insertedCoins.Count() == 0)
                {
                    throw new ArgumentNullException("Inserted coins is empty");
                }

                decimal insertedCoinAmount = insertedCoins.Sum(s => s.Amount);
                if (insertedCoinAmount < item.Price)
                {
                    throw new ArgumentException("Insuffecient amount. Please insert more coins.");
                }

                var itemInv = VendingItemRepository.VendingItems.Where(w => w.Name == item.Name).FirstOrDefault();
                if (itemInv.Quantity <= 0)
                {
                    throw new ArgumentException("No stocks available. Please choose another item.");
                }

                decimal changeAmount = insertedCoinAmount - item.Price;

                coinInventorySnapshot = vendingCoinInventoryService.CreateInventorySnapshot();

                vendingCoinInventoryService.AddCoins(insertedCoins);
                var coinsForChange = vendingCoinInventoryService.PickCoinsForChange(changeAmount);

                decimal coinsForChangeAmount = coinsForChange.Sum(s => s.Amount);
                if (coinsForChangeAmount == changeAmount)
                {
                    itemInv.Quantity -= 1;

                    result.IsSuccess      = true;
                    result.Message        = "Thank You.";
                    result.ReturnedAmount = coinsForChangeAmount;
                    result.ReturnedCoins  = coinsForChange;
                }
                else
                {
                    throw new Exception("Not enough coins for change. Please give an exact amount.");
                }
            }
            catch (Exception e)
            {
                if (coinInventorySnapshot != null)
                {
                    vendingCoinInventoryService.RestoreInventorySnapshot(coinInventorySnapshot.ToList());
                }

                result.IsSuccess      = false;
                result.Message        = e.Message;
                result.ReturnedAmount = insertedCoins.Sum(s => s.Amount);
                result.ReturnedCoins  = insertedCoins;
            }

            return(result);
        }
Example #10
0
 public int FindDifference(VendingItem item, int payment)
 {
     return((int)(item.Price - payment) * 100);
 }
Example #11
0
 public void AddVendingItem(VendingItem item)
 {
     _vendingItems.Add(item);
 }
Example #12
0
 public Slot(VendingItem givenItem, int givenQuantity = 0)
 {
     item     = givenItem;
     quantity = givenQuantity;
 }
Example #13
0
 /*Clears the given [x,y] slot of product, if any. Sets the slot to the new product at the given quantity*/
 public void setNewProduct(VendingItem newProduct, int quantity, int x, int y)
 {
     this.inventory.insertNew(newProduct, quantity, x, y);
 }
 public ProductViewModel(int id, string name, double price)
 {
     _model   = new VendingItem(id, name, price);
     Quantity = 0;
 }
Example #15
0
 public void AddItem(VendingItem item)
 {
     Inventory[item.Inventory.Column - 1, item.Inventory.Row - 1] = item;
 }
 public ProdutoViewModel(int id, string nome, double valor)
 {
     _model = new VendingItem(id, nome, valor);
     Qtd    = 0;
 }
Example #17
0
        public IActionResult WithdrawVendingItem(VendingItem item, IEnumerable <VendingCoin> coins)
        {
            var result = vendingMachineService.WithdrawVendingItem(item, coins);

            return(Json(result));
        }