Exemplo n.º 1
0
        internal void RunMutationTests()
        {
            Random rand = new Random(1);
            //DebugSettings.VerboseLogging = true;

            String logTarget = dynSettings.DynamoLogger.LogPath + "MutationLog.log";

            StreamWriter writer = new StreamWriter(logTarget);

            writer.WriteLine("MutateTest Internal activate");

            System.Diagnostics.Debug.WriteLine("MutateTest Internal activate");

            new Thread(() =>
            {
                bool passed = false;

                try
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        writer.WriteLine("##### - Beginning run: " + i);

                        var nodes = dynamoController.DynamoModel.Nodes;

                        writer.WriteLine("### - Beginning eval");


                        dynamoController.UIDispatcher.Invoke(new Action(() =>
                        {
                            DynamoViewModel.RunCancelCommand runCancel =
                                new DynamoViewModel.RunCancelCommand(false, false);
                            dynamoController.DynamoViewModel.ExecuteCommand(runCancel);
                        }));

                        while (dynamoController.DynamoViewModel.Controller.Runner.Running)
                        {
                            Thread.Sleep(10);
                        }

                        writer.WriteLine("### - Eval complete");
                        writer.Flush();
                        writer.WriteLine("### - Beginning readout");


                        Dictionary <Guid, String> valueMap = new Dictionary <Guid, String>();

                        foreach (NodeModel n in nodes)
                        {
                            if (n.OutPorts.Count > 0)
                            {
                                Guid guid   = n.GUID;
                                Object data = n.GetValue(0).Data;
                                String val  = data != null ? data.ToString() : "null";
                                valueMap.Add(guid, val);
                                writer.WriteLine(guid + " :: " + val);
                                writer.Flush();
                            }
                        }

                        writer.WriteLine("### - Readout complete");
                        writer.Flush();
                        writer.WriteLine("### - Beginning delete");
                        NodeModel node = nodes[rand.Next(nodes.Count)];
                        writer.WriteLine("### - Deletion target: " + node.GUID);


                        List <AbstractMutator> mutators = new List <AbstractMutator>()
                        {
                            new CodeBlockNodeMutator(rand), new DeleteNodeMutator(rand)
                        };


                        AbstractMutator mutator = mutators[rand.Next(mutators.Count)];

                        int numberOfUndosNeeded = mutator.Mutate();


                        Thread.Sleep(100);

                        writer.WriteLine("### - delete complete");
                        writer.Flush();
                        writer.WriteLine("### - Beginning re-exec");


                        dynamoController.UIDispatcher.Invoke(new Action(() =>
                        {
                            DynamoViewModel.RunCancelCommand runCancel =
                                new DynamoViewModel.RunCancelCommand(false, false);
                            dynamoController.DynamoViewModel.ExecuteCommand(runCancel);
                        }));

                        Thread.Sleep(100);

                        writer.WriteLine("### - re-exec complete");
                        writer.Flush();
                        writer.WriteLine("### - Beginning undo");


                        for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
                        {
                            dynamoController.UIDispatcher.Invoke(new Action(() =>
                            {
                                DynamoViewModel.UndoRedoCommand undoCommand =
                                    new DynamoViewModel.UndoRedoCommand(
                                        DynamoViewModel.UndoRedoCommand.Operation.Undo);
                                dynamoController.DynamoViewModel.ExecuteCommand(undoCommand);
                            }));

                            Thread.Sleep(100);
                        }


                        writer.WriteLine("### - undo complete");
                        writer.Flush();
                        writer.WriteLine("### - Beginning re-exec");

                        dynamoController.UIDispatcher.Invoke(new Action(() =>
                        {
                            DynamoViewModel.RunCancelCommand runCancel =
                                new DynamoViewModel.RunCancelCommand(false, false);

                            dynamoController.DynamoViewModel.ExecuteCommand(runCancel);
                        }));
                        Thread.Sleep(10);

                        while (dynamoController.DynamoViewModel.Controller.Runner.Running)
                        {
                            Thread.Sleep(10);
                        }

                        writer.WriteLine("### - re-exec complete");
                        writer.Flush();
                        writer.WriteLine("### - Beginning readback");


                        foreach (NodeModel n in nodes)
                        {
                            if (n.OutPorts.Count > 0)
                            {
                                try
                                {
                                    String valmap  = valueMap[n.GUID].ToString();
                                    Object data    = n.GetValue(0).Data;
                                    String nodeVal = data != null ? data.ToString() : "null";

                                    if (valmap != nodeVal)
                                    {
                                        writer.WriteLine("!!!!!!!!!!! Read-back failed");
                                        writer.WriteLine(n.GUID);


                                        writer.WriteLine("Was: " + nodeVal);
                                        writer.WriteLine("Should have been: " + valmap);
                                        writer.Flush();
                                        return;


                                        Debug.WriteLine("==========> Failure on run: " + i);
                                        Debug.WriteLine("Lookup map failed to agree");
                                        Validity.Assert(false);
                                    }
                                }
                                catch (Exception)
                                {
                                    writer.WriteLine("!!!!!!!!!!! Read-back failed");
                                    writer.Flush();
                                    return;
                                }
                            }
                        }

                        /*
                         * UIDispatcher.Invoke(new Action(() =>
                         * {
                         * DynamoViewModel.ForceRunCancelCommand runCancelForce =
                         * new DynamoViewModel.ForceRunCancelCommand(false,
                         *                false);
                         * DynamoViewModel.ExecuteCommand(runCancelForce);
                         *
                         * }));
                         * while (DynamoViewModel.Controller.Runner.Running)
                         * {
                         * Thread.Sleep(10);
                         * }
                         * foreach (NodeModel n in nodes)
                         * {
                         * if (n.OutPorts.Count > 0)
                         * {
                         *  String valmap = valueMap[n.GUID].ToString();
                         *  String nodeVal = n.GetValue(0).Data.ToString();
                         *
                         *  if (valmap != nodeVal)
                         *  {
                         *      Debug.WriteLine("==========> Failure on run: " + i);
                         *      Debug.WriteLine("Lookup map failed to agree");
                         *      Validity.Assert(false);
                         *
                         *  }
                         * }
                         * }
                         */
                    }

                    passed = true;
                }
                finally
                {
                    dynSettings.DynamoLogger.Log("Fuzz testing: " + (passed ? "pass" : "FAIL"));

                    writer.Flush();
                    writer.Close();
                    writer.Dispose();
                }
            }).
            Start();
        }
