private void CheckProduct(Product product,User user) { ICategoryService categoryService = new CategoryService(); IProductService productService = new ProductService(); IConfiguration configuration = ConfigurationService.GetInstance(); ICollection<Category> categorys = categoryService.GetCategorysForAProduct(product); int nrOfAuctions = 0; foreach(Category category in categorys) { ICollection<Category> parentCAtegorys = categoryService.getParents(category.IdCategory); ICollection<Product> products; foreach(Category parentCategory in parentCAtegorys) { products = productService.GetAllProductsOfACategory(category); foreach(Product productCat in products) { Auction auction = productService.GetAuctionOfAProduct(productCat); if (auction != null && auction.User.Equals(user)) nrOfAuctions++; } } } if(nrOfAuctions >= configuration.GetValue(Constants.MAX_NR_OF_AUCTION_ASSOCIATE_WITH_CATEGORY)) throw new AuctionException("The auction can not be added because the number of auctions per category was exceeded"); }
public void GetProductsOfACategory() { CategoryService categoryService = new CategoryService(); ProductService productService = new ProductService(); Category category = categoryService.GetCategoryById(8); ICollection<Product> products = productService.GetAllProductsOfACategory(category); Assert.AreEqual(products.Count(), 2); }