public void CanRemoveSingleCustomNodeByIdWhereThereAreDuplicatesWithDifferentIds() { const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; const string path = @"C:\turtle\graphics.dyn"; var guid1 = Guid.NewGuid(); var guid2 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1); var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path); var dummySearch2 = new CustomNodeSearchElement(null, dummyInfo2); search.Add(dummySearch1); search.Add(dummySearch2); Assert.AreEqual(2, search.NumElements); search.Remove(dummySearch2); Assert.AreEqual(1, search.NumElements); var results = search.Search(nodeName).ToList(); Assert.AreEqual(1, results.Count()); var res1 = results[0]; Assert.IsInstanceOf <CustomNodeSearchElement>(res1); var node1 = (CustomNodeSearchElement)res1; Assert.AreEqual(node1.ID, guid1); }
public void TestSearchTryLoadDocumentationCustom() { //Arrange string path = Path.Combine(TestDirectory, @"core\CustomNodes\CNDefault.dyf"); const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; var guid1 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var moq = new Mock <ICustomNodeSource>(); var dummySearch1 = new CustomNodeSearchElement(moq.Object, dummyInfo1); //Act //Execute the GenerateInputParameters() method List <Tuple <string, string> > inputParameters = dummySearch1.InputParameters as List <Tuple <string, string> >; //Execute the GenerateOutputParameters() method List <string> outputParameters = dummySearch1.OutputParameters as List <string>; dummySearch1.ProduceNode(); //Assert //It just validates that the parameters is not null and has at least one element in the list Assert.IsNotNull(inputParameters); Assert.Greater(inputParameters.Count, 0); Assert.IsNotNull(outputParameters); Assert.Greater(outputParameters.Count, 0); }
public void CanAddDuplicateCustomNodeWithDifferentGuidsAndGetBothInResults() { const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; const string path = @"C:\turtle\graphics.dyn"; var guid1 = Guid.NewGuid(); var guid2 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1); var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path); var dummySearch2 = new CustomNodeSearchElement(null, dummyInfo2); search.Add(dummySearch1); search.Add(dummySearch2); Assert.AreEqual(2, search.NumElements); var results = search.Search(nodeName).ToList(); Assert.AreEqual(2, results.Count()); var resultIds = results.Cast <CustomNodeSearchElement>().Select(x => x.ID).ToList(); Assert.IsTrue(resultIds.Contains(guid1)); Assert.IsTrue(resultIds.Contains(guid2)); }
public void CustomNodePropertiesWindowValidateCategories() { // sample CN #1 var CN1_Info = new CustomNodeInfo( Guid.NewGuid(), "category test node 1", "base.level1.level2.level3", "A node for testing CN dialog categories drop - down", @"C:\temp\category_test_node_1.dyf"); // sample CN #2 var CN2_Info = new CustomNodeInfo( Guid.NewGuid(), "category test node 2", "base.level1.level2.level3.level4.level5", "A node for testing CN dialog categories drop - down", @"C:\temp\category_test_node_2.dyf"); var CN1_Mock = new Mock <ICustomNodeSource>(); var CN2_Mock = new Mock <ICustomNodeSource>(); var CN1_element = new CustomNodeSearchElement(CN1_Mock.Object, CN1_Info); var CN2_element = new CustomNodeSearchElement(CN2_Mock.Object, CN2_Info); var provider = new NodeItemDataProvider(new NodeSearchModel()); var CN1_LoadedType = provider.CreateLoadedTypeItem <LoadedTypeItem>(CN1_element); var CN2_LoadedType = provider.CreateLoadedTypeItem <LoadedTypeItem>(CN2_element); var elements = new NodeSearchElement[] { CN1_element, CN2_element }; // Call function used to populate Add-ons categories drop-down in CN properties window List <string> addOnCategories = Dynamo.Controls.DynamoView.getUniqueAddOnCategories(elements).ToList(); // Expected results var CN1_expectedQualifiedName = "dyf://base.level1.level2.level3.category test node 1"; var CN2_expectedQualifiedName = "dyf://base.level1.level2.level3.level4.level5.category test node 2"; // Expected unique categories that will be populated for the drop-down in the function above string[] expectedCategories = new string[] { "base", "base.level1", "base.level1.level2", "base.level1.level2.level3", "base.level1.level2.level3.level4", "base.level1.level2.level3.level4.level5" // Should not include node names at bottom levels }; // Verify expected results Assert.AreEqual(CN1_expectedQualifiedName, CN1_LoadedType.fullyQualifiedName); Assert.AreEqual(CN2_expectedQualifiedName, CN2_LoadedType.fullyQualifiedName); Assert.AreEqual(addOnCategories.Count, expectedCategories.Length); for (int i = 0; i < addOnCategories.Count; i++) { Assert.AreEqual(addOnCategories[i], expectedCategories[i]); } }
private static NodeSearchElement CreateCustomNode(string name, string category, string description = "", string path = "") { var element = new CustomNodeSearchElement(null, new CustomNodeInfo(Guid.NewGuid(), name, category, description, path)); return(element); }
public void CanRefactorCustomNodeWhilePreservingDuplicates() { const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; const string path = @"C:\turtle\graphics.dyn"; var guid1 = Guid.NewGuid(); var guid2 = Guid.NewGuid(); //all properties are the same except guid. var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path); var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1); var dummySearch2 = new CustomNodeSearchElement(null, dummyInfo2); search.Add(dummySearch1); search.Add(dummySearch2); Assert.AreEqual(2, search.NumElements); // refactor one of the nodes with newNodeName const string newNodeName = "TheTurtle"; var newInfo = new CustomNodeInfo(guid1, newNodeName, catName, descr, path); dummySearch1.SyncWithCustomNodeInfo(newInfo); search.Update(dummySearch1); // num elements is unchanged Assert.AreEqual(2, search.NumElements); // search for new name var results = search.Search(newNodeName).ToList(); // results are correct - only one result Assert.AreEqual(1, results.Count()); var res1 = results[0]; Assert.IsInstanceOf <CustomNodeSearchElement>(res1); Assert.AreSame(dummySearch1, res1); // search for old name results = search.Search(nodeName).ToList(); // results are correct - the first nodes are returned Assert.AreEqual(1, results.Count()); var res2 = results[0]; Assert.IsInstanceOf <CustomNodeSearchElement>(res2); Assert.AreSame(dummySearch2, res2); }
public bool Add(CustomNodeInfo nodeInfo) { var nodeEle = new CustomNodeSearchElement(nodeInfo); if (SearchDictionary.Contains(nodeEle)) { return(this.Refactor(nodeInfo)); } SearchDictionary.Add(nodeEle, nodeEle.Name); SearchDictionary.Add(nodeEle, nodeInfo.Category + "." + nodeEle.Name); TryAddCategoryAndItem(nodeInfo.Category, nodeEle); return(true); }
public void CanRemoveElementCustomNodeByNameWithSingleCategory() { var element = new CustomNodeSearchElement( null, new CustomNodeInfo(Guid.NewGuid(), "Peter", "Greens", "des", "")); search.Add(element); var results = search.Search("Peter"); Assert.AreEqual(1, results.Count()); search.Remove(element); results = search.Search("Peter"); Assert.AreEqual(0, results.Count()); }
public void CanRefactorCustomNodeDescription() { const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; const string path = @"C:\turtle\graphics.dyn"; var guid1 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1); search.Add(dummySearch1); Assert.AreEqual(1, search.NumElements); // search for name var results = search.Search(nodeName).ToList(); // results are correct Assert.AreEqual(1, results.Count()); var res1 = results[0]; Assert.IsInstanceOf <CustomNodeSearchElement>(res1); Assert.AreEqual(guid1, ((CustomNodeSearchElement)res1).ID); // refactor description const string newDescription = "Tickle me elmo"; var newInfo = new CustomNodeInfo(guid1, nodeName, catName, newDescription, path); dummySearch1.SyncWithCustomNodeInfo(newInfo); search.Update(dummySearch1); // num elements is unchanged Assert.AreEqual(1, search.NumElements); // search for name var results1 = search.Search(nodeName).ToList(); // description is updated Assert.AreEqual(1, results1.Count()); var res2 = results1[0]; Assert.IsInstanceOf <CustomNodeSearchElement>(res2); Assert.AreEqual(guid1, ((CustomNodeSearchElement)res2).ID); Assert.AreEqual(newDescription, res2.Description); }
/// <summary> /// Helper method for custom node adding and removing /// </summary> public static void AssertAddAndRemoveCustomNode( NodeSearchModel searchModel, string nodeName, string catName, string descr = "Bla", string path = "Bla") { var dummyInfo = new CustomNodeInfo(Guid.NewGuid(), nodeName, catName, descr, path); var dummySearch = new CustomNodeSearchElement(null, dummyInfo); searchModel.Add(dummySearch); var res = searchModel.Search(nodeName).ToList(); Assert.AreNotEqual(0, res.Count()); Assert.AreEqual(res[0].Name, nodeName); searchModel.Remove(dummySearch); res = searchModel.Search(nodeName).ToList(); Assert.AreEqual(0, res.Count()); }
private void ExecuteElement(CustomNodeSearchElement element) { string name = element.Guid.ToString(); // create node var guid = Guid.NewGuid(); dynamoViewModel.ExecuteCommand( new DynamoModel.CreateNodeCommand(guid, name, 0, 0, true, true)); // select node var placedNode = dynamoViewModel.Model.Nodes.Find((node) => node.GUID == guid); if (placedNode != null) { DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(placedNode); } }
public void TestSearchConstructNewNodeModel() { //Arrange const string nodeName = "TheNoodle"; const string catName = "TheCat"; 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 moq = new Mock <ICustomNodeSource>(); var dummySearch1 = new CustomNodeSearchElement(moq.Object, dummyInfo1); //Act var nodeCreated = dummySearch1.CreateNode(); //Assert //We are using a Mock for the customNodeManager parameter passed to CustomNodeSearchElement constructor then it will be null Assert.IsNull(nodeCreated); }
public void TestSearchTryLoadDocumentationException() { //Arrange const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; string path = Path.Combine(TestDirectory, @"core\DoesntExists.dyn");//This dyn file doesn't exist var guid1 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var moq = new Mock <ICustomNodeSource>(); var dummySearch1 = new CustomNodeSearchElement(moq.Object, dummyInfo1); //Act //It generates an exception because the dyn file doesn't exists, the exception is not re-thrown List <Tuple <string, string> > parameters = dummySearch1.InputParameters as List <Tuple <string, string> >; //Assert //It just validates that the parameters is not null and has at least one element in the list Assert.IsNotNull(parameters); Assert.Greater(parameters.Count, 0); }
public void CanRefactorCustomNodeName() { const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; const string path = @"C:\turtle\graphics.dyn"; var guid1 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1); search.Add(dummySearch1); Assert.AreEqual(1, search.NumElements); const string newNodeName = "TheTurtle"; var newInfo = new CustomNodeInfo(guid1, newNodeName, catName, descr, path); dummySearch1.SyncWithCustomNodeInfo(newInfo); search.Update(dummySearch1); Assert.AreEqual(1, search.NumElements); // search for new name var results = search.Search(newNodeName).ToList(); // results are correct Assert.AreEqual(1, results.Count()); var res1 = results[0]; Assert.IsInstanceOf <CustomNodeSearchElement>(res1); Assert.AreEqual(guid1, ((CustomNodeSearchElement)res1).ID); // search for old name var results1 = search.Search(nodeName); // results are correct Assert.AreEqual(0, results1.Count()); }
public void CustomNodeSearchElementLoadedType() { var category = "abc.xyz.somepackage"; var name = "My Node"; var path = @"C:\temp\xyz.dyf"; var guid = Guid.NewGuid(); var info = new CustomNodeInfo(guid, name, category, "some description", path); var expectedQualifiedName = "dyf://abc.xyz.somepackage.My Node"; var moq = new Mock <ICustomNodeSource>(); var element = new CustomNodeSearchElement(moq.Object, info); var provider = new NodeItemDataProvider(new NodeSearchModel()); var item = provider.CreateLoadedTypeItem <LoadedTypeItem>(element); Assert.AreEqual(expectedQualifiedName, item.fullyQualifiedName); Assert.AreEqual(guid.ToString(), item.contextData); Assert.AreEqual(string.Empty, item.keywords); var url = new IconUrl(new Uri(item.iconUrl)); Assert.AreEqual(IconUrl.DefaultIcon, url.Name); Assert.AreEqual(IconUrl.DefaultPath, url.Path); }
public void CanRemoveNodeAndCategoryByFunctionId() { const string nodeName = "TheNoodle"; const string catName = "TheCat"; const string descr = "TheCat"; const string path = @"C:\turtle\graphics.dyn"; var guid1 = Guid.NewGuid(); var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path); var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1); // add custom node search.Add(dummySearch1); // confirm it's in the dictionary Assert.AreEqual(1, search.NumElements); // remove custom node search.Remove(dummySearch1); // it's gone Assert.AreEqual(0, search.NumElements); var results = search.Search(nodeName); Assert.AreEqual(0, results.Count()); }
public CustomNodeSearchElementViewModel(CustomNodeSearchElement element, SearchViewModel svm) : base(element, svm) { Model.PropertyChanged += ModelOnPropertyChanged; Path = Model.Path; }
public CustomNodeSearchElementViewModel(CustomNodeSearchElement element, SearchViewModel svm) : base(element, svm) { Path = Model.Path; }