Ejemplo n.º 1
0
        public void VendingDoesHaveEnoughChangeTest()
        {
            Customer customer = new Customer("customer");
            Coin coin = new Coin(10);
            Coin coin1 = new Coin(5);
            customer.Wallet.AddItem(coin);
            customer.Wallet.AddItem(coin1);

            VendingMachine vmachine = new VendingMachine("vmachine");
            GoodsItem item = new GoodsItem(7, "green tea");
            vmachine.GoodsStorage.AddItem(item);

            customer.InsertCoin(coin, vmachine);
            customer.InsertCoin(coin1, vmachine);

            vmachine.SellTheItem(item, customer);

            Assert.AreEqual(15, customer.Wallet.MoneyAmount, "customer wallet");
            Assert.AreEqual(0, customer.GoodsStorage.GoodsCount, "customer goods storage");
            Assert.AreEqual(0, vmachine.Wallet.MoneyAmount, "vm wallet");
            Assert.AreEqual(1, vmachine.GoodsStorage.GoodsCount, "vm goods storage");
        }
Ejemplo n.º 2
0
        public void VendingReturnChangeTest()
        {
            Customer customer = new Customer("customer");
            Coin coin = new Coin(10);
            Coin coin1 = new Coin(10);
            customer.Wallet.AddItem(coin);
            customer.Wallet.AddItem(coin1);

            VendingMachine vmachine = new VendingMachine("vmachine");
            GoodsItem item = new GoodsItem(15, "green tea");
            vmachine.GoodsStorage.AddItem(item);
            
            Coin coin0 = new Coin(5);
            Coin coin01 = new Coin(3);
            Coin coin02 = new Coin(2);
            vmachine.Wallet.AddItem(coin0);
            vmachine.Wallet.AddItem(coin01);
            vmachine.Wallet.AddItem(coin02);

            customer.InsertCoin(coin, vmachine);
            customer.InsertCoin(coin1, vmachine);

            vmachine.SellTheItem(item, customer);

            Assert.AreEqual(5, customer.Wallet.MoneyAmount, "customer wallet");
            Assert.AreEqual(1, customer.GoodsStorage.GoodsCount, "customer goods storage");
            Assert.AreEqual(1, customer.Wallet.GetItems(a=>a==coin0,-1).Count, "customer wallet");
            Assert.AreEqual(25, vmachine.Wallet.MoneyAmount, "vm wallet");
            Assert.AreEqual(0, vmachine.GoodsStorage.GoodsCount, "vm goods storage");
        }