예제 #1
0
        public void TestBasicNode2CodeWorkFlow4()
        {
            OpenModel(@"core\node2code\workflow4.dyn");
            var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;

            SelectAll(nodes);
            var command = new DynamoModel.ConvertNodesToCodeCommand();
            CurrentDynamoModel.ExecuteCommand(command);

            Assert.AreEqual(3, CurrentDynamoModel.CurrentWorkspace.Connectors.Count());
            Assert.AreEqual(3, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            var undo = new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo);
            CurrentDynamoModel.ExecuteCommand(undo);

            Assert.AreEqual(4, CurrentDynamoModel.CurrentWorkspace.Connectors.Count());
            Assert.AreEqual(4, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
        }
예제 #2
0
        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));
        }
예제 #3
0
        /// <summary>
        /// Run the dyn file and get all preview values in string representation. 
        /// Then, iterate all nodes, for each iteration, choose a node and convert 
        /// the remaining nodes to code, and compare the preview value of this 
        /// node against with its original value; then undo, run and compare the
        /// preview values of all nodes with original values.
        /// </summary>
        /// <param name="dynFilePath"></param>
        protected void MutationTest(string dynFilePath)
        {
            CurrentDynamoModel.Scheduler.ProcessMode = TaskProcessMode.Asynchronous;

            RunModel(dynFilePath);
            // Block until all tasks are executed
            while (CurrentDynamoModel.Scheduler.HasPendingTasks);

            var allNodes = CurrentDynamoModel.CurrentWorkspace.Nodes.Select(n => n.GUID).ToList();
            int nodeCount = allNodes.Count();
            var previewMap = allNodes.ToDictionary(n => n, n => GetStringData(n));

            var convertibleNodes = CurrentDynamoModel.CurrentWorkspace.Nodes
                                                                      .Where(node => node.IsConvertible)
                                                                      .Select(n => n.GUID).ToList();
            int connectorCount = CurrentDynamoModel.CurrentWorkspace.Connectors.Count();

            for (int i = 1; i <= Math.Min(convertibleNodes.Count(), 10); ++i)
            {
                var toBeConvertedNodes = convertibleNodes.Take(i);
                var otherNodes = allNodes.Except(toBeConvertedNodes);

                SelectAll(toBeConvertedNodes);

                var command = new DynamoModel.ConvertNodesToCodeCommand();
                CurrentDynamoModel.ExecuteCommand(command);
                // Block until all tasks are executed
                while (CurrentDynamoModel.Scheduler.HasPendingTasks);

                foreach (var node in otherNodes)
                {
                    // Verify after converting remaining nodes to code, the value
                    // of node that is not converted should remain same.
                    var preValue = previewMap[node];
                    var currentValue = GetStringData(node);
                    Assert.AreEqual(preValue, currentValue);
                }

                var undo = new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo);
                CurrentDynamoModel.ExecuteCommand(undo);
                // Block until all tasks are executed
                while (CurrentDynamoModel.Scheduler.HasPendingTasks) ;

                // 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);
                }
            }
        }
예제 #4
0
        public void TestBasicNode2CodeWorkFlow2()
        {
            // 1 -> Point.ByCoordinates ---+
            //                             |---------------------------+ 
            //                             +-- List.Create (index0)    |-> Line.ByStartPointEndPoint
            //                             +--> List.Create (index1)   |
            //                             |---------------------------+ 
            // 2 -> Point.ByCoordinates ---+
            OpenModel(@"core\node2code\workflow2.dyn");
            var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;

            SelectAll(nodes);
            var command = new DynamoModel.ConvertNodesToCodeCommand();
            CurrentDynamoModel.ExecuteCommand(command);

            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Connectors.Count());
            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            var undo = new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo);
            CurrentDynamoModel.ExecuteCommand(undo);

            Assert.AreEqual(6, CurrentDynamoModel.CurrentWorkspace.Connectors.Count());
            Assert.AreEqual(6, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
        }
