Exemplo n.º 1
0
        public void TestSimpleFork()
        {
            var eng = new FlowEngine();

            countGood = 0; countBad = 0;

            eng.Start(a => GoodStep(a))
            .ContinueWith(a => BadStep(a))
            .Where(new TupleList <Func <FlowStep, bool>, Action <FlowStep> >
            {
                { a => a.Result.ResultCode == FlowStepResultValues.Success, a => BadStep(a) },
                { a => a.Result.ResultCode == FlowStepResultValues.Failed, a => GoodStep(a) }
            })
            .IfAllSuccess(b => GoodStep(b));

            Assert.AreEqual(3, countGood);
            Assert.AreEqual(1, countBad);

            Assert.AreEqual(countGood + countBad, eng.Steps.Count);
            Assert.AreEqual(countGood, eng.Steps.Count - countBad);
            Assert.AreEqual(countBad, eng.Steps.Count - countGood);

            Assert.IsFalse(eng.AllWasGood());
            Assert.IsTrue(eng.SomethingWasWrong());
        }
Exemplo n.º 2
0
        public void TestSimpleFlow()
        {
            var eng = new FlowEngine();

            countGood = 0; countBad = 0;

            eng.Start(a => GoodStep(a))
            .ContinueWith(a => GoodStep(a))
            .ContinueWith(a => GoodStep(a));

            Assert.AreEqual(countGood, eng.Steps.Count);
            Assert.IsTrue(eng.AllWasGood());
        }
Exemplo n.º 3
0
        public void TestCountBad()
        {
            var eng = new FlowEngine();

            countGood = 0; countBad = 0;

            eng.Start(a => GoodStep(a))
            .ContinueWith(a => BadStep(a))
            .ContinueWith(a => GoodStep(a));

            Assert.AreEqual(countGood + countBad, eng.Steps.Count);
            Assert.AreEqual(countGood, eng.Steps.Count - countBad);
            Assert.AreEqual(countBad, eng.Steps.Count - countGood);

            Assert.IsFalse(eng.AllWasGood());
            Assert.IsTrue(eng.SomethingWasWrong());
        }
Exemplo n.º 4
0
        public void TestRealFlow()
        {
            var eng = new FlowEngine();

            countGood = 0; countBad = 0;

            eng.Start(a => GoodStep(a))
            .ContinueWith(a => GoodStep(a))
            .ContinueWith(a => GoodStep(a))
            .ContinueWith(a =>
            {
                GoodStep(a);
                eng.Start(b => GoodStep(b))
                .IfSuccess(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b));

                eng.Start(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b));

                eng.Start(b => GoodStep(b))
                .IfSuccess(b => GoodStep(b));
            })
            .ContinueWith(a =>
            {
                GoodStep(a);
                eng.Start(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b));

                eng.Start(b => GoodStep(b))
                .IfSuccess(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b));

                eng.Start(b => GoodStep(b))
                .IfSuccess(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b))
                .ContinueWith(b => GoodStep(b));
            });

            Assert.AreEqual(countGood, eng.Steps.Count);
            Assert.IsTrue(eng.AllWasGood());
        }
Exemplo n.º 5
0
        public void TestSimpleCondition()
        {
            var eng = new FlowEngine();

            countGood = 0; countBad = 0;
            eng.Start(a => GoodStep(a))
            .ContinueWith(a => BadStep(a))
            .IfSuccess(a => GoodStep(a))     // This will never be executed
            .IfFailed(a => GoodStep(a));     // This will never be executed

            Assert.AreEqual(1, countGood);

            Assert.AreEqual(countGood + countBad, eng.Steps.Count);
            Assert.AreEqual(countGood, eng.Steps.Count - countBad);
            Assert.AreEqual(countBad, eng.Steps.Count - countGood);

            Assert.IsFalse(eng.AllWasGood());
            Assert.IsTrue(eng.SomethingWasWrong());
        }
Exemplo n.º 6
0
        public void TestSubFlowAffectingResultOfMainFlow()
        {
            var eng = new FlowEngine();

            countGood = 0; countBad = 0;
            eng.Start((a) =>
            {
                GoodStep(a);
            })
            .IfSuccess((a) =>
            {
                var seng = new FlowEngine();
                GoodStep(a);
                seng.Start((b) =>
                {
                    BadStep(b);
                })
                .ContinueWith((b) =>
                {
                    GoodStep(b);
                })
                .ContinueWith((b) =>
                {
                    GoodStep(b);
                });
                if (!seng.AllWasGood())
                {
                    a.Result.ResultCode = FlowStepResultValues.Failed;     //I am affecting the result of the task
                }
            })
            .IfSuccess((a) =>
            {
                GoodStep(a);
            });

            Assert.IsFalse(eng.AllWasGood());
            Assert.AreEqual(countGood, 4);
            Assert.AreEqual(countBad, 1);
        }