Exemplo n.º 1
0
        public void Test_PurchaceItem9()
        {
            string userId = "user_with_1000";
            string itemId = "weapon_3";
            int    count  = -1;

            ItemStockInfo itemInfo      = new ItemStockInfo(new Item("weapon_3"), 124, 17); // copied from initialVendingMachineItems
            int           userBalance   = 1000;
            int           userItemCount = 0;

            var purchaseWasSuccessful = PurchaceItemTester((userId, itemId, count), (itemInfo, userBalance, userItemCount));

            Assert.AreEqual(false, purchaseWasSuccessful); // cannot purchase negative amount of items
        }
Exemplo n.º 2
0
        public void Test_PurchaceItem6()
        {
            string userId = "user_with_1000";
            string itemId = "weapon_1";
            int    count  = 9;

            ItemStockInfo itemInfo      = new ItemStockInfo(new Item("weapon_1"), 124, 1); // copied from initialVendingMachineItems
            int           userBalance   = 1000;
            int           userItemCount = 0;

            var purchaseWasSuccessful = PurchaceItemTester((userId, itemId, count), (itemInfo, userBalance, userItemCount));

            Assert.AreEqual(false, purchaseWasSuccessful);  // not enough items & not enough balance
        }
Exemplo n.º 3
0
        public void Test_PurchaceItem4()
        {
            string userId = "unknown_user";
            string itemId = "food_244";
            int    count  = 1;

            ItemStockInfo itemInfo      = new ItemStockInfo(new Item("food_244"), 14, 5); // copied from initialVendingMachineItems
            int           userBalance   = 0;
            int           userItemCount = 0;

            var purchaseWasSuccessful = PurchaceItemTester((userId, itemId, count), (itemInfo, userBalance, userItemCount));

            Assert.AreEqual(false, purchaseWasSuccessful); // unknown user
        }
Exemplo n.º 4
0
        public void Test_PurchaceItem3()
        {
            string userId = "user_with_100";
            string itemId = "food_244";
            int    count  = 2;

            ItemStockInfo itemInfo      = new ItemStockInfo(new Item("food_244"), 14, 5); // copied from initialVendingMachineItems
            int           userBalance   = 100;
            int           userItemCount = 0;

            var purchaseWasSuccessful = PurchaceItemTester((userId, itemId, count), (itemInfo, userBalance, userItemCount));

            Assert.AreEqual(true, purchaseWasSuccessful);
        }
Exemplo n.º 5
0
        public void Test_PurchaceItem1()
        {
            string userId = "user_with_1000";
            string itemId = "unknown_item_id";
            int    count  = 1;

            ItemStockInfo itemInfo      = new ItemStockInfo();
            int           userBalance   = 1000;
            int           userItemCount = 0;

            var purchaseWasSuccessful = PurchaceItemTester((userId, itemId, count), (itemInfo, userBalance, userItemCount));

            Assert.AreEqual(false, purchaseWasSuccessful); // unknown item
        }
Exemplo n.º 6
0
        public void Test_ReplaceItems()
        {
            var itemsToReplace = new ItemStockInfo[] {
                new ItemStockInfo(new Item("c_12"), 7, 0),
                new ItemStockInfo(new Item("b_24"), 14, 5),
                new ItemStockInfo(new Item("a_12"), 3, 5)
            };

            vendingMachine.ReplaceItems(itemsToReplace);

            var shouldMatch = itemsToReplace
                              .Where(isi => isi.count > 0)
                              .OrderBy(isi => isi.item.id).ToArray();

            Assert.AreEqual(shouldMatch, vendingMachine.GetCatalogueItems());
        }
Exemplo n.º 7
0
        public void Test_AddItems()
        {
            vendingMachine.RemoveItems();

            var a = new ItemStockInfo[] {
                new ItemStockInfo(new Item("w_1"), 124, 1),
                new ItemStockInfo(new Item("w_2"), 32, 1),
            };

            var b = new ItemStockInfo[] {
                new ItemStockInfo(new Item("f_12"), 7, 0),
                new ItemStockInfo(new Item("f_24"), 14, 5),
                new ItemStockInfo(new Item("d_12"), 3, 5)
            };

            var c = new ItemStockInfo[] {
                new ItemStockInfo(new Item("as_142"), 117, 0),
                new ItemStockInfo(new Item("g_242"), 1124, 5),
                new ItemStockInfo(new Item("hg_342"), 344, 5)
            };

            vendingMachine.AddItems(a);
            vendingMachine.AddItems(b);
            vendingMachine.AddItems(c);


            var expectedItems = new List <ItemStockInfo>();

            expectedItems.AddRange(a);
            expectedItems.AddRange(b);
            expectedItems.AddRange(c);
            expectedItems = expectedItems
                            .Where(item => item.count > 0)
                            .OrderBy(item => item.item.id).ToList();

            var items = vendingMachine.GetCatalogueItems();

            Assert.AreEqual(expectedItems.ToArray(), items);
        }