Exemplo n.º 1
0
        public void Test_ManuallyCreateProcess()
        {
            var process = new Process();

            var act1 = new Activity("act1");
            var act2 = new Activity("act2");
            var act3 = new Activity("act3");
            var act4 = new Activity("act4");

            var trans0 = new Transition();

            trans0.Destination = act1;
            act1.AddIncomingTransition(trans0);

            var trans1 = new Transition();

            trans1.Source      = act1;
            trans1.Destination = act2;
            act1.AddOutgoingTransition(trans1);

            var trans2 = new Transition();

            trans2.Source      = act1;
            trans2.Destination = act3;
            act1.AddOutgoingTransition(trans2);

            var trans3 = new Transition();

            trans3.Source      = act2;
            trans3.Destination = act4;
            act2.AddIncomingTransition(trans1);
            act2.AddOutgoingTransition(trans3);

            var trans4 = new Transition();

            trans4.Source      = act3;
            trans4.Destination = act4;
            act3.AddIncomingTransition(trans2);
            act3.AddOutgoingTransition(trans4);

            act2.AddExecution(_ =>
            {
                return((c, t) =>
                {
                    c.Set("state", "waiting");
                    return Task.CompletedTask;
                });
            });

            act3.AddExecution(_ =>
            {
                return((c, t) =>
                {
                    int total = c.Get("total", 0);
                    int current = t.Get("price", 26);
                    c.Set("total", total + current);
                    return Task.CompletedTask;
                });
            });

            act4.AddIncomingTransition(trans3);
            act4.AddIncomingTransition(trans4);

            var initData = new Dictionary <string, object>();

            process.Dispatcher.CreateWalker(trans0, null);

            process.Start(initData);

            Assert.Null(process.Context.Get <string>("waiting"));
            Assert.Equal(26, process.Context.Get <int>("total"));
        }