Example #1
0
        public void AddNewConnectionTwice()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node1             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test2.dll"), "IDontExistEither");
            ExperimentNode node2             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);

            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node1, node2);

            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);

            //add the same connection once again
            ExperimentNodeConnection newEdge2 = ((IEditableExperiment)experiment).AddConnection(node1, node2);

            Assert.IsNotNull(newEdge2);
            Assert.AreEqual(newEdge, newEdge2);
            // the amount of edges should still be the same
            Assert.AreEqual(1, experiment.EdgeCount);
        }
Example #2
0
        public void RemoveConnection()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node1             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test2.dll"), "IDontExistEither");
            ExperimentNode node2             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);

            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node1, node2);

            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);

            experiment.ResetModifiedFlag();

            Assert.AreEqual(4, experiment.VertexCount);
            ((IEditableExperiment)experiment).RemoveConnection(newEdge);

            // Verify that the edge was existed and the number of vertices was unaffected.
            Assert.AreEqual(0, experiment.EdgeCount);
            Assert.AreEqual(4, experiment.VertexCount);

            Assert.IsTrue(experiment.IsModified);
        }
Example #3
0
        public void GraphStructureValidator_NoPathToEnd2()
        {
            IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New());

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ExperimentNode node1 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5);
            ExperimentNode node2 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 15, 15);
            ExperimentNode node3 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 25, 25);

            experiment.AddConnection(experiment.StartNode, node1);
            experiment.AddConnection(experiment.StartNode, node3);
            experiment.AddConnection(node1, node2);
            experiment.AddConnection(node2, experiment.EndNode);

            Assert.IsFalse(node1.HasError);
            Assert.IsFalse(node2.HasError);
            Assert.IsFalse(node3.HasError);

            RunnableNodeFactory    templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance);
            RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            Assert.IsTrue(template.IsEmpty);

            Assert.IsTrue(node3.HasError);
            Assert.AreEqual(node3.ErrorMessage, "Unable to detect path to the END node.");
        }
Example #4
0
        public void PathUpdatedOnSaveExperiment()
        {
            IExperiment experiment = ExperimentManager.New();

            Assert.IsNotNull(experiment);
            Assert.AreEqual(2, experiment.VertexCount);
            Assert.IsTrue(string.IsNullOrEmpty(experiment.ExperimentInfo.FilePath));

            string filename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testSave.gml");

            try
            {
                bool success = ExperimentManager.Save(experiment, filename);

                Assert.IsTrue(success);
                Assert.IsTrue(File.Exists(filename));

                //did experiment info filepath got update on save
                Assert.AreEqual(experiment.ExperimentInfo.FilePath, filename);
            }
            finally
            {
                if (File.Exists(filename))
                {
                    //cleanup
                    File.Delete(filename);
                }
            }
        }
Example #5
0
        private void Activated(object sender, EventArgs eargs)
        {
            Experiment experiment = ExperimentManager.New();
            bool       success    = FileDialogs.NewExperimantDialog(m_applicationContext.MainWindow.WindowShell, ref experiment);

            if (success)
            {
                ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(m_applicationContext.Application, experiment);
                RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, experiment.ExperimentInfo.FilePath);
                m_applicationContext.OpenInWindow(newApplicationViewModel);

                String file = experiment.ExperimentInfo.FilePath;
                try
                {
                    ExperimentManager.Save(experiment, file);
                }
                catch (System.IO.IOException e)
                {
                    NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                    FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, "Failed to Save File", file);
                }
                catch (UnauthorizedAccessException e)
                {
                    NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                    FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, "Failed to Save File", file);
                }
                catch (Exception e)
                {
                    NLog.LogManager.GetCurrentClassLogger().ErrorException(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                    FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, "Failed to Save File", file);
                }
            }
        }