예제 #5
0
        public void TestMultioutputNode()
        {
            // Regression MAGN-8009 
            OpenModel(@"core\node2code\multipleoutput.dyn");
            var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;
            SelectAll(nodes);

            var functionNode = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<DSFunction>().FirstOrDefault();
            var guid = functionNode.AstIdentifierGuid;

            var command = new DynamoModel.ConvertNodesToCodeCommand();
            CurrentDynamoModel.ExecuteCommand(command);
            CurrentDynamoModel.ForceRun();

            var cbn = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<CodeBlockNodeModel>().FirstOrDefault();
            Assert.IsNotNull(cbn);
            Assert.IsFalse(cbn.Code.Contains(guid));
        }
예제 #6
0
        public void TestUsingTypeDependentVariableName02()
        {
            OpenModel(@"core\node2code\num.dyn");
            var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;
            SelectAll(nodes);

            var command = new DynamoModel.ConvertNodesToCodeCommand();
            CurrentDynamoModel.ExecuteCommand(command);

            var cbn = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<CodeBlockNodeModel>().FirstOrDefault();
            Assert.IsNotNull(cbn);
            Assert.IsTrue(cbn.GetAstIdentifierForOutputIndex(0).Value.StartsWith("num"));
        }
예제 #7
0
        public void TestNodeWithVarArgument()
        {
            OpenModel(@"core\node2code\splitstring.dyn");
            var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;
            SelectAll(nodes);

            var command = new DynamoModel.ConvertNodesToCodeCommand();
            CurrentDynamoModel.ExecuteCommand(command);
            CurrentDynamoModel.ForceRun();

            var cbn = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<CodeBlockNodeModel>().FirstOrDefault();
            Assert.IsNotNull(cbn);

            var guid = cbn.GUID.ToString();
            AssertPreviewValue(guid, new[] { "foo", "bar", "qux" });
        }
예제 #8
0
        public void TestDirectoryToCode()
        {
            OpenModel(@"core\node2code\directory.dyn");
            var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;

            SelectAll(nodes);
            var command = new DynamoModel.ConvertNodesToCodeCommand();
            CurrentDynamoModel.ExecuteCommand(command);

            var cbn = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<CodeBlockNodeModel>().FirstOrDefault();
            Assert.IsNotNull(cbn);

            Assert.IsTrue(cbn.Code.Contains(@"D:\\foo\\bar"));
        }
예제 #9
0
        /// <summary>
        /// Run the dyn file and get all preview values in string representation. 
        /// Then, iterate all nodes, for each iteration, choose a node and convert 
        /// the remaining nodes to code, and compare the preview value of this 
        /// node against with its original value.
        /// </summary>
        /// <param name="dynFilePath"></param>
        protected void MutationTest(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);
            }

            var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes.Select(n => n.GUID).ToList();
            foreach (var node in nodes)
            {
                SelectAllExcept(node);
                var command = new DynamoModel.ConvertNodesToCodeCommand();
                CurrentDynamoModel.ExecuteCommand(command);
                CurrentDynamoModel.ForceRun();

                var preValue = previewMap[node];
                var currentValue = GetStringData(node);
                Assert.AreEqual(preValue, currentValue);
 
                var undo = new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo);
                CurrentDynamoModel.ExecuteCommand(undo);
            }
        }
예제 #10
0
        /// <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);
            }
        }
예제 #11
0
        /// <summary>
        /// After command framework is implemented, this method should now be only 
        /// called from a menu item (i.e. Ctrl + W). It should not be used as a 
        /// way for any other code paths to convert nodes to code programmatically. 
        /// For that we now have ConvertNodesToCodeInternal which takes in more 
        /// configurable arguments.
        /// </summary>
        /// <param name="parameters">This is not used and should always be null,
        /// otherwise an ArgumentException will be thrown.</param>
        /// 
        internal void NodeToCode(object parameters)
        {
            if (null != parameters) // See above for details of this exception.
            {
                const string message = "Internal error, argument must be null";
                throw new ArgumentException(message, "parameters");
            }

            var command = new DynamoModel.ConvertNodesToCodeCommand();
            this.DynamoViewModel.ExecuteCommand(command);
        }