public void CanCreateAndPlaceNewCustomNode() { const string name = "Custom Node Creation Test"; const string description = "Description"; const string category = "Custom Node Category"; CurrentDynamoModel.ExecuteCommand( new DynamoModel.CreateCustomNodeCommand( Guid.NewGuid(), name, category, description, true)); Assert.IsInstanceOf <CustomNodeWorkspaceModel>(CurrentDynamoModel.CurrentWorkspace); var customNodeWs = CurrentDynamoModel.CurrentWorkspace as CustomNodeWorkspaceModel; var customNodeDef = customNodeWs.CustomNodeDefinition; Assert.AreEqual(name, customNodeDef.DisplayName); Assert.AreEqual(description, customNodeWs.Description); Assert.AreEqual(category, customNodeWs.Category); var home = CurrentDynamoModel.Workspaces.OfType <HomeWorkspaceModel>().FirstOrDefault(); Assert.NotNull(home); SelectTabByGuid(home.Guid); CurrentDynamoModel.ExecuteCommand( new DynamoModel.CreateNodeCommand( CurrentDynamoModel.CustomNodeManager.CreateCustomNodeInstance(customNodeDef.FunctionId), 0, 0, true, true)); Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count()); Assert.IsInstanceOf <Function>(CurrentDynamoModel.CurrentWorkspace.Nodes.First()); Assert.AreEqual( customNodeDef.FunctionId, ((Function)CurrentDynamoModel.CurrentWorkspace.Nodes.First()).Definition.FunctionId); }
public void GetNodeFromCommand_DuplicatedGuidsTest() { //Arrange //This guid belongs to a CoreNodeModels.CreateList node inside the .dyn file Guid existingNodeGuid = new Guid("81c94fd0-35a0-4680-8535-00aff41192d3"); string openPath = Path.Combine(TestDirectory, @"core\DetailedPreviewMargin_Test.dyn"); RunModel(openPath); //When a CreateNodeCommand is executed internally calls the GetNodeFromCommand() method var command = new DynamoModel.CreateNodeCommand(existingNodeGuid.ToString(), "List.Create", 0, 0, true, true); //Act CurrentDynamoModel.ExecuteCommand(command); //Assert //Validating that the NodeCommand was successfully created. Assert.IsNotNull(command); Assert.AreEqual(command.Name, "List.Create"); Assert.AreEqual(command.ModelGuid.ToString(), existingNodeGuid.ToString()); }
public void FlagIsFalseWhenEvaluationStarted() { //On run start, HasRunWithoutCrash = false // - This makes sure that if the user has modifies the file during a run that causes a crash, there // file is not erroneously marked as having run without crash. var ws = Open <HomeWorkspaceModel>(TestDirectory, crashProtDir, "runManual.dyn"); // We do a run so HasRunWithoutCrash is set to true. Otherwise, the test // assertion is not valid. BeginRun(); EmptyScheduler(); Assert.True(ws.HasRunWithoutCrash); // Update the number input to ensure another run takes place var n = ws.Nodes.OfType <Nodes.DoubleInput>().First(); CurrentDynamoModel.ExecuteCommand( new DynamoModel.UpdateModelValueCommand(n.GUID, "Value", "3.0")); // We'll need this flag to ensure the run is completed even when // done async var assertionComplete = false; ws.EvaluationStarted += (e, a) => { Assert.False(ws.HasRunWithoutCrash); assertionComplete = true; }; // Do the next run BeginRun(); EmptyScheduler(); if (!assertionComplete) { Assert.Fail("The assertion was not evaluated!"); } }
private void TestNodeToCodeUndoBase(string filePath) { // Verify after undo all nodes and connectors should be resotored back // to original state. OpenModel(filePath); var wp = CurrentDynamoModel.CurrentWorkspace; var nodeGuids = wp.Nodes.Select(n => n.GUID).ToList(); nodeGuids.Sort(); var connectorGuids = wp.Connectors.Select(c => c.GUID).ToList(); connectorGuids.Sort(); SelectAll(wp.Nodes); var command = new DynamoModel.ConvertNodesToCodeCommand(); CurrentDynamoModel.ExecuteCommand(command); var undo = new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo); CurrentDynamoModel.ExecuteCommand(undo); var curNodeGuids = wp.Nodes.Select(n => n.GUID).ToList(); curNodeGuids.Sort(); var curConnectorGuids = wp.Connectors.Select(c => c.GUID).ToList(); curConnectorGuids.Sort(); Assert.AreEqual(curNodeGuids.Count, nodeGuids.Count); Assert.IsTrue(nodeGuids.SequenceEqual(curNodeGuids)); Assert.AreEqual(curConnectorGuids.Count, connectorGuids.Count); Assert.IsTrue(connectorGuids.SequenceEqual(curConnectorGuids)); }
public void CannotRemoveDefaultDSVarArgFunctionPorts() { // Arrange string openPath = Path.Combine(TestDirectory, @"core\dsfunction\StringSplit.dyn"); OpenModel(openPath); var nodeGuid = Guid.Parse("c969eca6005a4273aee4ed8ddd73f3ab"); var node = CurrentDynamoModel.CurrentWorkspace.NodeFromWorkspace <DSVarArgFunction>(nodeGuid); int portCountBefore = node.InPorts.Count; // Act CurrentDynamoModel.ExecuteCommand(new DynCmd.ModelEventCommand(nodeGuid, "AddInPort", 1)); int portCountAfterAdd = node.InPorts.Count; CurrentDynamoModel.ExecuteCommand(new DynCmd.ModelEventCommand(nodeGuid, "RemoveInPort", 1)); CurrentDynamoModel.ExecuteCommand(new DynCmd.ModelEventCommand(nodeGuid, "RemoveInPort", 1)); int portCountAfterRemove = node.InPorts.Count; // Assert Assert.AreEqual(2, portCountBefore); Assert.AreEqual(3, portCountAfterAdd); Assert.AreEqual(2, portCountAfterRemove); }
public void DeletingImperativeCBNShouldNotLeadToCrash() { TaskStateChangedEventHandler evaluationDidNotFailHandler = (DynamoScheduler sender, TaskStateChangedEventArgs args) => { Assert.AreNotEqual(TaskStateChangedEventArgs.State.ExecutionFailed, args.CurrentState); }; try { CurrentDynamoModel.Scheduler.TaskStateChanged += evaluationDidNotFailHandler; OpenModel(@"core\imperative\delete_imperative_cbn_crash.dyn"); AssertPreviewValue("0692b19256834a9187f3bcd500d513f1", 5.86); CurrentDynamoModel.ExecuteCommand(new DeleteModelCommand("45f0db0f-c014-481e-9b7f-939da54f2adc")); CurrentDynamoModel.ExecuteCommand(new DeleteModelCommand("235f53ba-d913-45d0-986a-b9c6588cba45")); AssertPreviewValue("0692b19256834a9187f3bcd500d513f1", 5.86); Assert.AreEqual(2, CurrentDynamoModel.CurrentWorkspace.Nodes.Count()); } finally { CurrentDynamoModel.Scheduler.TaskStateChanged -= evaluationDidNotFailHandler; } }
public void BeginDuplicateConnectionTest() { //Arrange string openPath = Path.Combine(TestDirectory, @"core\DetailedPreviewMargin_Test.dyn"); RunModel(openPath); Guid id = Guid.NewGuid(); //This guid belongs to a CoreNodeModels.CreateList node inside the .dyn file Guid existingNodeGuid = new Guid("81c94fd0-35a0-4680-8535-00aff41192d3"); //Connection Command with one Input port using a new guid var connectionCommand = new DynamoModel.MakeConnectionCommand(id, 0, PortType.Input, DynamoModel.MakeConnectionCommand.Mode.BeginDuplicateConnection); //Connection Command with one Output port using a new guid var connectionCommand2 = new DynamoModel.MakeConnectionCommand(id, 0, PortType.Output, DynamoModel.MakeConnectionCommand.Mode.BeginDuplicateConnection); var watch1 = new Watch { X = 100, Y = 300 }; CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(watch1, false); //Connection Command using a guid from a Watch node addded previosuly var connectionCommand3 = new DynamoModel.MakeConnectionCommand(watch1.GUID, 0, PortType.Input, DynamoModel.MakeConnectionCommand.Mode.BeginDuplicateConnection); //Act //The ExecuteCommand method internally will execute the BeginDuplicateConnectionTest method CurrentDynamoModel.ExecuteCommand(connectionCommand); CurrentDynamoModel.ExecuteCommand(connectionCommand2); CurrentDynamoModel.ExecuteCommand(connectionCommand3); //Assert //Validating that the commands were created successfully Assert.IsNotNull(connectionCommand); Assert.IsNotNull(connectionCommand2); Assert.IsNotNull(connectionCommand3); }
/// <summary> /// Run the dyn file and get all preview values in string representation. /// Undo, force run and get all preview values in string representation. /// These two sets of preview value should be the same. /// </summary> /// <param name="dynFilePath"></param> protected void UndoTest(string dynFilePath) { Dictionary <Guid, string> previewMap = new Dictionary <Guid, string>(); RunModel(dynFilePath); foreach (var node in CurrentDynamoModel.CurrentWorkspace.Nodes) { previewMap[node.GUID] = GetStringData(node.GUID); } int nodeCount = CurrentDynamoModel.CurrentWorkspace.Nodes.Count(); int connectorCount = CurrentDynamoModel.CurrentWorkspace.Connectors.Count(); SelectAll(); var command = new DynamoModel.ConvertNodesToCodeCommand(); CurrentDynamoModel.ExecuteCommand(command); CurrentDynamoModel.ForceRun(); var undo = new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo); CurrentDynamoModel.ExecuteCommand(undo); CurrentDynamoModel.ForceRun(); // Verify after undo everything is OK Assert.AreEqual(nodeCount, CurrentDynamoModel.CurrentWorkspace.Nodes.Count()); Assert.AreEqual(connectorCount, CurrentDynamoModel.CurrentWorkspace.Connectors.Count()); foreach (var node in CurrentDynamoModel.CurrentWorkspace.Nodes) { Assert.IsTrue(previewMap.ContainsKey(node.GUID)); var preValue = previewMap[node.GUID]; var currentValue = GetStringData(node.GUID); Assert.AreEqual(preValue, currentValue); } }
public void Regress7808() { // Verify that updating the function defintion will execute code blocks node that use // this function. var dynFilePath = Path.Combine(TestDirectory, @"core\dsevaluation\regress7808.dyn"); OpenModel(dynFilePath); // Original function defintion is // def foo() { return = 21;} var watchNodeGuid = "aef2375c-3dd8-4be0-8230-d964a2417f99"; AssertPreviewValue(watchNodeGuid, 21); // change to // def foo() { return = 42; } var cbnGuid = Guid.Parse("6a260ba7-d658-4350-a777-49511f725454"); var command = new Models.DynamoModel.UpdateModelValueCommand(Guid.Empty, cbnGuid, "Code", @"def foo() { return = 42; }"); CurrentDynamoModel.ExecuteCommand(command); RunCurrentModel(); AssertPreviewValue(watchNodeGuid, 42); }
public void LiveRunnerServicesUpdateGraph() { //Arrange var openPath = Path.Combine(TestDirectory, @"core\DetailedPreviewMargin_Test.dyn"); RunModel(openPath); //With this flag set to true we reach the section for logging. CurrentDynamoModel.EngineController.VerboseLogging = true; //We cannot set the VerboseLogging flag before the Model is created then in order to execute the UpdateGraph() //we need to call the OpenFileCommand again with the VerboseLogging already set to true var openPath2 = Path.Combine(TestDirectory, @"core\Angle.dyn"); //Act //Internally this will execute the UpdateGraph() method var commandFile = new DynamoModel.OpenFileCommand(openPath2); CurrentDynamoModel.ExecuteCommand(commandFile); //Assert //Verify that the command was created successfully Assert.IsNotNull(commandFile); }
public void SelectModelImplTest() { //Arrange string openPath = Path.Combine(TestDirectory, @"core\DetailedPreviewMargin_Test.dyn"); RunModel(openPath); //This will add a new DSFunction node to the current workspace var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+")); CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false); //Select the node created (DSFunction) DynamoSelection.Instance.Selection.Add(addNode); var ids = DynamoSelection.Instance.Selection.OfType <NodeModel>().Select(x => x.GUID).ToList(); var selectCommand = new DynamoModel.SelectModelCommand(ids, ModifierKeys.Shift); //Act CurrentDynamoModel.ExecuteCommand(selectCommand); //Assert Assert.Greater(ids.Count, 0); //At least one guid was found Assert.IsNotNull(selectCommand); }
public void ModificationUITesting() { // Re-use code for creating a custom node CanCreateAndPlaceNewCustomNode(); var instance = CurrentDynamoModel.CurrentWorkspace.Nodes.First() as Function; SelectTabByGuid(instance.Definition.FunctionId); var currentInPortAmt = 0; var currentOutPortAmt = 0; #region Adding Func <string, Symbol> addInput = label => { var node = new Symbol(); CurrentDynamoModel.ExecuteCommand(new DynamoModel.CreateNodeCommand(node, 0, 0, true, true)); node.InputSymbol = label; Assert.AreEqual(++currentInPortAmt, instance.InPorts.Count); Assert.AreEqual(label, instance.InPorts.Last().Name); return(node); }; Func <string, Output> addOutput = label => { var node = new Output(); CurrentDynamoModel.ExecuteCommand(new DynamoModel.CreateNodeCommand(node, 0, 0, true, true)); node.Symbol = label; Assert.AreEqual(++currentOutPortAmt, instance.OutPorts.Count); Assert.AreEqual(label, instance.OutPorts.Last().Name); return(node); }; #endregion #region Renaming Action <Symbol, int, string> renameInput = (input, idx, s) => { input.InputSymbol = s; Assert.AreEqual(s, instance.InPorts[idx].Name); }; Action <Output, int, string> renameOutput = (output, idx, s) => { output.Symbol = s; Assert.AreEqual(s, instance.OutPorts[idx].Name); }; #endregion #region Deleting Action <NodeModel> deleteNode = nodeModel => { DynamoSelection.Instance.ClearSelection(); CurrentDynamoModel.AddToSelection(nodeModel); var command = new DynamoModel.DeleteModelCommand(Guid.Empty); CurrentDynamoModel.ExecuteCommand(command); }; Action <Symbol> deleteInput = input => { deleteNode(input); Assert.AreEqual(--currentInPortAmt, instance.InPorts.Count); }; Action <Output> deleteOutput = output => { deleteNode(output); Assert.AreEqual(--currentOutPortAmt, instance.OutPorts.Count); }; #endregion //Add some outputs var out1 = addOutput("output1"); var out2 = addOutput("output2"); //Add some inputs var in1 = addInput("input1"); var in2 = addInput("input2"); //Change some names renameInput(in1, 0, "test"); renameOutput(out2, 1, "something"); //Delete some ports deleteInput(in2); deleteOutput(out1); }
private void UpdateCodeBlockNodeContent(CodeBlockNodeModel cbn, string value) { var command = new DynCmd.UpdateModelValueCommand(Guid.Empty, cbn.GUID, "Code", value); CurrentDynamoModel.ExecuteCommand(command); }
public void CanUpdatePythonTemplateSettings() { string settingDirectory = Path.Combine(TestDirectory, "settings"); string settingsFilePath = Path.Combine(settingDirectory, "DynamoSettings-PythonTemplate-initial.xml"); string changedSettingsFilePath = Path.Combine(settingDirectory, "DynamoSettings-PythonTemplate-changed.xml"); string initialPyFilePath = Path.Combine(settingDirectory, @"PythonTemplate-initial.py"); string changedPyFilePath = Path.Combine(settingDirectory, @"PythonTemplate-changed.py"); string initialPyVerificationText = "# Unit tests Python template example"; string updatedPyVerificationText = "# Changed Unit tests Python template example"; string pyTemplate = ""; string updatedPyTemplate = ""; // Assert files required for test exist Assert.IsTrue(File.Exists(settingsFilePath)); Assert.IsTrue(File.Exists(initialPyFilePath)); Assert.IsTrue(File.Exists(changedPyFilePath)); // load initial settings // Keep in mind the initial settings file for this test has only specified a filename, not a full path var settings = PreferenceSettings.Load(settingsFilePath); settings.PythonTemplateFilePath = Path.Combine(settingDirectory, settings.PythonTemplateFilePath); // Assert path in settings file and in test match Assert.AreEqual(settings.PythonTemplateFilePath, initialPyFilePath); // Propagate Python template specified in settings file to DynamoModel & read it from *.py file CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath = settings.PythonTemplateFilePath; pyTemplate = File.ReadAllText(CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath); // Assert the template actually reads and is not empty Assert.IsNotEmpty(pyTemplate); Assert.IsTrue(pyTemplate.StartsWith(initialPyVerificationText)); // Assert the workspace has no nodes Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 0); // create a Python nodeModel & add node to workspace var firstPyNodeModel = new PythonNodeModels.PythonNode(); CurrentDynamoModel.ExecuteCommand(new DynCmd.CreateNodeCommand(firstPyNodeModel, 0, 0, true, false)); var firstPyNode = CurrentDynamoModel.CurrentWorkspace.Nodes.Last() as PythonNodeModels.PythonNode; // Assert a new node has been added to workspace Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 1); // Assert both the new python nodeModel and workspace node have been // initialised with the initial Python template Assert.AreEqual(firstPyNodeModel.Script, pyTemplate); Assert.AreEqual(firstPyNode.Script, pyTemplate); Assert.IsTrue(firstPyNodeModel.Script.StartsWith(initialPyVerificationText)); Assert.IsTrue(firstPyNode.Script.StartsWith(initialPyVerificationText)); // change Python template & save settings to XML file CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath = changedPyFilePath; CurrentDynamoModel.PreferenceSettings.Save(changedSettingsFilePath); // load updated settings // no need for combining paths here as we have already done so before saving settings = PreferenceSettings.Load(changedSettingsFilePath); // update the DynamoModel settings CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath = settings.PythonTemplateFilePath; updatedPyTemplate = File.ReadAllText(CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath); // Assert the updated template is applied and not empty Assert.AreEqual( CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath, changedPyFilePath ); Assert.IsNotEmpty(updatedPyTemplate); Assert.IsTrue(updatedPyTemplate.StartsWith(updatedPyVerificationText)); // create a Python nodeModel & add node to workspace var secondPyNodeModel = new PythonNodeModels.PythonNode(); CurrentDynamoModel.ExecuteCommand(new DynCmd.CreateNodeCommand(secondPyNodeModel, 100, 100, true, false)); var secondPyNode = CurrentDynamoModel.CurrentWorkspace.Nodes.Last() as PythonNodeModels.PythonNode; // Assert a new node has been added to workspace Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 2); // Assert both the new python nodeModel and workspace node have been // initialised with the updated Python template Assert.AreEqual(secondPyNodeModel.Script, updatedPyTemplate); Assert.AreEqual(secondPyNode.Script, updatedPyTemplate); Assert.IsTrue(secondPyNodeModel.Script.StartsWith(updatedPyVerificationText)); Assert.IsTrue(secondPyNode.Script.StartsWith(updatedPyVerificationText)); }
public void TestWarningsOnNodeModel() { //Arrange var cbn = new CodeBlockNodeModel(CurrentDynamoModel.LibraryServices); var command = new DynamoModel.CreateNodeCommand(cbn, 0, 0, true, false); CurrentDynamoModel.ExecuteCommand(command); Assert.IsNotNull(cbn); cbn.Warning("TestPermanent0", true); cbn.Warning("TestPermanent1", true); cbn.Warning("TestPermanent2", true); Assert.AreEqual(ElementState.PersistentWarning, cbn.State); Assert.AreEqual(string.Join("", new List <string>() { "TestPermanent0", "TestPermanent1", "TestPermanent2" }), cbn.ToolTipText); cbn.Warning("TestTransient0", false); Assert.AreEqual(ElementState.Warning, cbn.State); Assert.AreEqual(string.Join("", new List <string>() { "TestPermanent0", "TestPermanent1", "TestPermanent2", "\nTestTransient0" }), cbn.ToolTipText); cbn.ClearTransientWarning("TestTransientOther"); Assert.AreEqual(ElementState.Warning, cbn.State); Assert.AreEqual(string.Join("", new List <string>() { "TestPermanent0", "TestPermanent1", "TestPermanent2", "\nTestTransient0" }), cbn.ToolTipText); cbn.ClearTransientWarning("TestTransient0"); Assert.AreEqual(ElementState.PersistentWarning, cbn.State); Assert.AreEqual(string.Join("", new List <string>() { "TestPermanent0", "TestPermanent1", "TestPermanent2" }), cbn.ToolTipText); cbn.ClearErrorsAndWarnings(); Assert.AreEqual(ElementState.Active, cbn.State); Assert.AreEqual("", cbn.ToolTipText); cbn.Warning("TestPermanent0", true); cbn.Warning("TestPermanent1", true); cbn.Warning("TestPermanent2", true); Assert.AreEqual(ElementState.PersistentWarning, cbn.State); Assert.AreEqual(string.Join("", new List <string>() { "TestPermanent0", "TestPermanent1", "TestPermanent2" }), cbn.ToolTipText); cbn.Warning("TestTransient0", false); Assert.AreEqual(ElementState.Warning, cbn.State); Assert.AreEqual(string.Join("", new List <string>() { "TestPermanent0", "TestPermanent1", "TestPermanent2", "\nTestTransient0" }), cbn.ToolTipText); cbn.ClearTransientWarning(); Assert.AreEqual(ElementState.PersistentWarning, cbn.State); Assert.AreEqual(string.Join("", new List <string>() { "TestPermanent0", "TestPermanent1", "TestPermanent2" }), cbn.ToolTipText); cbn.ClearErrorsAndWarnings(); Assert.AreEqual(ElementState.Active, cbn.State); Assert.AreEqual("", cbn.ToolTipText); }