Example #1
0
        public void OnError_is_called_when_etl_operation_returns_errors()
        {
            var exception        = new Exception("Whoops!");
            var errorReturningOp = new ActionEtlOperation(ctx => false);

            errorReturningOp.WithErrors(new EtlOperationError(errorReturningOp, exception));
            var errorHandlerCalled = false;

            var pipeline = EtlPipeline.Create(settings => settings
                                              .OnError((ctx, errors) =>
            {
                errorHandlerCalled = true;
                errors.Count().Should().Be(1);
                var err = errors.Single();
                err.Exception.Should().Be(exception);
                err.SourceOperation.Should().Be(errorReturningOp);
                err.HasSourceItem.Should().BeFalse();
                err.SourceNode.Should().BeNull();
                return(true);
            })
                                              )
                           .Run(errorReturningOp)
                           .Execute();

            errorHandlerCalled.Should().BeTrue();
        }
Example #2
0
        public void Do_while_stops_execution_when_loop_returns_error_with_default_error_handling()
        {
            var context = new EtlPipelineContext();

            var items      = new Queue <string>(new[] { "The", "Quick", "Brown", "Foxed", "Jumps", "Over", "The", "Lazy", "Dog" });
            var iterations = 0;

            var getCountOperation = new ActionEtlOperation(ctx =>
            {
                ctx.State["remaining_count"] = items.Count;
                return(true);
            });

            EtlPipeline.Create(settings => settings
                               .UseExistingContext(context)
                               .Named("Do-While Pipeline Test"))
            .Run(getCountOperation)
            .Do(pipeline =>
            {
                pipeline
                .Run(ctx => new ActionEtlOperation(ctx2 =>
                {
                    items.Dequeue();
                    iterations++;
                    return(iterations != 5);
                }))
                .Run(getCountOperation);
            })
            .While(ctx => (int)ctx.State["remaining_count"] > 5)
            .Execute();

            iterations.Should().Be(4);
        }