Ejemplo n.º 1
0
        public void Try_To_Get_Purchasable_Items_Number_In_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            Assert.That(catalogue.ItemsThatCanBeBought(item, 100).Equals(0));
        }
Ejemplo n.º 2
0
        public void Get_Price_Of_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            decimal    price     = catalogue.GetPriceOfFullCatalogue();

            Assert.That(price.Equals(0));
        }
Ejemplo n.º 3
0
        public void Add_Item_To_Existing_Catalogue()
        {
            ICatalogueItem        item1 = new FakeCatalogueItem1();
            ICatalogueItem        item2 = new FakeCatalogueItem1();
            ICatalogueItem        item3 = new FakeCatalogueItem1();
            List <ICatalogueItem> items = new List <ICatalogueItem>()
            {
                item1, item2, item3
            };
            IItem fakeItem1 = new FakeItem();

            item1.Add(fakeItem1);

            IVendingMachineInternal fakeMachine = new FakeVendingMachine();
            ICatalogue catalogue = new SimpleCatalogue();

            catalogue.Init(fakeMachine);
            catalogue.Setup(items);


            IItem fakeItem2 = new FakeItem();

            catalogue.AddItem(fakeItem2);

            Assert.That(catalogue.ContainsItem(fakeItem2).Equals(true));
        }
Ejemplo n.º 4
0
        public void Try_To_Get_Items_That_Can_Be_Bought_From_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            Assert.That(catalogue.ItemsThatCanBeBought(item, 100).Equals(0));
        }
Ejemplo n.º 5
0
        public void Try_To_Get_Items_That_Can_Be_Bought_By_Index_From_Catalogue_Not_Having_It()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItem();

            catalogue.AddItem(item);
            Assert.That(catalogue.ItemsThatCanBeBought(1, 100).Equals(0));
        }
Ejemplo n.º 6
0
        public void Get_Price_Of_Items_In_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem1 = new FakeItemWithPrice();
            decimal    price     = catalogue.GetPriceOfAllItemsOfType(fakeItem1);

            Assert.That(price.Equals(0));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public void Subtract_Group_Of_Items_By_Index_From_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            var        exception = Assert.Throws <ItemMismatchException>(() =>
            {
                catalogue.SubtractItems(2, 200);
            });

            Assert.That(exception.GetType() == typeof(ItemMismatchException));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        public void Get_Price_Of_Index_In_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItemWithPrice();

            catalogue.AddItem(item);
            decimal price = catalogue.GetPriceOfItem(0);

            Assert.That(price.Equals(item.Price));
        }
Ejemplo n.º 11
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));
        }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
0
        public void Get_Price_Of_Index_Quantity_From_Empty_Catalogue()
        {
            ICatalogue catalogue = new SimpleCatalogue();

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

            Assert.That(exception.GetType() == typeof(EmptyContainerException));
        }
Ejemplo n.º 14
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));
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
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));
        }
Ejemplo n.º 17
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));
        }
Ejemplo n.º 18
0
        public void Get_Price_Of_Filled_Catalogue(int amount, decimal finalPrice)
        {
            ICatalogue catalogue = new SimpleCatalogue();

            for (int i = 0; i < amount; i++)
            {
                IItem fakeItem = new FakeItemWithPrice();
                catalogue.AddItem(fakeItem);
            }
            decimal price = catalogue.GetPriceOfFullCatalogue();

            Assert.That(price.Equals(finalPrice));
        }
Ejemplo n.º 19
0
        public void Get_Existing_Items_That_Can_Be_Bought(int initialAmount, decimal amount, int purchasableAmount)
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      fakeItem  = new FakeItemWithPrice();

            for (int i = 0; i < initialAmount; i++)
            {
                catalogue.AddItem(fakeItem);
            }
            int canBePurchased = catalogue.ItemsThatCanBeBought(fakeItem, amount);

            Assert.That(canBePurchased.Equals(purchasableAmount));
        }
Ejemplo n.º 20
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));
        }
Ejemplo n.º 21
0
        public void Get_Price_Of_Item_Quantity_In_Catalogue(int initialQuantity, int quantity, decimal price)
        {
            ICatalogue catalogue = new SimpleCatalogue();
            IItem      item      = new FakeItemWithPrice();

            for (int i = 0; i < initialQuantity; i++)
            {
                catalogue.AddItem(item);
            }
            decimal priceUnderTest = catalogue.GetPriceOfItem(item, quantity);

            Assert.That(price.Equals(priceUnderTest));
        }
Ejemplo n.º 22
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));
        }
Ejemplo n.º 23
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));
        }
Ejemplo n.º 24
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));
        }
Ejemplo n.º 25
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));
        }
Ejemplo n.º 26
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));
        }
Ejemplo n.º 27
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));
        }
Ejemplo n.º 28
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));
        }
Ejemplo n.º 29
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));
        }
Ejemplo n.º 30
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));
        }
        public List<SimpleCatalogue> SearchCatalogue(SearchBookDTO dto)
        {
            SimpleCatalogue scob;
            List<SimpleCatalogue> list = new List<SimpleCatalogue>();
            try
            {
                SqlDataReader reader = ConnectionManager.GetCommand("sp0001catalogue",
                                                                    new Dictionary<string, SqlDbType>()
                                                                        {
                                                                            {"@title", SqlDbType.NVarChar}
                                                                        },
                                                                    new List<object>()
                                                                        {
                                                                            dto.Info1
                                                                        }).
                    ExecuteReader();
                while (reader.Read())
                {
                    scob = new SimpleCatalogue();
                    scob.ISBN = reader["ISBN"].ToString();
                    scob.Title = reader["Title"].ToString();
                    list.Add(scob);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                Log.Error("Error at SearchBooksDAO - SearchCatalogue", e);
                return null;
            }

            return list;
        }