Example #6
0
        public void ValidateInputMapping_CorrectFlow_OutputFound2()
        {
            IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New());

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ExperimentNode readerNode  = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 5, 5);
            ExperimentNode writerNode1 = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 15, 15);
            ExperimentNode writerNode2 = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 25, 25);

            experiment.AddConnection(experiment.StartNode, writerNode1);
            experiment.AddConnection(writerNode1, writerNode2);
            experiment.AddConnection(writerNode2, readerNode);
            experiment.AddConnection(readerNode, experiment.EndNode);

            (writerNode1.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test1";
            (writerNode2.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test2";
            (readerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo    = "test1";

            RunnableNodeFactory    templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance);
            RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            Assert.IsFalse(template.IsEmpty);

            Assert.IsFalse(readerNode.HasError);
            Assert.IsFalse(writerNode1.HasError);
            Assert.IsFalse(writerNode2.HasError);

            Assert.AreEqual(5, template.Nodes.Count);
        }
Example #7
0
        public void AddNewComponentNullDefinition()
        {
            IExperiment experiment = ExperimentManager.New();

            Assert.AreEqual(2, experiment.VertexCount);
            ExperimentNode node = ((IEditableExperiment)experiment).AddComponentFromDefinition(null, -5, 5);
        }
Example #8
0
        public void SaveExperimentTest()
        {
            IExperiment experiment = ExperimentManager.New();

            Assert.IsNotNull(experiment);
            Assert.AreEqual(2, experiment.VertexCount);
            Assert.IsTrue(string.IsNullOrEmpty(experiment.ExperimentInfo.FilePath));

            string filename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testSave.gml");

            try
            {
                bool success = ExperimentManager.Save(experiment, filename);

                Assert.IsTrue(success);
                Assert.IsTrue(File.Exists(filename));

                IExperiment loadedExperiment = ExperimentManager.Load(filename, AppContext.Components);

                Assert.AreEqual(experiment.ExperimentInfo, loadedExperiment.ExperimentInfo);
            }
            finally
            {
                if (File.Exists(filename))
                {
                    //cleanup
                    File.Delete(filename);
                }
            }
        }
Example #9
0
        public void TestTemplateGraphDisposal_InValidNodes()
        {
            IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New());

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            //construct some simple m_experiment
            ExperimentNode node1 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5);
            ExperimentNode node2 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5);
            ExperimentNode node3 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5);

            node1.Data.Metadata.Label = "Broken Component";

            experiment.AddConnection(experiment.StartNode, node1);
            experiment.AddConnection(node1, node2);
            experiment.AddConnection(node2, node3);
            experiment.AddConnection(node3, experiment.EndNode);

            //initiate mockNodesFactory
            MockNodesFactory       mockNodesFactory = new MockNodesFactory();
            RunnableExperimentBase template         = GraphAdapter.Adapt(experiment, mockNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            //adaptation should have failed and graph should be empty because broken node construction failed
            Assert.IsTrue(template.IsEmpty);

            //but also all of the previously created nodes before reaching the broken node during adaptation should have been disposed.
            foreach (MockNode node in mockNodesFactory.CreatedNodes)
            {
                Assert.IsTrue(node.disposed);
            }
        }
Example #10
0
        public void ExperimentNew()
        {
            IExperiment experiment = ExperimentManager.New();

            Assert.IsNotNull(experiment);
            Assert.IsFalse(experiment.IsModified);
            Assert.AreEqual(2, experiment.VertexCount);
            Assert.IsTrue(string.IsNullOrEmpty(experiment.ExperimentInfo.FilePath));
        }
Example #11
0
        public void AddNewConnectionCannotTargetStartNode()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node2             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);

            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node2, experiment.StartNode);
        }
Example #12
0
        public void GetNewComponent()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def, -5, 5);

            ExperimentNode foundNode = experiment.GetNode(node.ID);

            Assert.AreEqual(node, foundNode);
        }
Example #13
0
        public void SaveOverReadOnlyFile()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            // set it to read only
            System.IO.FileInfo finfo = new System.IO.FileInfo(ExperimentFile);
            finfo.IsReadOnly = true;

            // attempt to save expecting an exception regarding it being read only
            ExperimentManager.Save(experiment, ExperimentFile);
        }
Example #14
0
        public void GraphStructureValidator_NoCircularLinkIfDecision()
        {
            Experiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ExperimentNode node1        = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5);
            ExperimentNode node2        = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 15, 15);
            var            decisionNode = AddDecisionToExperiment(experiment, 10, 10);

            decisionNode.Data.Metadata = CompileMockDecision("");

            experiment.AddConnection(experiment.StartNode, node1);
            experiment.AddConnection(node1, node2);
            experiment.AddConnection(node2, decisionNode);
            experiment.AddConnection(decisionNode, node1);
            experiment.AddConnection(decisionNode, experiment.EndNode);

            Assert.IsFalse(node1.HasError);
            Assert.IsFalse(node2.HasError);
            Assert.IsFalse(decisionNode.HasError);

            RunnableNodeFactory    templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance);
            RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            Assert.IsFalse(node1.HasError);
            Assert.IsFalse(node2.HasError);
            Assert.IsFalse(decisionNode.HasError);

            Assert.IsFalse(template.IsEmpty);
            Assert.AreEqual(5, template.Nodes.Count);

            //check all  edges
            foreach (RunnableNode node in template.Nodes)
            {
                if (node is RunnableDecisionNode)
                {
                    //in this graph decision node has only two outcoming edges
                    Assert.AreEqual(2, node.NextNodes.Count);
                }
                else if (node is RunnableEndNode)
                {
                    //end node has none outcoming edges
                    Assert.AreEqual(0, node.NextNodes.Count);
                }
                else
                {
                    //all other nodes in this graph has only one outcoming edge
                    Assert.AreEqual(1, node.NextNodes.Count);
                }
            }
        }