Exemplo n.º 2
0
        public override bool RunTest(NodeModel node, StreamWriter writer)
        {
            bool pass = false;

            var nodes = DynamoViewModel.Model.Nodes.ToList();

            if (nodes.Count == 0)
            {
                return(pass);
            }

            int nodesCountBeforeCopying = nodes.Count;

            int numberOfUndosNeeded = this.Mutate(node);

            Thread.Sleep(100);

            writer.WriteLine("### - Beginning undo");
            for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
            {
                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.UndoRedoCommand undoCommand =
                        new DynamoViewModel.UndoRedoCommand(DynamoViewModel.UndoRedoCommand.Operation.Undo);
                    DynamoViewModel.ExecuteCommand(undoCommand);
                }));
                Thread.Sleep(100);
            }
            writer.WriteLine("### - undo complete");
            writer.Flush();

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoViewModel.RunCancelCommand runCancel =
                    new DynamoViewModel.RunCancelCommand(false, false);
                DynamoViewModel.ExecuteCommand(runCancel);
            }));
            while (DynamoViewModel.Model.Runner.Running)
            {
                Thread.Sleep(10);
            }

            writer.WriteLine("### - Beginning test of CopyNode");
            if (node.OutPorts.Count > 0)
            {
                try
                {
                    int nodesCountAfterCopying = DynamoViewModel.Model.Nodes.ToList().Count;

                    if (nodesCountBeforeCopying != nodesCountAfterCopying)
                    {
                        writer.WriteLine("!!!!!!!!!!! - test of CopyNode is failed");
                        writer.WriteLine(node.GUID);

                        writer.WriteLine("Was: " + nodesCountAfterCopying);
                        writer.WriteLine("Should have been: " + nodesCountBeforeCopying);
                        writer.Flush();
                        return(pass);
                    }
                    else
                    {
                        writer.WriteLine("### - test of CopyNode is passed");
                        writer.Flush();
                    }
                }
                catch (Exception)
                {
                    writer.WriteLine("!!!!!!!!!!! - test of CopyNode is failed");
                    writer.Flush();
                    return(pass);
                }
            }
            writer.WriteLine("### - test of CopyNode complete");
            writer.Flush();

            return(pass = true);
        }
