public async Task GetWorkflowByName()
        {
            IEntityManager   database = TestSetup.CreateMemoryDatabase();
            IWorkflowService service  = new DatabaseWorkflowService(database, new Mock <IArchiveService>().Object);

            await service.CreateWorkflow(new WorkflowStructure {
                Name = "Test"
            });

            await service.CreateWorkflow(new WorkflowStructure {
                Name = "Plum"
            });

            await service.CreateWorkflow(new WorkflowStructure {
                Name = "Sollbestand"
            });

            WorkflowDetails workflow = await service.GetWorkflow("Plum");

            Assert.NotNull(workflow);
            Assert.AreEqual("Plum", workflow.Name);
        }
Esempio n. 2
0
        public async Task ExecuteSubWorkflowWithParametersInLoop()
        {
            Mock <IScriptImportService> importservice = new Mock <IScriptImportService>();

            importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object);
            Mock <IArchiveService> archiveservice = new Mock <IArchiveService>();

            IEntityManager           database         = TestSetup.CreateMemoryDatabase();
            CacheService             cache            = new CacheService(new NullLogger <CacheService>());
            IScriptCompiler          compiler         = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, archiveservice.Object, importservice.Object, null, null);
            IWorkflowService         workflowservice  = new DatabaseWorkflowService(database, archiveservice.Object);
            WorkflowCompiler         workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, workflowservice, compiler);
            WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, workflowservice, workflowcompiler);

            await workflowservice.CreateWorkflow(new WorkflowStructure {
                Name  = "Submarine",
                Nodes = new [] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$value"
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                }
            });

            WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure {
                Name  = "Subcall Test",
                Nodes = new[] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "0",
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Iterator,
                        Parameters = new Dictionary <string, object> {
                            ["Item"]       = "value",
                            ["Collection"] = "[1,2,3,4,5]"
                        }
                    },
                    new NodeData {
                        Type       = NodeType.Workflow,
                        Parameters = new Dictionary <string, object> {
                            ["Name"]      = "Submarine",
                            ["Arguments"] = new Dictionary <string, object> {
                                ["value"] = "$value"
                            }
                        },
                        Variable = "subresult"
                    },
                    new NodeData {
                        Type       = NodeType.BinaryOperation,
                        Parameters = new Dictionary <string, object> {
                            ["Lhs"]       = "$result",
                            ["Operation"] = BinaryOperation.Add,
                            ["Rhs"]       = "$subresult"
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$result",
                        }
                    },
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                    new IndexTransition {
                        OriginIndex = 1,
                        TargetIndex = 2
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 3,
                        Type        = TransitionType.Loop
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 5
                    },
                    new IndexTransition {
                        OriginIndex = 3,
                        TargetIndex = 4
                    },
                    new IndexTransition {
                        OriginIndex = 4,
                        TargetIndex = 2
                    },
                }
            }), new Dictionary <string, object>(), false);

            await task.Task;

            Assert.AreEqual(TaskStatus.Success, task.Status);
            Assert.AreEqual(15, task.Result);
        }
Esempio n. 3
0
        public async Task ProfileSubWorkflow()
        {
            Mock <IScriptImportService> importservice = new Mock <IScriptImportService>();

            importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object);
            Mock <IArchiveService> archiveservice = new Mock <IArchiveService>();

            IEntityManager           database         = TestSetup.CreateMemoryDatabase();
            CacheService             cache            = new CacheService(new NullLogger <CacheService>());
            IScriptCompiler          compiler         = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, archiveservice.Object, importservice.Object, null, null);
            IWorkflowService         workflowservice  = new DatabaseWorkflowService(database, archiveservice.Object);
            WorkflowCompiler         workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, workflowservice, compiler);
            WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, workflowservice, workflowcompiler);

            await workflowservice.CreateWorkflow(new WorkflowStructure {
                Name  = "Submarine",
                Nodes = new [] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Name       = "Subvalue",
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$job.id"
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                }
            });

            WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure {
                Name  = "Subcall Test",
                Nodes = new[] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Workflow,
                        Name       = "Call Submarine",
                        Parameters = new Dictionary <string, object> {
                            ["Name"]      = "Submarine",
                            ["Arguments"] = new Dictionary <string, object> {
                                ["job"] = new Dictionary <string, object> {
                                    ["id"] = 1.0
                                }
                            }
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                }
            }), new Dictionary <string, object>(), true);

            await task.Task;

            Assert.AreEqual(TaskStatus.Success, task.Status);
            Assert.That(task.Log.Any(l => l.Contains("calls")));
            Assert.AreEqual(1.0, task.Result);
        }