public async Task Will_execute_each_function_middleware_layer_exactly_once( [Random( 0, 10, 5, Distinct = true )] int segmentCount, [Random( -10000, 10000, 5, Distinct = true )] int input ) { IPipelineBuilder <int, int, int, int> builder = Pipeline.Of <int, int>(); for (var i = 0; i < segmentCount; i++) { builder = builder.Use((x, next) => next(x + 1)); } var calculator = builder.OutputTo(x => x) .BuildPipeline(Resolver.Resolve); var expectedResult = input + segmentCount; var result = await calculator(input); Assert.AreEqual(expectedResult, result); }
public static IPipelineFactory <TRequest, TResponse> OutputTo <TRequest, TProcessRequest, TProcessResponse, TResponse>( this IPipelineBuilder <TRequest, TProcessRequest, TProcessResponse, TResponse> builder, Func <TProcessRequest, Task <TProcessResponse> > process ) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (process is null) { throw new ArgumentNullException(nameof(process)); } return(builder.OutputTo((request, ct) => process(request))); }