Exemplo n.º 1
0
        public void Check_For_A_Non_Existent_Item_In_Non_Empty_Catalogue()
        {
            IItem           item1     = new FakeItem();
            IItem           item2     = new FakeItemWithPrice();
            SimpleCatalogue catalogue = new SimpleCatalogue();

            catalogue.AddItem(item1);
            Assert.That(catalogue.ContainsItem(item2).Equals(false));
        }
Exemplo n.º 2
0
        public void Try_To_Get_Purchasable_Items_Number_That_Are_Non_Existent_In_Non_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();
            IItem      item2     = new FakeItemWithPrice();

            catalogue.AddItem(item);

            Assert.That(catalogue.ItemsThatCanBeBought(item2, 100).Equals(0));
        }
Exemplo n.º 3
0
        public void Try_To_Get_Items_That_Can_Be_Bought_From_Catalogue_Not_Having_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            catalogue.AddItem(item);
            IItem item2 = new FakeItemWithPrice();

            Assert.That(catalogue.ItemsThatCanBeBought(item2, 100).Equals(0));
        }
Exemplo n.º 4
0
        public void Get_Items_Count_Of_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();
            var        exception = Assert.Throws <EmptyContainerException>(() =>
            {
                catalogue.GetItemsCount(item);
            });

            Assert.That(exception.GetType() == typeof(EmptyContainerException));
        }
Exemplo n.º 5
0
        public void Add_A_New_Catalogue_Item()
        {
            IItem item = new FakeItem();
            IVendingMachineInternal fakeMachine = new FakeVendingMachine();
            SimpleCatalogue         catalogue   = new SimpleCatalogue();

            catalogue.Init(fakeMachine);
            catalogue.AddItem(item);
            Console.WriteLine($"Catalogue count = {catalogue.GetCatalogueItems().Count}");
            Assert.That(catalogue.ContainsItem(item).Equals(true));
        }
Exemplo n.º 6
0
        public void Subtract_Group_Of_Items_From_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();
            var        exception = Assert.Throws <EmptyContainerException>(() =>
            {
                catalogue.SubtractItems(fakeItem, 200);
            });

            Assert.That(exception.GetType() == typeof(EmptyContainerException));
        }
Exemplo n.º 7
0
        public void Subtract_Item_From_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();
            var        exception = Assert.Throws <ItemMismatchException>(() =>
            {
                catalogue.SubtractItem(fakeItem);
            });

            Assert.That(exception.GetType() == typeof(ItemMismatchException));
        }
Exemplo n.º 8
0
        public void Get_Price_Of_Item_Quantity_From_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();

            var exception = Assert.Throws <EmptyContainerException>(() =>
            {
                catalogue.GetPriceOfItem(fakeItem, 100);
            });

            Assert.That(exception.GetType() == typeof(EmptyContainerException));
        }
Exemplo n.º 9
0
        public void Check_For_Item_in_Blank_Catalogue()
        {
            IItem           item      = new FakeItem();
            SimpleCatalogue catalogue = new SimpleCatalogue();
            FakeItem        fake      = new FakeItem();
            var             exception = Assert.Throws <EmptyContainerException>(() =>
            {
                catalogue.ContainsItem(fake);
            });

            Assert.That(exception.GetType() == typeof(EmptyContainerException));
        }
Exemplo n.º 10
0
        public void Subtract_Item_From_Catalogue_Containing_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();

            for (int i = 0; i < 100; i++)
            {
                catalogue.AddItem(fakeItem);
            }
            IItem fakeItem2 = catalogue.SubtractItem(fakeItem);

            Assert.That(fakeItem2.Equals(fakeItem));
        }
Exemplo n.º 11
0
        public void Subtract_Group_Of_Items_By_Index_From_The_Catalogue(int quantity, int subtractQuantity, int result)
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            for (int i = 0; i < quantity; i++)
            {
                catalogue.AddItem(item);
            }
            List <IItem> items = catalogue.SubtractItems(0, subtractQuantity);

            Assert.That(items.Count.Equals(result));
        }
Exemplo n.º 12
0
        public void Subtract_More_Items_By_Index_Than_There_Is_In_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            catalogue.AddItem(item);
            var exception = Assert.Throws <SubtractionFromLesserQuantityException>(() =>
            {
                catalogue.SubtractItems(0, 200);
            });

            Assert.That(exception.GetType() == typeof(SubtractionFromLesserQuantityException));
        }
Exemplo n.º 13
0
        public void Get_Items_Count_Of_Catalogue_Containing_It(int amount, int finalAmount)
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            for (int i = 0; i < amount; i++)
            {
                catalogue.AddItem(item);
            }
            int itemsCount = catalogue.GetItemsCount(item);

            Assert.That(itemsCount.Equals(finalAmount));
        }
Exemplo n.º 14
0
        public void Get_Items_Count_Of_Catalogue_Not_Containing_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();
            IItem      item2     = new FakeItemWithPrice();

            catalogue.AddItem(item);
            var exception = Assert.Throws <ItemMismatchException>(() =>
            {
                catalogue.GetItemsCount(item2);
            });

            Assert.That(exception.GetType() == typeof(ItemMismatchException));
        }
