public void FindAppleSourCream() { string[] dataSource = { "dog donkey apple monkey sour", "this planet sour goat", "here is the sour cream" }; string[] query = { "apple", "sour cream" }; bool finder = StringSearcher.StringArrayAndSearch(dataSource, query); Assert.IsTrue(finder); }
private void btnSearch_Click(object sender, RoutedEventArgs e) { try { GenericSearch.MainWindow dialog = new GenericSearch.MainWindow(); if (dialog.ShowDialog() == true) { recipeListBox.SelectedItem = null; searchTerms = dialog.SearchTerms; ClearFields(); //Take a list of recipes, and for each create an array of string from its fields (and ingredients), then search it using the searchTerms, //if the result is true than add it to a List and set the recipes listbox datacontext to the new list. List <Recipe> foundRecipes = new List <Recipe>(); foreach (Recipe r in context.Recipes) { string[] recipeFields = context.RecipeFields(r); if (StringSearcher.StringArrayAndSearch(recipeFields, searchTerms)) { foundRecipes.Add(r); } } //If no recipes were found then inform user in the error lable. if (foundRecipes.Count > 0) { recipeListBox.SelectedItem = null; foundRecipes.Sort(); recipeListBox.DataContext = foundRecipes; } else { recipeListBox.DataContext = foundRecipes; errorLabel.Content = "No recipes were found matching your requirements."; } } } catch (Exception ex) { var baseexception = ex.GetBaseException(); errorLabel.Content = baseexception.Message; } }