public void ParallelChildren()
        {
            var a = Helpers.BuildActivity();
            var b = Helpers.BuildActivity();
            var p = new ParallelBlock(new[] {a, b}, 1);

            var wi = new WorkItem(Helpers.Integer(), Helpers.Integer(), 0, WorkflowType.Parallel, Helpers.String())
            {
                InputId = Helpers.Integer()
            };

            _navigator.Find(wi.WorkflowPath).Returns(p);

            var items = _workItemBuilder.BuildChildren(wi).ToArray();
            var item1 = items[0];
            var item2 = items[1];

            Assert.Equal(2, items.Count());

            Assert.Equal(wi.JobId, item1.JobId);
            Assert.Equal(wi.Id, item1.ParentId);
            Assert.Equal(0, item1.Order);
            Assert.Equal(wi.InputId, item1.InputId);
            Assert.Equal(WorkflowType.Activity, item1.Type);

            Assert.Equal(wi.JobId, item2.JobId);
            Assert.Equal(wi.Id, item2.ParentId);
            Assert.Equal(1, item2.Order);
            Assert.Equal(wi.InputId, item2.InputId);
            Assert.Equal(WorkflowType.Activity, item2.Type);

            _navigator.Received(1).Path(p.Children.First());
            _navigator.Received(1).Path(p.Children.Last());
        }
        public void Test()
        {
            var a1 = Helpers.BuildActivity();
            var a2 = Helpers.BuildActivity();
            var a3 = Helpers.BuildActivity();
            var a4 = Helpers.BuildActivity();
            var a5 = Helpers.BuildActivity();
            var c1 = new SequenceBlock(new[] {a1});
            var f = new ForkBlock(a2, 1);
            var p = new ParallelBlock(new[] {a4, a5}, 1);
            var c2 = new SequenceBlock(new WorkflowBlock[] {f, c1, a3, p});

            var navigator = new WorkflowPathNavigator(c2);

            Assert.Equal("Sequence[0].Sequence[1].Activity[0]", navigator.Path(a1));
            Assert.Equal("Sequence[0].Fork[0].Activity[0]", navigator.Path(a2));
            Assert.Equal("Sequence[0].Activity[2]", navigator.Path(a3));
            Assert.Equal("Sequence[0].Sequence[1]", navigator.Path(c1));
            Assert.Equal("Sequence[0].Fork[0]", navigator.Path(f));
            Assert.Equal("Sequence[0]", navigator.Path(c2));
            Assert.Equal("Sequence[0].Parallel[3]", navigator.Path(p));
            Assert.Equal("Sequence[0].Parallel[3].Activity[0]", navigator.Path(a4));
            Assert.Equal("Sequence[0].Parallel[3].Activity[1]", navigator.Path(a5));

            Assert.Equal(a1, navigator.Find("Sequence[0].Sequence[1].Activity[0]"));
            Assert.Equal(a2, navigator.Find("Sequence[0].Fork[0].Activity[0]"));
            Assert.Equal(a3, navigator.Find("Sequence[0].Activity[2]"));
            Assert.Equal(c1, navigator.Find("Sequence[0].Sequence[1]"));
            Assert.Equal(f, navigator.Find("Sequence[0].Fork[0]"));
            Assert.Equal(c2, navigator.Find("Sequence[0]"));

            Assert.Equal(p, navigator.Find("Sequence[0].Parallel[3]"));
            Assert.Equal(a4, navigator.Find("Sequence[0].Parallel[3].Activity[0]"));
            Assert.Equal(a5, navigator.Find("Sequence[0].Parallel[3].Activity[1]"));
        }
        public void PallaralConstruction()
        {
            Func<string, int> parse = int.Parse;
            Func<string, int> count = s => s.Length;

            var parallel = new ParallelBlock(new[] {new ActivityBlock(parse), new ActivityBlock(count)}, 1);

            Assert.Equal(WorkflowType.Parallel, parallel.Type);
            Assert.Equal(new[] {typeof (string)}, parallel.InputTypes);
            Assert.Equal(typeof (IEnumerable<object>), parallel.OutputType);

            // test method with signature void(void)
            parallel = new ParallelBlock(new[] {new ActivityBlock(new Action(delegate { }))}, 1);
            Assert.Equal(new Type[0], parallel.InputTypes);
            Assert.Equal(typeof (void), parallel.OutputType);
        }
Example #4
0
        public async Task TestParallel()
        {
            Func<int, string> stringify = x => x.ToString();
            Func<int, int> identity = x => x;

            var parallel = new ParallelBlock(new[] {new ActivityBlock(stringify), new ActivityBlock(identity)}, 1);
            var workflow = new Workflow<int, IEnumerable<object>>("test", parallel);
            var output = (await WorkflowRunner.Run(workflow, 1)).ToArray();

            Assert.Equal(2, output.Length);
            Assert.Equal("1", output[0]);
            Assert.Equal(1, output[1]);
        }