Пример #1
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var sagaWithCompenstate = new SagaBuilder <TestContext>()
                                      .With_Context_State(context)
                                      .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Add_Numbers(ctx);
                ctx.AddError("error adding two numbers");
            }))
                                      .With_Error_Behavior(Domain.Saga.ErrorBehavior.Terminate) // could be Terminate so saga halts at this step
                                      .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Add_Numbers(ctx);
            }))
                                      .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                           (err) =>
            {
                presenter.Respond(err);
            });

            sagaWithCompenstate.Run();
        }
Пример #2
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var workflowResult = new SagaBuilder <TestContext>()
                                 .With_Context_State(context)
                                 .Using_Step(_addTask)
                                 .Using_Step(_plusTenTask)
                                 .Using_Step((ctx) =>
            {
                var input = new TestInput
                {
                    a = ctx.Value1,
                    b = ctx.Result
                };
                var propertyPresenter = new PropertyPresenter <TestResult, ErrorOutput>();
                _useCase.Execute(input, propertyPresenter);
                if (propertyPresenter.IsErrorResponse())
                {
                    throw new Exception();
                }
                ctx.Result = propertyPresenter.SuccessContent.Result;
            })
                                 .With_Finish_Actions(Respond_With_Success(presenter), Respond_With_Error(presenter))
                                 .Run();
        }
Пример #3
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var workflowResult = new SagaBuilder <TestContext>()
                                 .With_Context_State(context)
                                 .Using_Step(_addTask)
                                 .Using_Step(_addWithDiTask)
                                 .With_Roll_Back_Action_On_Error((ctx) =>
            {
                presenter.Respond(new ErrorOutput("Error on step 2"));
            })
                                 .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            })
                                 .Run();
        }
Пример #4
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var sagaWithoutCompenstate = new SagaBuilder <TestContext>()
                                         .With_Context_State(context)
                                         .Using_Step(_addTask)
                                         .Using_Step(_errorTask)
                                         .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                              (err) =>
            {
                presenter.Respond(err);
            });

            var sagaWithCompenstate = new SagaBuilder <TestContext>()
                                      .With_Context_State(context)
                                      .Using_Step(_addTask)
                                      .With_Error_Behavior(Domain.Saga.ErrorBehavior.Continue) // could be Terminate so saga halts at this step
                                      .Using_Step(_errorTask)
                                      .With_Roll_Back_Action_On_Error((ctx) =>
            {
                ctx.Result -= 10;
            })
                                      .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                           (err) =>
            {
                presenter.Respond(err);
            });

            sagaWithCompenstate.Run();
            //sagaWithoutCompenstate.Run();
        }
Пример #5
0
 public SagaTests()
 {
     this._saga = new SagaBuilder();
 }
Пример #6
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            // using inline actions
            var sagaWithActions = new SagaBuilder <TestContext>()
                                  .With_Context_State(context)
                                  .Using_Step((ctx) =>
            {
                ctx.Result = ctx.Value1 + ctx.Value2;
            })
                                  .Using_Step((ctx) =>
            {
                ctx.Result += 10;
            })
                                  .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            // using local methods to wrap actions
            var sagaWithActionWrappingMethods = new SagaBuilder <TestContext>()
                                                .With_Context_State(context)
                                                .Using_Step((ctx) =>
            {
                AddTwoNumbers(ctx);
            })
                                                .Using_Step((ctx) =>
            {
                AddTen(ctx);
            })
                                                .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            // using inline async actions
            var sagaWithAsyncActions = new SagaBuilder <TestContext>()
                                       .With_Context_State(context)
                                       .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Task.FromResult(ctx.Result = ctx.Value1 + ctx.Value2);
            }))
                                       .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Task.FromResult(ctx.Result += 10);
            }))
                                       .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            // using Steps
            var sagaWithSteps = new SagaBuilder <TestContext>()
                                .With_Context_State(context)
                                .Using_Step(_addTask)
                                .Using_Step(_plusTenTask)
                                .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            sagaWithActions.Run();
            //sagaWithActionWrappingMethods.Run();
            //sagaWithAsyncActions.Run();
            //sagaWithSteps.Run();
        }