Exemplo n.º 3
0
        public override bool RunTest(NodeModel node, StreamWriter writer)
        {
            bool pass = false;

            writer.WriteLine("### - Beginning readout");

            var valueMap = new Dictionary <Guid, String>();

            if (node.OutPorts.Count > 0)
            {
                Guid   guid = node.GUID;
                Object data = node.GetValue(0).Data;
                String val  = data != null?data.ToString() : "null";

                valueMap.Add(guid, val);
                writer.WriteLine(guid + " :: " + val);
                writer.Flush();
            }

            writer.WriteLine("### - Readout complete");
            writer.Flush();

            writer.WriteLine("### - Beginning delete");
            writer.WriteLine("### - Deletion target: " + node.GUID);

            int numberOfUndosNeeded = Mutate(node);

            Thread.Sleep(100);

            writer.WriteLine("### - delete complete");
            writer.Flush();

            writer.WriteLine("### - Beginning re-exec");

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoViewModel.RunCancelCommand runCancel =
                    new DynamoViewModel.RunCancelCommand(false, false);

                DynamoViewModel.ExecuteCommand(runCancel);
            }));
            Thread.Sleep(100);

            writer.WriteLine("### - re-exec complete");
            writer.Flush();

            writer.WriteLine("### - Beginning undo");

            for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
            {
                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.UndoRedoCommand undoCommand =
                        new DynamoViewModel.UndoRedoCommand(
                            DynamoViewModel.UndoRedoCommand.Operation.Undo);

                    DynamoViewModel.ExecuteCommand(undoCommand);
                }));
            }
            Thread.Sleep(100);

            writer.WriteLine("### - undo complete");
            writer.Flush();

            writer.WriteLine("### - Beginning re-exec");

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoViewModel.RunCancelCommand runCancel =
                    new DynamoViewModel.RunCancelCommand(false, false);

                DynamoViewModel.ExecuteCommand(runCancel);
            }));
            Thread.Sleep(10);
            while (DynamoViewModel.Model.Runner.Running)
            {
                Thread.Sleep(10);
            }

            writer.WriteLine("### - re-exec complete");
            writer.Flush();

            writer.WriteLine("### - Beginning readback");

            if (node.OutPorts.Count > 0)
            {
                try
                {
                    String valmap  = valueMap[node.GUID].ToString();
                    Object data    = node.GetValue(0).Data;
                    String nodeVal = data != null?data.ToString() : "null";

                    if (valmap != nodeVal)
                    {
                        writer.WriteLine("!!!!!!!!!!! Read-back failed");
                        writer.WriteLine(node.GUID);

                        writer.WriteLine("Was: " + nodeVal);
                        writer.WriteLine("Should have been: " + valmap);
                        writer.Flush();
                        return(pass);
                    }
                }
                catch (Exception)
                {
                    writer.WriteLine("!!!!!!!!!!! Read-back failed");
                    writer.Flush();
                    return(pass);
                }
            }

            return(pass = true);
        }
Exemplo n.º 4
0
        public override bool RunTest(NodeModel node, StreamWriter writer)
        {
            bool pass = false;

            var nodes = DynamoViewModel.Model.Nodes.ToList();

            if (nodes.Count == 0)
            {
                return(pass);
            }

            int nodesCountBeforeDelete = nodes.Count;

            writer.WriteLine("### - Beginning readout");

            writer.WriteLine("### - Beginning delete");
            writer.WriteLine("### - Deletion target: " + node.GUID);

            int numberOfUndosNeeded = Mutate(node);

            Thread.Sleep(100);

            writer.WriteLine("### - delete complete");
            writer.Flush();

            writer.WriteLine("### - Beginning re-exec");

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoViewModel.RunCancelCommand runCancel =
                    new DynamoViewModel.RunCancelCommand(false, false);

                DynamoViewModel.ExecuteCommand(runCancel);
            }));
            Thread.Sleep(100);

            writer.WriteLine("### - re-exec complete");
            writer.Flush();

            writer.WriteLine("### - Beginning undo");

            int nodesCountAfterDelete = DynamoViewModel.Model.Nodes.Count;

            if (nodesCountBeforeDelete > nodesCountAfterDelete)
            {
                for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
                {
                    DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                    {
                        DynamoViewModel.UndoRedoCommand undoCommand =
                            new DynamoViewModel.UndoRedoCommand(
                                DynamoViewModel.UndoRedoCommand.Operation.Undo);

                        DynamoViewModel.ExecuteCommand(undoCommand);
                    }));
                    Thread.Sleep(100);
                }
                writer.WriteLine("### - undo complete");
                writer.Flush();

                writer.WriteLine("### - Beginning re-exec");

                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.RunCancelCommand runCancel =
                        new DynamoViewModel.RunCancelCommand(false, false);

                    DynamoViewModel.ExecuteCommand(runCancel);
                }));
                Thread.Sleep(10);
                while (DynamoViewModel.Model.Runner.Running)
                {
                    Thread.Sleep(10);
                }
                writer.WriteLine("### - re-exec complete");
                writer.Flush();

                int nodesCountAfterUbdo = DynamoViewModel.Model.Nodes.Count;
                if (nodesCountBeforeDelete == nodesCountAfterUbdo)
                {
                    writer.WriteLine("### - Node was restored");
                }
                else
                {
                    writer.WriteLine("### - Node wasn't restored");
                    return(pass);
                }
                writer.Flush();
            }
            else
            {
                writer.WriteLine("### - Error removing a node");
                writer.Flush();
                return(pass);
            }
            return(pass = true);
        }
