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); }
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); }
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(); }
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(); }
public static HttpConnectPipelineBuilder UseHttpClient(this HttpConnectPipelineBuilder builder) { return(builder.UseHttpClient(s_httpClient)); }