/// <summary> /// Creates the data base objects for varois tests... /// </summary> /// <param name="superMarket">The out argument for superMarket.</param> /// <param name="categories">The out argument for categories.</param> /// <param name="products">The out argument for products.</param> private static void CreateDataBaseObjects(out Supermarket superMarket, out List <Category> categories, out List <Product> products) { superMarket = new Supermarket() { Name = "SuperMarket", Id = 1 }; #region Creating categories //vegtables Category vegetables = SmartShopLogicsTests.CreateCategory(superMarket, "vegetables", 1); //dairy Category dairy = SmartShopLogicsTests.CreateCategory(superMarket, "dairy", 5); //bakery Category bakery = SmartShopLogicsTests.CreateCategory(superMarket, "bakery", 9); categories = new List <Category> { vegetables, dairy, bakery }; #endregion products = new List <Product> { #region Creating products new Product { ProductName = "Bread", Category = bakery }, new Product { ProductName = "Milk", Category = dairy }, new Product { ProductName = "Pita", Category = bakery }, new Product { ProductName = "Tomato", Category = vegetables }, new Product { ProductName = "Onion", Category = vegetables }, new Product { ProductName = "Cream", Category = dairy } #endregion }; }
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; } }
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); }