Exemplo n.º 5
0
        public override bool RunTest(NodeModel node, StreamWriter writer)
        {
            bool pass = false;

            var types = LoadAllTypesFromDynamoAssemblies();

            foreach (Type type in types)
            {
                string nodeName = GetName(type);

                var firstNodeConnectors = node.AllConnectors.ToList();

                double coordinatesX = node.X;
                double coordinatesY = node.Y;

                if (!string.IsNullOrEmpty(nodeName))
                {
                    DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                    {
                        Guid guidNumber = Guid.NewGuid();

                        DynamoViewModel.CreateNodeCommand createCommand =
                            new DynamoViewModel.CreateNodeCommand(guidNumber, nodeName,
                                                                  coordinatesX, coordinatesY, false, false);

                        DynamoViewModel.ExecuteCommand(createCommand);
                    }));

                    var valueMap = new Dictionary <Guid, String>();
                    foreach (ConnectorModel connector in firstNodeConnectors)
                    {
                        Guid   guid = connector.Start.Owner.GUID;
                        Object data = connector.Start.Owner.GetValue(0).Data;
                        String val  = data != null?data.ToString() : "null";

                        valueMap.Add(guid, val);
                        writer.WriteLine(guid + " :: " + val);
                        writer.Flush();
                    }

                    int numberOfUndosNeeded = Mutate(node);
                    Thread.Sleep(100);

                    writer.WriteLine("### - Beginning undo");
                    for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
                    {
                        DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                        {
                            DynamoViewModel.UndoRedoCommand undoCommand =
                                new DynamoViewModel.UndoRedoCommand(DynamoViewModel.UndoRedoCommand.Operation.Undo);

                            DynamoViewModel.ExecuteCommand(undoCommand);
                        }));
                    }
                    Thread.Sleep(100);

                    writer.WriteLine("### - undo complete");
                    writer.Flush();

                    DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                    {
                        DynamoViewModel.RunCancelCommand runCancel =
                            new DynamoViewModel.RunCancelCommand(false, false);

                        DynamoViewModel.ExecuteCommand(runCancel);
                    }));
                    while (DynamoViewModel.Model.Runner.Running)
                    {
                        Thread.Sleep(10);
                    }

                    writer.WriteLine("### - Beginning test of CustomNode");
                    if (node.OutPorts.Count > 0)
                    {
                        try
                        {
                            NodeModel nodeAfterUndo = DynamoViewModel.Model.Nodes.ToList().FirstOrDefault((t) =>
                            {
                                return(t.GUID == node.GUID);
                            });

                            if (nodeAfterUndo != null)
                            {
                                var firstNodeConnectorsAfterUndo = nodeAfterUndo.AllConnectors.ToList();
                                foreach (ConnectorModel connector in firstNodeConnectors)
                                {
                                    Guid   guid = connector.Start.Owner.GUID;
                                    Object data = connector.Start.Owner.GetValue(0).Data;
                                    String val  = data != null?data.ToString() : "null";

                                    if (valueMap[guid] != val)
                                    {
                                        writer.WriteLine("!!!!!!!!!!! - test of CustomNode is failed");
                                        writer.WriteLine(node.GUID);

                                        writer.WriteLine("Was: " + val);
                                        writer.WriteLine("Should have been: " + valueMap[guid]);
                                        writer.Flush();
                                        return(pass);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            writer.WriteLine("!!!!!!!!!!! - test of CustomNode is failed");
                            writer.Flush();
                            return(pass);
                        }
                    }
                    writer.WriteLine("### - test of CustomNode complete");
                    writer.Flush();
                }
            }
            return(pass = true);
        }