Exemplo n.º 15
0
        public void Subtract_Index_Greater_Than_Catalogue_Size()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();

            catalogue.AddItem(fakeItem);

            var exception = Assert.Throws <ItemNotFoundException>(() =>
            {
                catalogue.SubtractItem(10);
            });

            Assert.That(exception.GetType() == typeof(ItemNotFoundException));
        }
Exemplo n.º 16
0
        public void Subtract_Item_From_Catalogue_Not_Containing_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();

            catalogue.AddItem(fakeItem);
            IItem fakeItem2 = new FakeItemWithPrice();
            var   exception = Assert.Throws <ItemMismatchException>(() =>
            {
                catalogue.SubtractItem(fakeItem2);
            });

            Assert.That(exception.GetType() == typeof(ItemMismatchException));
        }
Exemplo n.º 17
0
        public void Get_Price_Of_Index_In_Catalogue_Not_Containing_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            catalogue.AddItem(item);

            var exception = Assert.Throws <ItemNotFoundException>(() =>
            {
                catalogue.GetPriceOfItem(1);
            });

            Assert.That(exception.GetType() == typeof(ItemNotFoundException));
        }
Exemplo n.º 18
0
        public void Get_Price_Of_Index_Quantity_In_Catalogue_More_Than_Actual_Quantity()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            catalogue.AddItem(item);

            var exception = Assert.Throws <ItemNotFoundException>(() =>
            {
                catalogue.GetPriceOfItem(0, 100);
            });

            Assert.That(exception.GetType() == typeof(ItemNotFoundException));
        }
Exemplo n.º 19
0
        public void Get_Item_Index_From_Catalogue_Containing_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            catalogue.AddItem(item);
            IItem item2 = new FakeItemWithPrice();

            catalogue.AddItem(item2);

            int index = catalogue.GetItemIndex(item2);

            Assert.That(index.Equals(1));
        }
Exemplo n.º 20
0
        public void Subtract_Valid_index_From_A_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();
            IItem      fakeItem2 = new FakeItemWithPrice();

            for (int i = 0; i < 100; i++)
            {
                catalogue.AddItem(fakeItem);
                catalogue.AddItem(fakeItem2);
            }

            IItem fakeItemResult = catalogue.SubtractItem(1);

            Assert.That(fakeItemResult.Equals(fakeItem2));
        }
Exemplo n.º 21
0
        public void Get_Price_Of_All_Items_Of_A_Type_In_A_Catalogue_With_Multiple_Type_Of_Objects(int initialAmount, decimal finalPrice)
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem1 = new FakeItemWithPrice();

            for (int i = 0; i < initialAmount; i++)
            {
                catalogue.AddItem(fakeItem1);
            }
            IItem fakeItem2 = new FakeItem();

            catalogue.AddItem(fakeItem2);
            decimal price = catalogue.GetPriceOfAllItemsOfType(fakeItem1);

            Assert.That(price.Equals(finalPrice));
        }
Exemplo n.º 22
0
        public void Subtract_Group_Of_Items_By_Index_Actually_Removes_Them_From_Catalogue(int quantity, int subtractQuantity, int result)
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            for (int i = 0; i < quantity; i++)
            {
                catalogue.AddItem(item);
            }

            int          itemCount    = catalogue.GetItemsCount(item);
            List <IItem> items        = catalogue.SubtractItems(0, subtractQuantity);
            int          itemCountNew = catalogue.GetItemsCount(item);
            int          difference   = itemCount - itemCountNew;

            Assert.That(difference.Equals(result));
        }
Exemplo n.º 23
0
        public void Subtract_Group_Of_Items_From_Catalogue_Which_Does_Not_Have_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();
            IItem      fakeItem2 = new FakeItemWithPrice();

            for (int i = 0; i < 100; i++)
            {
                catalogue.AddItem(fakeItem);
            }
            var exception = Assert.Throws <ItemMismatchException>(() =>
            {
                catalogue.SubtractItems(fakeItem2, 200);
            });

            Assert.That(exception.GetType() == typeof(ItemMismatchException));
        }
Exemplo n.º 24
0
        public void Subtract_More_Items_From_Catalogue_Than_It_Has()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();
            IItem      fakeItem2 = new FakeItemWithPrice();

            for (int i = 0; i < 100; i++)
            {
                catalogue.AddItem(fakeItem2);
            }
            var exception = Assert.Throws <SubtractionFromLesserQuantityException>(() =>
            {
                catalogue.SubtractItems(fakeItem2, 200);
            });

            Assert.That(exception.GetType() == typeof(SubtractionFromLesserQuantityException));
        }
Exemplo n.º 25
0
        public void Check_If_Subtraction_Actually_Remove_Item_From_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItem();
            IItem      fakeItem2 = new FakeItemWithPrice();

            for (int i = 0; i < 100; i++)
            {
                catalogue.AddItem(fakeItem);
                catalogue.AddItem(fakeItem2);
            }

            int itemsCount = catalogue.GetItemsCount(fakeItem2);

            catalogue.SubtractItem(1);
            int newItemsCount = catalogue.GetItemsCount(fakeItem2);
            int difference    = itemsCount - newItemsCount;

            Assert.That(difference.Equals(1));
        }