public async Task TestMiddlewareOrder()
        {
            StringBuilder sb = new StringBuilder();

            _pipelineBuilder.Use(async(ctx, next) =>
            {
                sb.AppendLine("  Middleware 1");
                await next();
            });
            _pipelineBuilder.Use(async(ctx, next) =>
            {
                sb.AppendLine("  Middleware 2");
                await next();
            });
            _pipelineBuilder.Use(async(ctx, next) =>
            {
                sb.AppendLine("  Middleware 3");
                await next();
            });
            _pipelineBuilder.Use(async(ctx, next) =>
            {
                sb.AppendLine("  Middleware 4");
                await next();
            });
            _pipelineBuilder.Use(async(ctx, next) =>
            {
                sb.AppendLine("  Middleware 5");
                await next();
            });

            var func = _pipelineBuilder.Build();
            await func.Invoke(_ctx, async() => { });

            //Just test! I know its stupid.
            var testInfo = sb.ToString();
            var str      = RemoveWhiteSpace(testInfo);

            if ("12345" != str)
            {
                Assert.Fail("Expected order: 1-2-3-4-5.\n" +
                            "Middleware execution order:\n" +
                            testInfo);
            }
            else
            {
                Assert.Pass();
            }
        }
        public MethodChain2()
        {
            IPipelineBuilder builder = null;

            builder.Pipeline("myPipeline").
            TriggerOn(TriggerType.Push).
            AddGlobals().
            RunsOn(OperatingSystem.UbuntuLatest).
            SetEnvVar("MY_ENV_VAR", "HELLO WORLD!").
            AddStep("Default Checkout step").
            AsAction().
            SetName("Checkout").
            Execute("actions/checkout@v2").
            AddStep("Default clean step").
            AsShell().
            Execute("echo \"My Global Job\"").
            Execute("mvn clean").
            InDirectory("./TANKS").
            AddJob("compile").
            AddStep("Compile Step").
            AsShell().
            Execute("mvn compile").
            InDirectory("./TANKS").
            AddJob("compile").
            AddStep("Compile Step").
            AsShell().
            Execute("mvn compile").
            InDirectory("./TANKS");

            builder.Build();
            builder.Collect();
        }
Exemplo n.º 3
0
        public async Task TestWithDependencyInjection()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddSingleton <IStepTracker, StepTracker>();
            services.AddSingleton <IStepA, StepA>();
            services.AddSingleton <IStepB, StepB>();
            services.AddSingleton <IStepC, StepC>();
            services.AddSingleton <IStepD, StepD>();
            services.AddSingleton <IPipelineBuilder, PipelineBuilder>();

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            IPipelineBuilder pipelineBuilder = serviceProvider.GetRequiredService <IPipelineBuilder>();

            IPipeline pipeline = pipelineBuilder.Build();

            await pipeline.Run();

            //IStepTracker is a dependency for StepA and StepB. It has been injected by the DI container.
            IStepTracker stepTracker = serviceProvider.GetRequiredService <IStepTracker>();

            List <string> traces = stepTracker.GetTraces();

            Assert.AreEqual(4, traces.Count);
            Assert.AreEqual("StepA", traces[0]);
            Assert.AreEqual("StepB", traces[1]);
            Assert.AreEqual("StepC", traces[2]);
            Assert.AreEqual("StepD", traces[3]);
        }
 public static Pipeline Build(this IPipelineBuilder builder)
 {
     return(builder.Build(new NoRetryFailureHandlingStrategy()));
 }
Exemplo n.º 5
0
 private void BuildPipeline()
 {
     _pipeline = _blockProcessorPipelineBuilder.Build();
 }