Exemplo n.º 6
0
        public override bool RunTest(NodeModel node, 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).Data;
                    String val  = data != null?data.ToString() : "null";

                    valueMap.Add(guid, val);
                    writer.WriteLine(guid + " :: " + val);
                    writer.Flush();
                }
            }

            string customNodeFilePath = string.Empty;

            if (node is Function)
            {
                customNodeFilePath = ((Function)node).Definition.WorkspaceModel.FileName;
            }

            var workspaces = DynamoViewModel.Model.Workspaces;

            if (File.Exists(customNodeFilePath))
            {
                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.OpenFileCommand openFile =
                        new DynamoViewModel.OpenFileCommand(customNodeFilePath);

                    DynamoViewModel.ExecuteCommand(openFile);
                }));
                Thread.Sleep(100);

                var nodesInCustomNodeBeforeMutation = workspaces.FirstOrDefault((t) =>
                {
                    return(t.Name == ((Function)node).Definition.WorkspaceModel.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(() =>
                    {
                        DynamoViewModel.UndoRedoCommand undoCommand =
                            new DynamoViewModel.UndoRedoCommand(DynamoViewModel.UndoRedoCommand.Operation.Undo);

                        DynamoViewModel.ExecuteCommand(undoCommand);
                    }));
                    Thread.Sleep(100);
                }
                writer.WriteLine("### - undo complete");
                writer.Flush();

                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.RunCancelCommand runCancel =
                        new DynamoViewModel.RunCancelCommand(false, false);

                    DynamoViewModel.ExecuteCommand(runCancel);
                }));
                while (DynamoViewModel.Model.Runner.Running)
                {
                    Thread.Sleep(10);
                }

                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.SwitchTabCommand switchCmd =
                        new DynamoViewModel.SwitchTabCommand(workspaceIndex);

                    DynamoViewModel.ExecuteCommand(switchCmd);
                }));
                Thread.Sleep(100);

                var nodesInCustomNodeAfterMutation = workspaces.FirstOrDefault((t) =>
                {
                    return(t.Name == ((Function)node).Definition.WorkspaceModel.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.FirstOrDefault((t) =>
                        {
                            return(t.GetType() == node.Workspace.GetType());
                        }).Nodes.ToList().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).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(() =>
                        {
                            DynamoViewModel.SwitchTabCommand swithCommand =
                                new DynamoViewModel.SwitchTabCommand(workspaceIndex);

                            DynamoViewModel.ExecuteCommand(swithCommand);

                            DynamoViewModel.Workspaces.Remove(item);
                        }));
                    }
                }

                writer.WriteLine("### - test of CustomNode complete");
                writer.Flush();
            }
            return(pass = true);
        }
Exemplo n.º 7
0
        public override bool RunTest(NodeModel node, StreamWriter writer)
        {
            bool pass = false;

            var valueMap = new Dictionary <Guid, String>();

            if (node.OutPorts.Count > 0)
            {
                var firstNodeConnectors = node.AllConnectors.ToList(); //Get node connectors
                foreach (ConnectorModel connector in firstNodeConnectors)
                {
                    Guid guid = connector.Start.Owner.GUID;
                    if (!valueMap.ContainsKey(guid))
                    {
                        Object data = connector.Start.Owner.GetValue(0).Data;
                        String val  = data != null?data.ToString() : "null";

                        valueMap.Add(guid, val);
                        writer.WriteLine(guid + " :: " + val);
                        writer.Flush();
                    }
                }
            }

            int numberOfUndosNeeded = Mutate(node);

            Thread.Sleep(100);

            writer.WriteLine("### - Beginning undo");
            for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
            {
                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.UndoRedoCommand undoCommand =
                        new DynamoViewModel.UndoRedoCommand(DynamoViewModel.UndoRedoCommand.Operation.Undo);

                    DynamoViewModel.ExecuteCommand(undoCommand);
                }));
                Thread.Sleep(100);
            }
            writer.WriteLine("### - undo complete");
            writer.Flush();

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoViewModel.RunCancelCommand runCancel =
                    new DynamoViewModel.RunCancelCommand(false, false);

                DynamoViewModel.ExecuteCommand(runCancel);
            }));
            while (DynamoViewModel.Model.Runner.Running)
            {
                Thread.Sleep(10);
            }

            writer.WriteLine("### - Beginning test of NumberRange");
            if (node.OutPorts.Count > 0)
            {
                try
                {
                    var firstNodeConnectors = node.AllConnectors.ToList();
                    foreach (ConnectorModel connector in firstNodeConnectors)
                    {
                        String valmap  = valueMap[connector.Start.Owner.GUID].ToString();
                        Object data    = connector.Start.Owner.GetValue(0).Data;
                        String nodeVal = data != null?data.ToString() : "null";

                        if (valmap != nodeVal)
                        {
                            writer.WriteLine("!!!!!!!!!!! - test of NumberRange is failed");
                            writer.WriteLine(node.GUID);

                            writer.WriteLine("Was: " + nodeVal);
                            writer.WriteLine("Should have been: " + valmap);
                            writer.Flush();
                            return(pass);
                        }
                    }
                }
                catch (Exception)
                {
                    writer.WriteLine("!!!!!!!!!!! - test of NumberRange is failed");
                    writer.Flush();
                    return(pass);
                }
            }
            writer.WriteLine("### - test of NumberRange complete");
            writer.Flush();

            return(pass = true);
        }
