Ejemplo n.º 1
0
        public void PasteInputAndOutputNodeInHomeWorkspace()
        {
            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));

            CurrentDynamoModel.ExecuteCommand(new DynamoModel.CreateNodeCommand(
                                                  new Symbol(),
                                                  0, 0,
                                                  true, true));

            CurrentDynamoModel.ExecuteCommand(new DynamoModel.CreateNodeCommand(
                                                  new Output(),
                                                  0, 0,
                                                  true, true));

            foreach (var node in CurrentDynamoModel.CurrentWorkspace.Nodes)
            {
                CurrentDynamoModel.AddToSelection(node);
            }

            CurrentDynamoModel.Copy();

            var home = CurrentDynamoModel.Workspaces.OfType <HomeWorkspaceModel>().FirstOrDefault();

            Assert.NotNull(home);
            SelectTabByGuid(home.Guid);

            CurrentDynamoModel.Paste();

            var homeNodes = home.Nodes;

            Assert.AreEqual(2, homeNodes.Count());
            Assert.IsInstanceOf <CodeBlockNodeModel>(homeNodes.ElementAt(0));
            Assert.IsInstanceOf <CodeBlockNodeModel>(homeNodes.ElementAt(1));
        }
Ejemplo n.º 2
0
        public void CanAddOneNodeToClipboard()
        {
            int numNodes = 1;

            // create 100 nodes, and select them as you go
            for (int i = 0; i < numNodes; i++)
            {
                var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
                CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);

                Assert.AreEqual(i + 1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

                CurrentDynamoModel.AddToSelection(CurrentDynamoModel.CurrentWorkspace.Nodes.Last());
                Assert.AreEqual(i + 1, DynamoSelection.Instance.Selection.Count);
            }

            CurrentDynamoModel.Copy();
            Assert.AreEqual(numNodes, CurrentDynamoModel.ClipBoard.Count);
        }
        public void DelayedExecutionUndoRedoTest()
        {
            DynamoSelection.Instance.ClearSelection();
            workspaceNodes().ForEach((ele) => DynamoSelection.Instance.Selection.Add(ele));
            CurrentDynamoModel.Copy();
            CurrentDynamoModel.Paste();
            Assert.AreEqual(wModel.Nodes.Count(), originalNodeCount * 2);

            CurrentDynamoModel.ExecuteCommand(new UndoRedoCommand(UndoRedoCommand.Operation.Undo));
            Assert.AreEqual(wModel.Nodes.Count(), originalNodeCount);

            activateTaskCounter(originalNodeCount);
            CurrentDynamoModel.ExecuteCommand(new UndoRedoCommand(UndoRedoCommand.Operation.Redo));
            Assert.AreEqual(wModel.Nodes.Count(), originalNodeCount * 2);
            Assert.AreEqual(taskCounter, 1);
            deactivateTaskCounter();

            CurrentDynamoModel.ExecuteCommand(new UndoRedoCommand(UndoRedoCommand.Operation.Undo));
            Assert.IsTrue(wModel.Nodes.Count() == originalNodeCount);
        }
Ejemplo n.º 4
0
        public void TestCopyPasteNestedGroup()
        {
            // Arrange
            var nestedGroupTitle = "Nested Group";
            var parentGroupNode  = new DummyNode();
            var nestedGroupNode  = new DummyNode();

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(parentGroupNode, false);
            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(nestedGroupNode, false);

            // Created nested group
            DynamoSelection.Instance.Selection.Add(nestedGroupNode);
            var nestedGroupId = Guid.NewGuid();
            var nestedGroup   = CurrentDynamoModel.CurrentWorkspace.AddAnnotation(nestedGroupTitle, "A group inside another group", nestedGroupId);

            // Create parent group
            var parentGroup = new AnnotationModel(
                new NodeModel[] { parentGroupNode },
                new NoteModel[] { },
                new AnnotationModel[] { nestedGroup });

            CurrentDynamoModel.CurrentWorkspace.AddAnnotation(parentGroup);

            // Act
            DynamoSelection.Instance.Selection.Add(nestedGroup);
            CurrentDynamoModel.Copy();
            CurrentDynamoModel.Paste();

            var copiedGroups = CurrentDynamoModel.CurrentWorkspace.Annotations
                               .Where(x => x.AnnotationText == nestedGroupTitle);

            var copiedGroup = copiedGroups.Where(x => x.GUID != nestedGroupId);

            // Assert
            Assert.That(parentGroup.Nodes.Contains(nestedGroup));
            Assert.That(CurrentDynamoModel.CurrentWorkspace.Annotations.Count() == 3);
            Assert.That(copiedGroups.Count() == 2);
            Assert.That(copiedGroup.Count() == 1);
            Assert.IsFalse(parentGroup.Nodes.Contains(copiedGroup.FirstOrDefault()));
        }
Ejemplo n.º 5
0
        public void CanCopyPasteJSONDummyNodeAndRetainsOriginalJSON()
        {
            string openPath = Path.Combine(TestDirectory, testFileWithDummyNode);

            OpenModel(openPath);

            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.OfType <DummyNode>().Count());
            //select the dummy node
            CurrentDynamoModel.AddToSelection(CurrentDynamoModel.CurrentWorkspace.Nodes.OfType <DummyNode>().First());
            CurrentDynamoModel.Copy();
            CurrentDynamoModel.Paste();
            //get both dummyNodes
            Assert.AreEqual(2, CurrentDynamoModel.CurrentWorkspace.Nodes.OfType <DummyNode>().Count());
            var dummies = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType <DummyNode>().ToList();

            var oc1 = (dummies[0].OriginalNodeContent as JObject).ToString();
            var oc2 = (dummies[1].OriginalNodeContent as JObject).ToString();

            Console.WriteLine(oc1);
            Console.WriteLine(oc2);
            //assert that originalData are the same string
            Assert.AreEqual(oc1, oc2);
        }
Ejemplo n.º 6
0
        public void CanCopyAndPasteDSVarArgFunctionNode()
        {
            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            const string dsVarArgFunctionName = "DSCore.String.Split@string,string[]";
            var          node = new DSVarArgFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor(dsVarArgFunctionName));

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(node, false);

            // Here we check to see if we do get a DSVarArgFunction node (which
            // is what this test case is written for, other nodes will render the
            // test case meaningless).
            //
            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            CurrentDynamoModel.AddToSelection(node); // Select the only DSVarArgFunction node.
            CurrentDynamoModel.Copy();               // Copy the only DSVarArgFunction node.

            Assert.DoesNotThrow(() =>
            {
                CurrentDynamoModel.Paste(); // Nope, paste should not crash Dynamo.
            });
        }
Ejemplo n.º 7
0
        public void CanCopydAndPasteNodeWithRightOffset()
        {
            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));

            addNode.Height  = 2;
            addNode.Width   = 2;
            addNode.CenterX = 3;
            addNode.CenterY = 2;

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            CurrentDynamoModel.AddToSelection(addNode);
            Assert.AreEqual(1, DynamoSelection.Instance.Selection.Count);

            CurrentDynamoModel.Copy();
            Assert.AreEqual(1, CurrentDynamoModel.ClipBoard.Count);

            CurrentDynamoModel.Paste();
            Assert.AreEqual(2, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            Assert.AreEqual(22, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(1).X);
            Assert.AreEqual(21, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(1).Y);
        }