Esempio n. 1
0
        public void Operations_work_when_using_objects()
        {
            var wf = new StatefulWorkflow <ITest>("wf");

            wf.Yield(13);
            wf.Do((x, i) => { x.Ping((int)i["i"]); });

            var test = Mock.Of <ITest>(x => (int)x.GetStateId("wf") == 13);
            var mock = Mock.Get(test);

            wf.StartWithParams(test, new { i = 42 });
            mock.Verify(x => x.SetStateId("wf", null));
            mock.Verify(x => x.Ping((int)42));
        }
Esempio n. 2
0
        public void it_can_branch_using_negative_Unless_with_parameters()
        {
            var point = Declare.Step();

            var wf = new StatefulWorkflow<Entity>()
                .Define(point)
                .Yield("branched")
                .Yield("start")
                .Unless((x, opts) => (bool)opts["shouldBranch"]).BranchTo(point)
                .Yield("didn't branch");

            var obj = new Entity() { state = "start" };
            wf.StartWithParams(obj, new { shouldBranch = false });
            Assert.That(obj.GetStateId(null), Is.EqualTo("branched"));
        }
Esempio n. 3
0
        public void it_can_use_params_at_any_step()
        {
            string secondStep = null;
            var wf = new StatefulWorkflow<ITest>("wf");
            wf.Yield(13);
            wf.Do((x, i) => { x.Ping((int)i["i"]); });
            wf.Do((x, opts) => secondStep = (string)opts["o"]);

            var test = Mock.Of<ITest>(x => (int)x.GetStateId("wf") == 13);
            var mock = Mock.Get(test);
            wf.StartWithParams(test, new { i = 42, o = "hello" });
            mock.Verify(x => x.SetStateId("wf", null));
            mock.Verify(x => x.Ping((int)42));
            secondStep.ShouldBe("hello");
        }
Esempio n. 4
0
        public void failed_branches_work_with_parameters()
        {
            var jump = Declare.Step();

            var wf = new StatefulWorkflow<ITest>("wf")
                .Unless((x, opts) => (bool)opts["flag"]).BranchTo(jump)
                .Yield("it didn't jump")
                .Define(jump)
                .Yield("it jumped");

            var test = Mock.Of<ITest>();
            wf.StartWithParams(test, new { flag = true });
            Mock.Get(test).Verify(x => x.SetStateId("wf", "it jumped"), Times.Never());
            Mock.Get(test).Verify(x => x.SetStateId("wf", "it didn't jump"));
        }
Esempio n. 5
0
        public void failed_branches_work_with_parameters()
        {
            var jump = Declare.Step();

            var wf = new StatefulWorkflow <ITest>("wf")
                     .Unless((x, opts) => (bool)opts["flag"]).BranchTo(jump)
                     .Yield("it didn't jump")
                     .Define(jump)
                     .Yield("it jumped");

            var test = Mock.Of <ITest>();

            wf.StartWithParams(test, new { flag = true });
            Mock.Get(test).Verify(x => x.SetStateId("wf", "it jumped"), Times.Never());
            Mock.Get(test).Verify(x => x.SetStateId("wf", "it didn't jump"));
        }
Esempio n. 6
0
        public void it_can_use_params_at_any_step()
        {
            string secondStep = null;
            var    wf         = new StatefulWorkflow <ITest>("wf");

            wf.Yield(13);
            wf.Do((x, i) => { x.Ping((int)i["i"]); });
            wf.Do((x, opts) => secondStep = (string)opts["o"]);

            var test = Mock.Of <ITest>(x => (int)x.GetStateId("wf") == 13);
            var mock = Mock.Get(test);

            wf.StartWithParams(test, new { i = 42, o = "hello" });
            mock.Verify(x => x.SetStateId("wf", null));
            mock.Verify(x => x.Ping((int)42));
            secondStep.ShouldBe("hello");
        }
Esempio n. 7
0
        public void it_can_access_data_from_lambda()
        {
            bool lambdaCalled = false;
            var wf = new StatefulWorkflow<Entity>()
                .Yield("start")
                .When(x => true).Fail(f => f.With((o, opts) =>
                {
                    lambdaCalled = true;
                    Assert.That(opts, Is.Not.Null);
                    Assert.That(opts["option"], Is.EqualTo("this"));
                    return "failed successfully";
                }))
                .Yield("end");

            Assert.Throws<WorkflowActionFailedException>(() =>
            wf.StartWithParams(new Entity() { state = "start" }, new { option = "this" }));
            Assert.That(lambdaCalled, "lambda builder function should be called");
        }
Esempio n. 8
0
        public void it_can_branch_using_positive_Unless_with_parameters()
        {
            var point = Declare.Step();

            var wf = new StatefulWorkflow <Entity>()
                     .Define(point)
                     .Yield("branched")
                     .Yield("start")
                     .Unless((x, opts) => (bool)opts["shouldBranch"]).BranchTo(point)
                     .Yield("didn't branch");

            var obj = new Entity()
            {
                state = "start"
            };

            wf.StartWithParams(obj, new { shouldBranch = true });
            Assert.That(obj.GetStateId(null), Is.EqualTo("didn't branch"));
        }
Esempio n. 9
0
        public void it_can_access_data_from_lambda()
        {
            bool lambdaCalled = false;
            var  wf           = new StatefulWorkflow <Entity>()
                                .Yield("start")
                                .When(x => true).Fail(f => f.With((o, opts) =>
            {
                lambdaCalled = true;
                Assert.That(opts, Is.Not.Null);
                Assert.That(opts["option"], Is.EqualTo("this"));
                return("failed successfully");
            }))
                                .Yield("end");

            Assert.Throws <WorkflowActionFailedException>(() =>
                                                          wf.StartWithParams(new Entity()
            {
                state = "start"
            }, new { option = "this" }));
            Assert.That(lambdaCalled, "lambda builder function should be called");
        }
Esempio n. 10
0
        public void Operations_work_when_using_objects()
        {
            var wf = new StatefulWorkflow<ITest>("wf");
            wf.Yield(13);
            wf.Do((x, i) => { x.Ping((int)i["i"]); });

            var test = Mock.Of<ITest>(x => (int)x.GetStateId("wf") == 13);
            var mock = Mock.Get(test);
            wf.StartWithParams(test, new { i = 42 });
            mock.Verify(x => x.SetStateId("wf", null));
            mock.Verify(x => x.Ping((int)42));
        }