Exemplo 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));
        }
Exemplo 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"));
        }
Exemplo 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");
        }
Exemplo 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"));
        }
Exemplo 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"));
        }
Exemplo 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");
        }
Exemplo 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");
        }
Exemplo 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"));
        }
Exemplo 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");
        }
Exemplo 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));
        }