public void GetAllSuperMarketsFromDbTest() { DataBase dataBase = Substitute.For <DataBase>(); //Assign Random rnd = new Random(1); int expected = rnd.Next(1000); List <Supermarket> superMarkets = new List <Supermarket>(); for (int i = 0; i < expected; i++) { Supermarket sm = new Supermarket() { Id = i, Name = "Supermarket " + i }; superMarkets.Add(sm); } dataBase.GetAllSuperMarkets().Returns(superMarkets); SmartShopLogics bs = new SmartShopLogics(dataBase); expected = superMarkets.Count; //act int actual = bs.GetAllSuperMarkets().Count; //assert Assert.IsTrue(expected == actual, String.Format("Got unexpected number of superMarkets ({0} instead of {1}", actual, expected)); }
public ClientForm() { InitializeComponent(); this._logicsService = new SmartShopLogics(); this.GetDbItems(); this.BindSuperMarkets(); this.BindCategories(); this.BindProducts(); this.SetAllCategoriesdCheckState(true); this.MatchGuiToUserType(); //this.SetIcon(); }
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); }
private void InitSessionVariables() { var logics = new SmartShopLogics(); Application[SessionKeys.LOGICS] = logics; }