public void TestSearchGetAllCategoryNames() { //Arrange IEnumerable <string> allCategoryNames = null; //Arrange const string nodeName = "TheNoodle"; const string catName = "TheCat.CatSon";//This will create a Category and Subcategory const string descr = "TheCat"; const string path = @"C:\temp\graphics.dyn"; var guid1 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var dummySearch1 = new CustomNodeSearchElementTest(null, dummyInfo1); var searchLibrary = new SearchLibrary <NodeSearchElement, NodeModel>(); searchLibrary.Add(dummySearch1); //Act var root = SearchCategoryUtil.CategorizeSearchEntries( searchLibrary.SearchEntries, entry => entry.Categories); foreach (var category in root.SubCategories) { allCategoryNames = SearchCategoryUtil.GetAllCategoryNames(category); } //Assert //Just validate that search entries is not null Assert.IsNotNull(root); //Validate that the GetAllCategoryNames returned at least one element Assert.Greater(allCategoryNames.Count(), 0); }
public void CanDuplicateAddedNodesInBrowser() { const string catName = "Category.Child.Thing.That"; const string nodeName = "what is this"; for (var i = 0; i < 100; i++) { search.Add( new CustomNodeSearchElement( null, new CustomNodeInfo(Guid.NewGuid(), nodeName, catName, "des", ""))); } var categorized = SearchCategoryUtil.CategorizeSearchEntries(search.SearchEntries, x => x.Categories); Assert.AreEqual(1, categorized.SubCategories.Count()); categorized = categorized.SubCategories.First(); Assert.AreEqual("Category", categorized.Name); Assert.AreEqual(1, categorized.SubCategories.Count()); categorized = categorized.SubCategories.First(); Assert.AreEqual("Child", categorized.Name); Assert.AreEqual(1, categorized.SubCategories.Count()); categorized = categorized.SubCategories.First(); Assert.AreEqual("Thing", categorized.Name); Assert.AreEqual(1, categorized.SubCategories.Count()); categorized = categorized.SubCategories.First(); Assert.AreEqual("That", categorized.Name); Assert.AreEqual(0, categorized.SubCategories.Count()); Assert.AreEqual(100, categorized.Entries.Count()); Assert.AreEqual(nodeName, categorized.Entries.First().Name); }
/// <summary> /// Presents the function name dialogue. Returns true if the user enters /// a function name and category. /// </summary> /// <param name="name"></param> /// <param name="category"></param> /// <returns></returns> public void ShowNewFunctionDialog(FunctionNamePromptEventArgs e) { string error = ""; do { var categorized = SearchCategoryUtil.CategorizeSearchEntries( dynamoViewModel.Model.SearchModel.SearchEntries, entry => entry.Categories); var allCategories = categorized.SubCategories.SelectMany(sub => sub.GetAllCategoryNames()); var dialog = new FunctionNamePrompt(allCategories) { categoryBox = { Text = e.Category }, DescriptionInput = { Text = e.Description }, nameView = { Text = e.Name }, nameBox = { Text = e.Name }, // center the prompt Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner }; if (e.CanEditName) { dialog.nameBox.Visibility = Visibility.Visible; dialog.nameView.Visibility = Visibility.Collapsed; } else { dialog.nameView.Visibility = Visibility.Visible; dialog.nameBox.Visibility = Visibility.Collapsed; } if (dialog.ShowDialog() != true) { e.Success = false; return; } if (String.IsNullOrEmpty(dialog.Text)) { MessageBox.Show(Dynamo.Wpf.Properties.Resources.MessageCustomNodeNoName, Dynamo.Wpf.Properties.Resources.CustomNodePropertyErrorMessageBoxTitle, MessageBoxButton.OK, MessageBoxImage.Error); } //else if (e.Name != dialog.Text && dynamoViewModel.Model.BuiltInTypesByNickname.ContainsKey(dialog.Text)) //{ // error = "A built-in node with the given name already exists."; // MessageBox.Show(error, "Custom Node Property Error", MessageBoxButton.OK, // MessageBoxImage.Error); //} else if (dialog.Category.Equals("")) { MessageBox.Show(Dynamo.Wpf.Properties.Resources.MessageCustomNodeNeedNewCategory, Dynamo.Wpf.Properties.Resources.CustomNodePropertyErrorMessageBoxTitle, MessageBoxButton.OK, MessageBoxImage.Error); } else { error = ""; } e.Name = dialog.Text; e.Category = dialog.Category; e.Description = dialog.Description; } while (!error.Equals("")); e.Success = true; }