Exemplo n.º 1
0
        public void Middleware_ShortCircuitsPipeline()
        {
            var builder = new DefaultInvocationPipelineBuilder <FunctionContext>();

            builder.Use(next => context =>
            {
                context.Items.Add("Middleware1", null);
                return(next(context));
            });

            builder.Use(next => context =>
            {
                context.Items.Add("Middleware2", null);

                return(Task.CompletedTask);
            });

            builder.Use(next => context =>
            {
                context.Items.Add("Middleware3", null);
                return(next(context));
            });

            var pipeline = builder.Build();

            var context = _mockContext.Object;

            context.Items = new Dictionary <object, object>();

            pipeline(context);

            Assert.Equal(new[] { "Middleware1", "Middleware2" }, context.Items.Keys);
        }
Exemplo n.º 2
0
        public void Build_BuildsInCorrectOrder()
        {
            var builder = new DefaultInvocationPipelineBuilder <FunctionContext>();

            builder.Use(next => context =>
            {
                context.Items.Add("Middleware1", null);
                return(next(context));
            });

            builder.Use(next => context =>
            {
                context.Items.Add("Middleware2", null);
                return(next(context));
            });

            builder.Use(next => context =>
            {
                context.Items.Add("Middleware3", null);
                return(next(context));
            });

            var pipeline = builder.Build();

            var context = _mockContext.Object;

            context.Items = new Dictionary <object, object>();

            pipeline(context);

            Assert.Equal(new[] { "Middleware1", "Middleware2", "Middleware3" }, context.Items.Keys);
        }