コード例 #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();
        }
コード例 #2
0
        public static HttpConnectPipelineBuilder UseHttpClient(
            this HttpConnectPipelineBuilder builder,
            HttpClient httpClient)
        {
            HttpClientMiddleware httpClientMiddleware = new HttpClientMiddleware(httpClient);

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

            return(builder);
        }
コード例 #3
0
        public void BuildReturnsCallableDelegate()
        {
            var builder  = new HttpConnectPipelineBuilder();
            var pipeline = builder.Build();

            var context = new HttpConnectContext();

            pipeline.Invoke(context);

            context.Response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
コード例 #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();
        }
コード例 #5
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();
        }
コード例 #6
0
 public static HttpConnectPipelineBuilder UseHttpClient(this HttpConnectPipelineBuilder builder)
 {
     return(builder.UseHttpClient(s_httpClient));
 }