Exemplo n.º 8
0
        public override bool RunTest(NodeModel node, StreamWriter writer)
        {
            bool pass = false;

            List <ConnectorModel> firstNodeConnectors = node.AllConnectors.ToList();

            Dictionary <Guid, String> valueMap = new Dictionary <Guid, String>();

            foreach (ConnectorModel connector in firstNodeConnectors)
            {
                if (connector.Start.Owner.GUID != node.GUID)
                {
                    Guid guid = connector.Start.Owner.GUID;
                    if (!valueMap.ContainsKey(guid))
                    {
                        String val = connector.Start.Owner.NickName;
                        valueMap.Add(guid, val);
                        writer.WriteLine(guid + " :: " + val);
                        writer.Flush();
                    }
                }
                else if (connector.End.Owner.GUID != node.GUID)
                {
                    Guid guid = connector.End.Owner.GUID;
                    if (!valueMap.ContainsKey(guid))
                    {
                        String val = connector.End.Owner.NickName;
                        valueMap.Add(guid, val);
                        writer.WriteLine(guid + " :: " + val);
                        writer.Flush();
                    }
                }
            }

            int numberOfUndosNeeded = Mutate(node);

            Thread.Sleep(100);

            List <NodeModel> nodesAfterMutate = DynamoViewModel.Model.Nodes;

            if (nodesAfterMutate.Contains(node))
            {
                writer.WriteLine("### - Connector wasn't deleted");
                writer.Flush();
                return(pass);
            }
            else
            {
                writer.WriteLine("### - Connector was deleted");
            }

            for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
            {
                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoViewModel.UndoRedoCommand undoCommand =
                        new DynamoViewModel.UndoRedoCommand(
                            DynamoViewModel.UndoRedoCommand.Operation.Undo);

                    DynamoViewModel.ExecuteCommand(undoCommand);
                }));
            }
            Thread.Sleep(100);

            List <NodeModel> nodesAfterUndo = DynamoViewModel.Model.Nodes;

            NodeModel nodeAfterUndo = nodesAfterUndo.FirstOrDefault(t => t.GUID.Equals(node.GUID));

            List <ConnectorModel> firstNodeConnectorsAfterUndo = nodeAfterUndo.AllConnectors.ToList();

            foreach (ConnectorModel connector in firstNodeConnectorsAfterUndo)
            {
                if (connector.Start.Owner.GUID != node.GUID)
                {
                    Guid guid = connector.Start.Owner.GUID;

                    if (!valueMap.ContainsKey(guid))
                    {
                        writer.WriteLine("### - ### - Connector wasn't recreated");
                        writer.Flush();
                        return(pass);
                    }
                    else
                    {
                        writer.WriteLine("### - Connector was recreated");
                        writer.Flush();
                    }
                }
                else if (connector.End.Owner.GUID != node.GUID)
                {
                    Guid guid = connector.End.Owner.GUID;

                    if (!valueMap.ContainsKey(guid))
                    {
                        writer.WriteLine("### - ### - Connector wasn't recreated");
                        writer.Flush();
                        return(pass);
                    }
                    else
                    {
                        writer.WriteLine("### - Connector was recreated");
                        writer.Flush();
                    }
                }
            }
            return(pass = true);
        }