public void CanDeletePresetState() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; model.CurrentWorkspace.AddNode(numberNode1, false); model.CurrentWorkspace.AddNode(numberNode2, false); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 2); DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.CurrentWorkspace.AddPreset( "state1", "a state with 2 numbers", IDS); //assert that the preset has been created Assert.AreEqual(model.CurrentWorkspace.Presets.Count(), 1); Assert.AreEqual(model.CurrentWorkspace.Presets.First().Nodes.Count(), 2); //delete state var state = model.CurrentWorkspace.Presets.First(); model.CurrentWorkspace.RemoveState(state); Assert.AreEqual(model.CurrentWorkspace.Presets.Count(), 0); }
public void CanCreatePreset() { //Create a Node var numberNode = new DoubleInput(); numberNode.Value = "1"; ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(numberNode, false); //verify the node was created Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count()); DynamoSelection.Instance.Selection.Add(numberNode); //Check for input nodes Assert.AreEqual(true, ViewModel.GetSelectedInputNodes().Any()); var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+")); ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(addNode, false); DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(addNode); Assert.AreEqual(false, ViewModel.GetSelectedInputNodes().Any()); DynamoSelection.Instance.Selection.Add(numberNode); //Check for input nodes Assert.AreEqual(true, ViewModel.GetSelectedInputNodes().Any()); }
public void RunButtonDisabledInPeriodicRun() { var homeSpace = GetHomeSpace(); var node = new DoubleInput(); Model.AddNodeToCurrentWorkspace(node, true); node.CanUpdatePeriodically = true; homeSpace.RunSettings.RunType = RunType.Periodic; Assert.False((View.RunSettingsControl.RunButton.IsEnabled)); }
public void PeriodicEnabledWithPeriodicNodes() { var node = new DoubleInput { CanUpdatePeriodically = true }; var homeSpace = GetHomeSpace(); homeSpace.AddNode(node, true); var item = View.RunSettingsControl.RunTypesComboBox.Items[2] as RunTypeItem; Assert.True(item.Enabled); }
public void TestNodeToCodeCommandState() { DynamoSelection.Instance.ClearSelection(); Assert.IsFalse(ViewModel.CurrentSpaceViewModel.NodeToCodeCommand.CanExecute(null)); var node = new DoubleInput(); ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(node, false); DynamoSelection.Instance.Selection.Add(node); Assert.IsTrue(ViewModel.CurrentSpaceViewModel.NodeToCodeCommand.CanExecute(null)); DynamoSelection.Instance.ClearSelection(); Assert.IsFalse(ViewModel.CurrentSpaceViewModel.NodeToCodeCommand.CanExecute(null)); }
private List<NodeModel> SetupNumberNodesAndPresets() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+")); model.ExecuteCommand(new DynamoModel.CreateNodeCommand(numberNode1,0,0,true,false)); model.ExecuteCommand(new DynamoModel.CreateNodeCommand(numberNode2, 0, 0, true, false)); model.ExecuteCommand(new DynamoModel.CreateNodeCommand(addNode, 0, 0, true, false)); //connect them up model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(numberNode1.GUID,0,PortType.Output,DynCmd.MakeConnectionCommand.Mode.Begin)); model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID,0,PortType.Input,DynCmd.MakeConnectionCommand.Mode.End)); model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(numberNode2.GUID,0,PortType.Output,DynCmd.MakeConnectionCommand.Mode.Begin)); model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID,1,PortType.Input,DynCmd.MakeConnectionCommand.Mode.End)); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3); Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2); DynamoSelection.Instance.ClearSelection(); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var ids = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.ExecuteCommand(new DynamoModel.AddPresetCommand("state1", "3", ids)); //change values numberNode1.Value = "2"; numberNode2.Value = "3"; DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); ids = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); model.ExecuteCommand(new DynamoModel.AddPresetCommand("state2", "5", ids)); return new List<NodeModel>() { numberNode1, numberNode2,addNode }; }
public void TestNewNodeFromSelectionCommandState() { Assert.IsFalse(ViewModel.CurrentSpaceViewModel.NodeFromSelectionCommand.CanExecute(null)); var node = new DoubleInput(); ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(node, false); ViewModel.Model.AddToSelection(node); Assert.IsTrue(ViewModel.CurrentSpaceViewModel.NodeFromSelectionCommand.CanExecute(null)); var ws = ViewModel.Model.CustomNodeManager.Collapse( DynamoSelection.Instance.Selection.OfType<NodeModel>(), ViewModel.Model.CurrentWorkspace, true, new FunctionNamePromptEventArgs { Category = "Testing", Description = "", Name = "__CollapseTest2__", Success = true }); Assert.IsFalse(ViewModel.CurrentSpaceViewModel.NodeFromSelectionCommand.CanExecute(null)); }
public void TestDoubleInput() { var numNode = new DoubleInput { Value = "0.0", X = 400 }; //To check if base Serialization method is being called //Assert initial values Assert.AreEqual(400, numNode.X); Assert.AreEqual("0.0", numNode.Value); //Serialize node and then change values XmlDocument xmlDoc = new XmlDocument(); XmlElement serializedEl = numNode.Serialize(xmlDoc, SaveContext.Undo); numNode.X = 250; numNode.Value = "4"; //Assert new changes Assert.AreEqual(250, numNode.X); Assert.AreEqual("4", numNode.Value); //Deserialize and aasert old values numNode.Deserialize(serializedEl, SaveContext.Undo); Assert.AreEqual(400, numNode.X); Assert.AreEqual("0.0", numNode.Value); }
// Add a number node on workspace private void CreateNodeOnCurrentWorkspace() { // Create number node var numNode = new DoubleInput { X = 100, Y = 100 }; ViewModel.Model.CurrentWorkspace.AddNode(numNode, true); }
public void CanAddAndRestoreState() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+")); //add the nodes model.CurrentWorkspace.AddNode(numberNode1, false); model.CurrentWorkspace.AddNode(numberNode2, false); model.CurrentWorkspace.AddNode(addNode, false); //connect them up ConnectorModel.Make(numberNode1,addNode, 0, 0); ConnectorModel.Make(numberNode2,addNode, 0, 1); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3); Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.CurrentWorkspace.AddPreset( "state1", "3", IDS); //change values numberNode1.Value = "2"; numberNode2.Value = "3"; DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); model.CurrentWorkspace.AddPreset( "state2", "5", IDS); //now restore state to state 1 model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where( x => x.Name == "state1").First()); RunCurrentModel(); Thread.Sleep(250); //assert that the value of the add node is 3 Assert.AreEqual(addNode.CachedValue.Data, 3); //now restore state to state 2 model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where( x => x.Name == "state2").First()); RunCurrentModel(); Thread.Sleep(250); //assert that the value of the add node is 5 Assert.AreEqual(addNode.CachedValue.Data, 5); }
public void CanRestoreStateAndNodesDoNotMove() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+")); //add the nodes model.CurrentWorkspace.AddNode(numberNode1, false); model.CurrentWorkspace.AddNode(numberNode2, false); model.CurrentWorkspace.AddNode(addNode, false); //connect them up ConnectorModel.Make(numberNode1, addNode, 0, 0); ConnectorModel.Make(numberNode2, addNode, 0, 1); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3); Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.CurrentWorkspace.AddPreset( "state1", "3", IDS); Assert.AreEqual(numberNode1.X, 0); Assert.AreEqual(numberNode1.Y, 0); Assert.AreEqual(numberNode2.X, 0); Assert.AreEqual(numberNode2.Y, 0); // move the nodes numberNode1.X = 10; numberNode1.Y = 10; numberNode2.X = 20; numberNode2.Y = 20; //set the state back before model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where( x => x.Name == "state1").First()); Assert.AreEqual(numberNode1.X, 10); Assert.AreEqual(numberNode1.Y, 10); Assert.AreEqual(numberNode2.X, 20); Assert.AreEqual(numberNode2.Y, 20); }
public void CanCreateStatesAndSave() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+")); //add the nodes model.CurrentWorkspace.AddNode(numberNode1, false); model.CurrentWorkspace.AddNode(numberNode2, false); model.CurrentWorkspace.AddNode(addNode, false); //connect them up ConnectorModel.Make(numberNode1, addNode, 0, 0); ConnectorModel.Make(numberNode2, addNode, 0, 1); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3); Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.CurrentWorkspace.AddPreset( "state1", "3", IDS); //change values numberNode1.Value = "2"; numberNode2.Value = "3"; DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); model.CurrentWorkspace.AddPreset( "state2", "5", IDS); //save these states var newPath = GetNewFileNameOnTempPath("dyn"); var res = model.CurrentWorkspace.SaveAs(newPath, model.EngineController.LiveRunnerRuntimeCore); Assert.IsTrue(res); Assert.IsTrue(File.Exists(newPath)); }
public void CanRestoreStateInGraphThatIsMissingNodes() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+")); //add the nodes model.CurrentWorkspace.AddNode(numberNode1, false); model.CurrentWorkspace.AddNode(numberNode2, false); model.CurrentWorkspace.AddNode(addNode, false); //connect them up ConnectorModel.Make(numberNode1, addNode, 0, 0); ConnectorModel.Make(numberNode2, addNode, 0, 1); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3); Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.CurrentWorkspace.AddPreset( "state1", "3", IDS); //change values numberNode1.Value = "2"; numberNode2.Value = "3"; //now delete numberNode1; model.CurrentWorkspace.RemoveNode(numberNode1); //now restore state to state 1 Assert.DoesNotThrow(() => { model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where( x => x.Name == "state1").First()); }); //now check that numbernode2 has been set to correct value in state 1 Assert.AreEqual(numberNode2.Value, "2"); //check that node 1 has actually been deleted Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 2); }
public void AddPresetShouldSetDirtyFlag() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+")); //Check for Dirty flag Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges,false); //add the nodes model.CurrentWorkspace.AddAndRegisterNode(numberNode1, false); model.CurrentWorkspace.AddAndRegisterNode(numberNode2, false); model.CurrentWorkspace.AddAndRegisterNode(addNode, false); //Check for Dirty flag Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, true); //Set the dirty flag to false. Mocking the save. model.CurrentWorkspace.HasUnsavedChanges = false; Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, false); //connect them up ConnectorModel.Make(numberNode1, addNode, 0, 0); ConnectorModel.Make(numberNode2, addNode, 0, 1); //Check for Dirty flag - After the connection the dirty flag should be set. Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, true); //Set the dirty flag to false. Mocking the save. model.CurrentWorkspace.HasUnsavedChanges = false; Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, false); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3); Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var ids = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.CurrentWorkspace.AddPreset( "state1", "3", ids); Assert.AreEqual(1, model.CurrentWorkspace.Presets.Count()); //change values numberNode1.Value = "2"; numberNode2.Value = "3"; DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); ids = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); model.CurrentWorkspace.AddPreset( "state2", "5", ids); //Check for Dirty flag - After the Preset the dirty flag should be set. Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, true); }
public void CloseWorkspaceShouldClearPresets() { var model = CurrentDynamoModel; //create some numbers var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+")); //add the nodes model.CurrentWorkspace.AddAndRegisterNode(numberNode1, false); model.CurrentWorkspace.AddAndRegisterNode(numberNode2, false); model.CurrentWorkspace.AddAndRegisterNode(addNode, false); //connect them up ConnectorModel.Make(numberNode1, addNode, 0, 0); ConnectorModel.Make(numberNode2, addNode, 0, 1); Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3); Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList(); //create the preset from 2 nodes model.CurrentWorkspace.AddPreset( "state1", "3", IDS); Assert.AreEqual(1, model.CurrentWorkspace.Presets.Count()); //Clear the current workspace model.ClearCurrentWorkspace(); //Clearing the workspace should clear the presets Assert.AreEqual(0, model.CurrentWorkspace.Presets.Count()); }