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)); }
/// <summary> /// Initializes a new instance of the <see cref="ProdcutForm"/> class. /// </summary> private ProductForm(Product product, IEnumerable<Category> categories, Supermarket superMarket) { InitializeComponent(); this._superMarket = superMarket; this.Categories = categories; this.Product = product; }
/// <summary> /// Gets the sort by super market. /// </summary> /// <param name="superMarket">The super market.</param> /// <returns>the sort</returns> public CategorySort GetSortBySuperMarket(Supermarket superMarket) { return(this.CategorySorts.FirstOrDefault(cs => cs.SupermarketId == superMarket.Id) ?? new CategorySortNullObject()); }
/// <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 }; }
/// <summary> /// Creates a category. /// </summary> /// <param name="supermarket">The Supermarket that the category sort will be for.</param> /// <param name="catName">Name of the category.</param> /// <param name="sortValue">The sort value for category.</param> /// <returns>the category with a sort value for specified supermarket</returns> private static Category CreateCategory(Supermarket supermarket, string catName, int sortValue) { //creating the category Category cat = new Category() { Name = catName }; //creating the sort CategorySort catSort = new CategorySort() { Category = cat, Supermarket = supermarket, SortValue = sortValue, SupermarketId = supermarket.Id }; //assigning the sort cat.CategorySorts.Add(catSort); return cat; }
/// <summary> /// Gets a ceeate product form instance. /// </summary> /// <param name="categories">The categories.</param> /// <returns></returns> internal static ProductForm GetCreateProductInstance(IEnumerable<Category> categories, Supermarket superMarket) { return new ProductForm(null, categories, superMarket); }
/// <summary> /// Gets an edit product form instance. /// </summary> /// <param name="product">The product.</param> /// <param name="categories">The categories.</param> /// <returns></returns> internal static ProductForm GetEditProductInstance(Product product, IEnumerable<Category> categories, Supermarket superMarket) { return new ProductForm(product, categories, superMarket); }
/// <summary> /// Gets the sort by super market. /// </summary> /// <param name="superMarket">The super market.</param> /// <returns>the sort</returns> public CategorySort GetSortBySuperMarket(Supermarket superMarket) { return this.CategorySorts.FirstOrDefault(cs => cs.SupermarketId == superMarket.Id) ?? new CategorySortNullObject(); }
/// <summary> /// Gets an edit category form instance. /// </summary> /// <param name="category">The Category.</param> /// <param name="categories">The categories.</param> /// <returns></returns> internal static CategoryForm GetEditCategoryInstance(Category category, Supermarket superMarket) { return new CategoryForm(category, superMarket); }
/// <summary> /// Gets a ceeate category form instance. /// </summary> /// <param name="categories">The categories.</param> /// <returns></returns> internal static CategoryForm GetCreateCategoryInstance(Supermarket superMarket) { return new CategoryForm(null,superMarket); }
/// <summary> /// Initializes a new instance of the <see cref="ProdcutForm"/> class. /// </summary> private CategoryForm(Category category, Supermarket superMarket) { InitializeComponent(); this._superMarket = superMarket; this.Category = category ?? new CategoryNullObject(); }
public ShopList GetShoppingList(Dictionary<Product, int> quantityByProduct, Supermarket market, Customer customer) { ShopList list = new ShopList(); foreach (var pair in quantityByProduct) { var product = pair.Key; var quantity = pair.Value; ShoplistItem item = new ShoplistItem(); item.Product = product; item.ProductId = product.Id; item.Quantity = quantity; item.ShopList = list; list.ShoplistItems.Add(item); } if (market == null) { var markets = this.GetAllSuperMarkets(); market = markets[0]; } list.Supermarket = market; list.SuperMarketId = market.Id; return this.GetSortedList(list,customer); }