예제 #1
0
        public void SortedGivenShopListTest()
        {
            //Assign
            Supermarket     sm;
            List <Category> categories;
            List <Product>  products;

            SmartShopLogicsTests.CreateDataBaseObjects(out sm, out categories, out products);

            ShopList list = new ShopList();

            #region Populating shopping list
            list.Supermarket   = sm;
            list.SuperMarketId = sm.Id;
            for (int i = 0; i < products.Count; i++)
            {
                Product      currProduct = products[i];
                ShoplistItem newItem     = new ShoplistItem()
                {
                    Product = currProduct, Quantity = i, ShopList = list
                };
                list.ShoplistItems.Add(newItem);
            }
            #endregion


            //act
            DataBase        dataBase = Substitute.For <DataBase>();
            SmartShopLogics bs       = new SmartShopLogics(dataBase);
            ShopList        sorted   = bs.GetSortedList(list, null);

            //assert
            int lastCategoryId = -1;
            for (int i = 0; i < sorted.ShoplistItems.Count; i++)
            {
                List <ShoplistItem> items = sorted.ShoplistItems.ToList();
                int currCategory          = items[i].Product.Category.CategorySorts.Where(cat => cat.Supermarket == sm).SingleOrDefault().SortValue;
                //If list is sorted, the sort value should always increase
                Assert.IsTrue(currCategory >= lastCategoryId, "Shopping list was not sorted properly ({0} sort value came before {1})", lastCategoryId, currCategory);
                lastCategoryId = currCategory;
            }
        }
예제 #2
0
        public void GetAllCategoriesFromDbTest()
        {
            DataBase dataBase = Substitute.For <DataBase>();

            //Assign
            Supermarket     sm;
            List <Category> categories;
            List <Product>  products;

            SmartShopLogicsTests.CreateDataBaseObjects(out sm, out categories, out products);

            dataBase.GetAllCategories().Returns(categories);
            SmartShopLogics bs = new SmartShopLogics(dataBase);

            int expected = categories.Count;

            //act
            int actual = bs.GetAllCategories().Count;

            //assert
            Assert.IsTrue(expected == actual, "Got unexpected number of categories ({0} instead of {1})", actual, expected);
        }