public void LookupByCuisineTest() { Ingredient a = new Ingredient("name1", "description1", 123, "gr"); Ingredient b = new Ingredient("name2", "description2", 456, "kg"); Recipe food = new Recipe( "kabab", "charkh karde", new Ingredient[] { a }, 3, "irani", new string[] { "irani", "kabab" } ); Recipe food1 = new Recipe( "joje", "kabab karde", new Ingredient[] { b }, 2, "irani", new string[] { "irani", "joje" } ); RecipeBook book = new RecipeBook("recipeBook", 2); book.Add(food); book.Add(food1); Assert.IsTrue(new Recipe[] { food, food1 }.SequenceEqual(book.LookupByCuisine("irani"))); }
/// <summary> /// searches in recipes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnSearch_Click(object sender, RoutedEventArgs e) { try { switch (SearchKind.Text) { case "Title": RecipeListBox.Items.Clear(); ListBoxItem item = new ListBoxItem(); item.Content = recipeBook.LookupByTitle(SearchTextBox.Text).Title; RecipeListBox.Items.Add(item); break; case "Keyword": RecipeListBox.Items.Clear(); Recipe[] recipeSearchByKeyword; recipeSearchByKeyword = recipeBook.LookupByKeyword(SearchTextBox.Text); for (int i = 0; i < recipeSearchByKeyword.Length && recipeSearchByKeyword[i] != null; i++) { ListBoxItem items = new ListBoxItem(); items.Content = recipeSearchByKeyword[i].Title; RecipeListBox.Items.Add(items); } break; case "Cuisine": RecipeListBox.Items.Clear(); Recipe[] recipeSearchByCuisine; recipeSearchByCuisine = recipeBook.LookupByCuisine(SearchTextBox.Text); for (int i = 0; i < recipeSearchByCuisine.Length && recipeSearchByCuisine[i] != null; i++) { ListBoxItem items = new ListBoxItem(); items.Content = recipeSearchByCuisine[i].Title; RecipeListBox.Items.Add(items); } break; default: MessageBox.Show("How do you want to search?"); break; } } catch (NullReferenceException) { MessageBox.Show("Please try again!"); } }
public void LookupByCuisineTest() { recipeBook.Add(recipe); CollectionAssert.Contains(recipeBook.LookupByCuisine("iranian"), recipe); }