Example #15
0
        public void AddNewConnectionNullNode2()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node2             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(null, node2);

            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);
        }
Example #16
0
        public void RemoveComponent()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode added            = ((IEditableExperiment)experiment).AddComponentFromDefinition(def, -5, 5);

            ((IEditableExperiment)experiment).RemoveVertex(added);
            Assert.AreEqual(2, experiment.VertexCount);
            foreach (ExperimentNode node in experiment.Vertices)
            {
                Assert.AreNotEqual(added.ID, node.ID);
            }
        }
Example #17
0
        public void GetComponent()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ExperimentNode startNode = experiment.GetNode("Start");

            Assert.IsNotNull(startNode);
            Assert.AreEqual("Start", startNode.ID);
            Assert.IsTrue(startNode is TraceLab.Core.Experiments.ExperimentStartNode);
            ExperimentNode endNode = experiment.GetNode("End");

            Assert.IsNotNull(endNode);
            Assert.AreEqual("End", endNode.ID);
            Assert.IsTrue(endNode is TraceLab.Core.Experiments.ExperimentEndNode);

            ExperimentNode nodeDoesntExist = experiment.GetNode(Guid.NewGuid().ToString());

            Assert.IsNull(nodeDoesntExist);
        }
Example #18
0
        private void NewFunc(object param)
        {
            var    experiment          = ExperimentManager.New();
            Window parentWindow        = param as Window;
            NewExperimentDialog dialog = new NewExperimentDialog(parentWindow, this.SettingsViewModel.DefaultExperimentsDirectory);

            dialog.DataContext = experiment.ExperimentInfo;

            bool?success = dialog.ShowDialog();

            if (success == true)
            {
                ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(m_viewModel, experiment);
                RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, experiment.ExperimentInfo.FilePath);
                OpenInWindow(newApplicationViewModel);

                string file = experiment.ExperimentInfo.FilePath;
                try
                {
                    ExperimentManager.Save(experiment, file);
                }
                catch (System.IO.IOException e)
                {
                    NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                    System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK);
                }
                catch (UnauthorizedAccessException e)
                {
                    NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                    System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK);
                }
                catch (Exception e)
                {
                    NLog.LogManager.GetCurrentClassLogger().ErrorException(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                    System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK);
                }
            }
        }
Example #19
0
        public void AddNewConnection()
        {
            IExperiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node1             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test2.dll"), "IDontExistEither");
            ExperimentNode node2             = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);

            // We know already that experiments are modified after adding components, but we
            // want to make sure that they're modified after adding a connection too, so lets clear the modification flag first.
            experiment.ResetModifiedFlag();
            Assert.IsFalse(experiment.IsModified);

            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node1, node2);

            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);
            Assert.IsTrue(experiment.IsModified);
        }
