Ejemplo n.º 1
0
        public void WhenAddingMultipleActionsToThePipelineWithUseThenAllActionsAreTriggered()
        {
            bool trigger1 = false, trigger2 = false, trigger3 = false;
            var  builder = new HttpConnectPipelineBuilder();

            builder.Use((next) => ctx =>
            {
                trigger1 = true;
                return(next.Invoke(ctx));
            });
            builder.Use((next) => ctx =>
            {
                trigger2 = true;
                return(next.Invoke(ctx));
            });
            builder.Use((next) => ctx =>
            {
                trigger3 = true;
                return(next.Invoke(ctx));
            });
            var pipeline = builder.Build();

            var context = new HttpConnectContext();

            pipeline.Invoke(context);

            trigger1.Should().BeTrue();
            trigger2.Should().BeTrue();
            trigger3.Should().BeTrue();
        }
        public static HttpConnectPipelineBuilder UseHttpClient(
            this HttpConnectPipelineBuilder builder,
            HttpClient httpClient)
        {
            HttpClientMiddleware httpClientMiddleware = new HttpClientMiddleware(httpClient);

            builder.Use((next) => (ctx) => httpClientMiddleware.Invoke(ctx));

            return(builder);
        }
Ejemplo n.º 3
0
        public void WhenOneActionBlocksThePipelineWithAllActionsAreNotTriggered()
        {
            bool trigger1 = false, trigger2 = false;
            var  builder = new HttpConnectPipelineBuilder();

            builder.Use((next) => ctx =>
            {
                trigger1 = true;
                return(Task.CompletedTask);
            });
            builder.Use((next) => ctx =>
            {
                trigger2 = true;
                return(next.Invoke(ctx));
            });
            var pipeline = builder.Build();

            var context = new HttpConnectContext();

            pipeline.Invoke(context);

            trigger1.Should().BeTrue();
            trigger2.Should().BeFalse();
        }
Ejemplo n.º 4
0
        public void WhenAddingActionToThePipelineWithUseThenActionIsTriggered()
        {
            bool triggered = false;
            var  builder   = new HttpConnectPipelineBuilder();

            builder.Use((next) => ctx =>
            {
                triggered = true;
                return(next.Invoke(ctx));
            });
            var pipeline = builder.Build();

            var context = new HttpConnectContext();

            pipeline.Invoke(context);

            triggered.Should().BeTrue();
        }