Exemple #1
0
        public async Task SimpleFlowElementMapOnError()
        {
            var flow = new FlowBuilder()
                       .Add(
                FlowElementBuilder
                .New()
                .CanExecuteContinue()
                .OnExecute(async(_, _) => new FlowErrorResult()
            {
                ErrorObject = "failed"
            })
                .Build()
                .MapOnError(async(_, _, _) => 42)
                )
                       .Build();

            var flowResult = await flow.RunAsync(4);

            flowResult
            .Should()
            .BeOfType <FlowSuccessResult>()
            .Which.Result
            .Should()
            .Be(42);
        }
Exemple #2
0
        public async Task SimpleFlowElementCanExecuteErrorShouldNotExecuteSecondStep()
        {
            var flow = new FlowBuilder()
                       .Add(
                FlowElementBuilder
                .New()
                .CanExecute(async(i, _) => CanExecuteResult.Error("error"))
                .OnExecute(async(i, _) => throw new Exception("Should not execute step 1"))
                .Build()
                ,
                FlowElementBuilder
                .New()
                .CanExecute(async(i, _) => CanExecuteResult.Continue)
                .OnExecute(async(i, _) => throw new Exception("Should not execute step 2"))
                .Build()
                )
                       .Build();

            var flowResult = await flow.RunAsync(4);

            flowResult
            .Should()
            .BeOfType <FlowErrorResult>()
            .Which.ErrorObject
            .Should().Be("error");
        }
Exemple #3
0
        public async Task SimpleFlowElementCanExecuteSkip()
        {
            var flow = new FlowBuilder()
                       .Add(
                FlowElementBuilder
                .New()
                .CanExecute(async(i, _) => CanExecuteResult.Skip)
                .OnExecute(async(i, _) => (int)i * 2)
                .Build()
                ).Build();

            var flowResult = await flow.RunAsync(4);

            flowResult
            .Should()
            .BeOfType <FlowSuccessResult>()
            .Which.Result
            .Should().Be(4);
        }
Exemple #4
0
        public async Task SimpleFlowElementMapOnSuccess()
        {
            var flow = new FlowBuilder()
                       .Add(
                FlowElementBuilder
                .New()
                .CanExecuteContinue()
                .OnExecute(async(i, _) => (int)i * 2)
                .Build()
                .MapOnSuccess(async(result, _, _) => (int)result.Result * 2)
                )
                       .Build();

            var flowResult = await flow.RunAsync(4);

            flowResult
            .Should()
            .BeOfType <FlowSuccessResult>()
            .Which.Result
            .Should()
            .Be(16);
        }