Example #20
0
        public void ValidateInputMapping_NoOutputFound2()
        {
            Assert.Fail("Test temporarily broken. The input mapping validator temporarily validates across all components, " +
                        "not only predecessors nodes. Test ignored till the validator feature is going to be revisited.");

            IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New());

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ExperimentNode readerNode1 = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 5, 5);
            ExperimentNode readerNode2 = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 15, 15);
            ExperimentNode writerNode  = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 25, 25);

            experiment.AddConnection(experiment.StartNode, writerNode);
            experiment.AddConnection(experiment.StartNode, readerNode1);
            experiment.AddConnection(writerNode, readerNode2);
            experiment.AddConnection(readerNode1, experiment.EndNode);
            experiment.AddConnection(readerNode2, experiment.EndNode);

            (writerNode.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "fakemapping";
            (readerNode1.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo  = "fakemapping";
            (readerNode2.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo  = "fakemapping";

            Assert.IsFalse(readerNode1.HasError);
            Assert.IsFalse(readerNode2.HasError);
            Assert.IsFalse(writerNode.HasError);

            RunnableNodeFactory    templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance);
            RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            Assert.IsTrue(template.IsEmpty);

            Assert.IsFalse(readerNode2.HasError);
            Assert.IsFalse(writerNode.HasError);

            Assert.IsTrue(readerNode1.HasError);
            Assert.AreEqual(readerNode1.ErrorMessage, "The component attempts to load 'fakemapping' from the Workspace. However, none of the previous components outputs 'fakemapping' to the Workspace.");
        }
Example #21
0
        public void TestTemplateGraphDisposal_ValidNodes()
        {
            IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New());

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            //construct some simple m_experiment
            ExperimentNode node1 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5);
            ExperimentNode node2 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5);

            experiment.AddConnection(experiment.StartNode, node1);
            experiment.AddConnection(node1, node2);
            experiment.AddConnection(node2, experiment.EndNode);

            //initiate mockNodesFactory
            MockNodesFactory       mockNodesFactory = new MockNodesFactory();
            RunnableExperimentBase template         = GraphAdapter.Adapt(experiment, mockNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            foreach (MockNode node in mockNodesFactory.CreatedNodes)
            {
                Assert.IsFalse(node.disposed);
            }

            //execute disptacher, because in case of correct graph dispatcher disposes nodes
            MockProgress progress = new MockProgress();

            using (var dispatcher = ExperimentRunnerFactory.CreateExperimentRunner(template))
            {
                dispatcher.ExecuteExperiment(progress);
                Assert.IsFalse(progress.HasError);
            }

            foreach (MockNode node in mockNodesFactory.CreatedNodes)
            {
                Assert.IsTrue(node.disposed);
            }
        }
Example #22
0
        public void ValidateInputMapping_NoOutputFound()
        {
            IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New());

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ExperimentNode readerNode = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 5, 5);
            ExperimentNode writerNode = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 5, 5);

            experiment.AddConnection(experiment.StartNode, writerNode);
            experiment.AddConnection(writerNode, readerNode);
            experiment.AddConnection(readerNode, experiment.EndNode);

            (readerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "fakemapping";

            Assert.IsFalse(readerNode.HasError);

            RunnableNodeFactory    templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance);
            RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            Assert.IsTrue(template.IsEmpty);

            Assert.IsTrue(readerNode.HasError);
            Assert.AreEqual(readerNode.ErrorMessage, "The component attempts to load 'fakemapping' from the Workspace. However, none of the previous components outputs 'fakemapping' to the Workspace.");
        }
Example #23
0
        public void ValidateInputMapping_Decision_CorrectMapping()
        {
            Experiment experiment = ExperimentManager.New();

            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ExperimentNode writerNode = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 15, 15);

            (writerNode.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test";

            ExperimentNode readerNode = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 25, 25);

            (readerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "test";

            ExperimentNode incrementerNode = experiment.AddComponentFromDefinition(m_incrementerComponentMetaDefinition, 35, 35);

            (incrementerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo   = "test";
            (incrementerNode.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test";

            var decisionNode = AddDecisionToExperiment(experiment, 10, 10);
            //code doesn't really matter in this case, because we don't execute dispatcher
            string decisionCode = "";

            decisionNode.Data.Metadata = CompileMockDecision(decisionCode);

            experiment.AddConnection(experiment.StartNode, writerNode);
            experiment.AddConnection(writerNode, readerNode);
            experiment.AddConnection(readerNode, decisionNode);
            experiment.AddConnection(decisionNode, incrementerNode);
            experiment.AddConnection(incrementerNode, readerNode);
            experiment.AddConnection(decisionNode, experiment.EndNode);

            Assert.IsFalse(writerNode.HasError);
            Assert.IsFalse(readerNode.HasError);
            Assert.IsFalse(incrementerNode.HasError);
            Assert.IsFalse(decisionNode.HasError);

            RunnableNodeFactory    templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance);
            RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories);

            Assert.IsFalse(writerNode.HasError);
            Assert.IsFalse(readerNode.HasError);
            Assert.IsFalse(incrementerNode.HasError);
            Assert.IsFalse(decisionNode.HasError);

            Assert.IsFalse(template.IsEmpty);
            Assert.AreEqual(6, template.Nodes.Count);

            //check all  edges
            foreach (RunnableNode node in template.Nodes)
            {
                if (node is RunnableDecisionNode)
                {
                    //in this graph decision node has only two outcoming edges
                    Assert.AreEqual(2, node.NextNodes.Count);
                }
                else if (node is RunnableEndNode)
                {
                    //end node has none outcoming edges
                    Assert.AreEqual(0, node.NextNodes.Count);
                }
                else
                {
                    //all other nodes in this graph has only one outcoming edge
                    Assert.AreEqual(1, node.NextNodes.Count);
                }
            }
        }