public void Dispose_DS_ClassInstance() { CurrentDynamoModel.EngineController.LibraryServices.ImportLibrary("..\\..\\..\\test\\core\\library\\testclass.ds"); var testNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("Test.CreateTest")); CurrentDynamoModel.ExecuteCommand(new DynamoModel.CreateNodeCommand(testNode, 0, 0, true, false)); var node = CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault(); Assert.IsNotNull(node); int stackCount = CurrentDynamoModel.EngineController.LiveRunnerRuntimeCore.RuntimeMemory.Stack.Count; CurrentDynamoModel.DeleteModelInternal(new List <Graph.ModelBase>() { node }); // There is an issue with global variables, they do not get cleaned up properly // so in this case the stack count will be increased by 1. // Change this after the issue is fixed int stackCountAfterDelete = stackCount + 1; Assert.AreEqual(stackCount + 1, CurrentDynamoModel.EngineController.LiveRunnerRuntimeCore.RuntimeMemory.Stack.Count); }
public void TestCopyPasteGroup_IfItsNodeDeletedAfterCopying() { //Add a Node var ws = CurrentDynamoModel.CurrentWorkspace; var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+")); ws.AddAndRegisterNode(addNode); Assert.AreEqual(ws.Nodes.Count(), 1); //Add a Note var addNote = ws.AddNote(false, 200, 200, "This is a test note", Guid.NewGuid()); Assert.AreEqual(ws.Notes.Count(), 1); //Select the node and notes DynamoSelection.Instance.Selection.Add(addNode); DynamoSelection.Instance.Selection.Add(addNote); //create the group around selected nodes and notes var groupId = Guid.NewGuid(); var annotation = ws.AddAnnotation("This is a test group", groupId); Assert.AreEqual(ws.Annotations.Count(), 1); Assert.AreNotEqual(0, annotation.Width); //Add the group selection DynamoSelection.Instance.Selection.Add(annotation); //Copy the group CurrentDynamoModel.Copy(); var modelToDelete = new List <ModelBase> { addNode }; //Delete the node CurrentDynamoModel.DeleteModelInternal(modelToDelete); // only the note should remain Assert.AreEqual(1, annotation.SelectedModels.Count()); //paste the group CurrentDynamoModel.Paste(); //there should be 2 groups in the workspace Assert.AreEqual(ws.Annotations.Count(), 2); var pastedGroup = ws.Annotations.First(g => g != annotation); // group has been copied with 1 node and 1 note Assert.AreEqual(2, pastedGroup.SelectedModels.Count()); }
public void GitHub_461_DeleteNodesFromCustomNodeWorkspaceAfterCollapse() { string openPath = Path.Combine(TestDirectory, @"core\collapse\collapse.dyn"); OpenModel(openPath); var nodesToCollapse = new[] { "1da395b9-2539-4705-a479-1f6e575df01d", "b8130bf5-dd14-4784-946d-9f4705df604e", "a54c7cfa-450a-4edc-b7a5-b3e15145a9e1" }; foreach ( var node in nodesToCollapse.Select(CurrentDynamoModel.CurrentWorkspace.NodeFromWorkspace)) { CurrentDynamoModel.AddToSelection(node); } var ws = CurrentDynamoModel.CustomNodeManager.Collapse( DynamoSelection.Instance.Selection.OfType <NodeModel>(), Enumerable.Empty <NoteModel>(), CurrentDynamoModel.CurrentWorkspace, true, new FunctionNamePromptEventArgs { Category = "Testing", Description = "", Name = "__CollapseTest2__", Success = true }); CurrentDynamoModel.AddCustomNodeWorkspace(ws); SelectTabByGuid(ws.CustomNodeId); Assert.AreEqual(6, CurrentDynamoModel.CurrentWorkspace.Nodes.Count()); var modelsToDelete = new List <ModelBase>(); var addition = CurrentDynamoModel.CurrentWorkspace.FirstNodeFromWorkspace <DSFunction>(); Assert.IsNotNull(addition); Assert.AreEqual("+", addition.Name); modelsToDelete.Add(addition); CurrentDynamoModel.DeleteModelInternal(modelsToDelete); Assert.AreEqual(5, CurrentDynamoModel.CurrentWorkspace.Nodes.Count()); }
public void TestOnDeletionStarted() { //Arrange //This will subscribe our local method to the DeletionStarted event CurrentDynamoModel.DeletionStarted += CurrentDynamoModel_DeletionStarted; //This create a new Code Block node and update the content var codeBlockNode0 = CreateCodeBlockNode(); UpdateCodeBlockNodeContent(codeBlockNode0, @"true;"); // Create the watch node. var watch = new Watch(); var command = new DynCmd.CreateNodeCommand( watch, 0, 0, true, false); CurrentDynamoModel.ExecuteCommand(command); // Connect the two nodes ConnectorModel.Make(codeBlockNode0, watch, 0, 0); // Run Assert.DoesNotThrow(BeginRun); // Check that we have two nodes in the current workspace, the Watch node and the CodeBlock Assert.AreEqual(2, CurrentDynamoModel.CurrentWorkspace.Nodes.Count()); // Delete the code block node, internally this will call the OnDeletionStarted() method var nodeCodeBlock = new List <ModelBase> { codeBlockNode0 }; CurrentDynamoModel.DeleteModelInternal(nodeCodeBlock); // Check that we have only the watch in the current workspace Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count()); Assert.AreEqual("Watch", CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault().GetType().Name); // Try to delete the Watch node var nodeWatch = new List <ModelBase> { watch }; CurrentDynamoModel.DeleteModelInternal(nodeWatch); CurrentDynamoModel.DeletionStarted -= CurrentDynamoModel_DeletionStarted; Assert.IsTrue(deletionStarted); }