public void ForceRunCancelCommand_DeserializeCoreTest() { //Arrange string wspath = Path.Combine(TestDirectory, @"core\callsite\RebindingSingleDimension.dyn"); var fileCommand = new DynamoModel.OpenFileCommand(wspath); var runCancelCommand = new DynamoModel.ForceRunCancelCommand(false, false); CurrentDynamoModel.ExecuteCommand(runCancelCommand); XmlDocument xmlDocument = new XmlDocument(); XmlElement elemTest = xmlDocument.CreateElement("TestCommand"); //Act var helper = new XmlElementHelper(elemTest); //DeserializeCore method is looking for the attributes ShowErrors and CancelRun, then we need to set them up before calling the method. helper.SetAttribute("ShowErrors", true); helper.SetAttribute("CancelRun", true); var deserializedCommand = ForceRunCancelCommand.DeserializeCore(elemTest); //Assert Assert.IsNotNull(deserializedCommand); }
public void TestTryFindFileUri() { //Arrange //The dyn file passed as parameter doesn't exists, so a different part in TryFindFile method will be executed string wspath = Path.Combine(TestDirectory, @"core\callsite\RebindingSingleDimension1.dyn"); var fileCommand = new DynamoModel.OpenFileCommand(wspath); CustomXmlDocument xmlDocument = new CustomXmlDocument(); //We set the URI to be fake so when it's split on TryFindFile it will execute a different code section xmlDocument.CustomBaseURL = "http://localhost/test"; XmlElement elemTest = xmlDocument.CreateElement("TestCommand"); //Act var command = new OpenFileCommandDerivedTest(wspath); command.SerializeCoreTest(elemTest); //Assert Assert.Throws <FileNotFoundException>(() => OpenFileCommand.DeserializeCore(elemTest)); }
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 TestTryFindFile() { //Arrange string wspath = Path.Combine(TestDirectory, @"core\callsite\RebindingSingleDimension.dyn"); var fileCommand = new DynamoModel.OpenFileCommand(wspath); //We need a XmlDocument instance to create a new custom XmlElement XmlDocument xmlDocument = new XmlDocument(); XmlElement elemTest = xmlDocument.CreateElement("TestCommand"); //Act var command = new OpenFileCommandDerivedTest(wspath); command.SerializeCoreTest(elemTest); var deserializedCommand = OpenFileCommand.DeserializeCore(elemTest); //We need to set up the DynamoModel inside the OpenFileCommandDerivedTest class before calling TrackAnalytics() command.ExecuteTest(CurrentDynamoModel); command.TrackAnalytics(); //Assert //It will validate that the Deserialized element is valid Assert.IsNotNull(deserializedCommand); }
public override bool RunTest(NodeModel node, EngineController engine, StreamWriter writer) { bool pass = false; int workspaceIndex = DynamoViewModel.CurrentWorkspaceIndex; var firstNodeConnectors = node.AllConnectors.ToList(); var valueMap = new Dictionary <Guid, String>(); foreach (ConnectorModel connector in firstNodeConnectors) { if (connector.End.Owner.GUID != node.GUID) { Guid guid = connector.Start.Owner.GUID; Object data = connector.Start.Owner.GetValue(0, engine).Data; String val = data != null?data.ToString() : "null"; valueMap.Add(guid, val); writer.WriteLine(guid + " :: " + val); writer.Flush(); } } string customNodeFilePath = string.Empty; var function = node as Function; CustomNodeInfo info = null; if (function != null) { var id = function.Definition.FunctionId; if (DynamoViewModel.Model.CustomNodeManager.TryGetNodeInfo(id, out info)) { customNodeFilePath = info.Path; } } var workspaces = DynamoViewModel.Model.Workspaces; if (File.Exists(customNodeFilePath)) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoModel.OpenFileCommand openFile = new DynamoModel.OpenFileCommand(customNodeFilePath); DynamoViewModel.ExecuteCommand(openFile); })); Thread.Sleep(100); var nodesInCustomNodeBeforeMutation = workspaces.FirstOrDefault((t) => (t.Name == info.Name)).Nodes.ToList(); var customNodeStructureBeforeMutation = GetDictionaryOfConnectedNodes(nodesInCustomNodeBeforeMutation); int numberOfUndosNeeded = Mutate(node); Thread.Sleep(100); writer.WriteLine("### - Beginning undo"); for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoModel.UndoRedoCommand undoCommand = new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo); DynamoViewModel.ExecuteCommand(undoCommand); })); Thread.Sleep(100); } writer.WriteLine("### - undo complete"); writer.Flush(); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoModel.RunCancelCommand runCancel = new DynamoModel.RunCancelCommand(false, false); DynamoViewModel.ExecuteCommand(runCancel); })); while (!DynamoViewModel.HomeSpace.RunSettings.RunEnabled) { Thread.Sleep(10); } DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoModel.SwitchTabCommand switchCmd = new DynamoModel.SwitchTabCommand(workspaceIndex); DynamoViewModel.ExecuteCommand(switchCmd); })); Thread.Sleep(100); var nodesInCustomNodeAfterMutation = workspaces.FirstOrDefault((t) => (t.Name == info.Name)).Nodes.ToList(); var customNodeStructureAfterMutation = GetDictionaryOfConnectedNodes(nodesInCustomNodeAfterMutation); writer.WriteLine("### - Beginning test of CustomNode structure"); if (customNodeStructureBeforeMutation.Count == customNodeStructureAfterMutation.Count) { foreach (var item in customNodeStructureAfterMutation) { if (item.Value != customNodeStructureBeforeMutation[item.Key]) { writer.WriteLine("!!!!!!!!!!! - test of CustomNode structure is failed"); writer.Flush(); return(pass); } } } else { writer.WriteLine("!!!!!!!!!!! - test of CustomNode structure is failed"); writer.Flush(); return(pass); } writer.WriteLine("### - Beginning test of CustomNode"); if (node.OutPorts.Count > 0) { try { NodeModel nodeAfterUndo = workspaces.SelectMany(ws => ws.Nodes) .FirstOrDefault(t => t.GUID.Equals(node.GUID)); if (nodeAfterUndo == null) { writer.WriteLine("!!!!!!!!!!! - test of CustomNode is failed"); writer.Flush(); return(pass); } var firstNodeConnectorsAfterUndo = nodeAfterUndo.AllConnectors.ToList(); foreach (ConnectorModel connector in firstNodeConnectorsAfterUndo) { if (connector.End.Owner.GUID != node.GUID) { Object data = connector.Start.Owner.GetValue(0, engine).Data; String nodeVal = data != null?data.ToString() : "null"; if (valueMap[connector.Start.Owner.GUID] != nodeVal) { writer.WriteLine("!!!!!!!!!!! - test of CustomNode is failed"); writer.WriteLine(node.GUID); writer.WriteLine("Was: " + nodeVal); writer.WriteLine("Should have been: " + valueMap[connector.End.Owner.GUID]); writer.Flush(); return(pass); } } } } catch (Exception) { writer.WriteLine("!!!!!!!!!!! - test of CustomNode is failed"); writer.Flush(); return(pass); } } var workspacesOfCustomNodes = DynamoViewModel.Workspaces.Where((t) => { return(t.Model is CustomNodeWorkspaceModel); }).ToList(); if (workspacesOfCustomNodes != null) { foreach (var item in workspacesOfCustomNodes) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoModel.SwitchTabCommand swithCommand = new DynamoModel.SwitchTabCommand(workspaceIndex); DynamoViewModel.ExecuteCommand(swithCommand); DynamoViewModel.Workspaces.Remove(item); })); } } writer.WriteLine("### - test of CustomNode complete"); writer.Flush(); } return(pass = true); }