예제 #1
0
        public async Task Middleware_IsExecutedInOrder()
        {
            var middleware = new List <IJobHostHttpMiddleware>
            {
                new TestMiddleware1(),
                new TestMiddleware2()
            };

            var pipeline = new DefaultMiddlewarePipeline(middleware);

            var context = new DefaultHttpContext();

            context.Items["middlewarelist"] = string.Empty;

            RequestDelegate requestDelegate = c =>
            {
                c.Items.Add(nameof(requestDelegate), string.Empty);

                return(Task.CompletedTask);
            };

            context.Items.Add(ScriptConstants.JobHostMiddlewarePipelineRequestDelegate, requestDelegate);

            await pipeline.Pipeline(context);

            Assert.Contains(nameof(TestMiddleware1) + nameof(TestMiddleware2), context.Items["middlewarelist"].ToString());
        }
예제 #2
0
        public async Task RequestMiddleware_IsExecuted()
        {
            var pipeline = new DefaultMiddlewarePipeline(new List <IJobHostHttpMiddleware>());

            var context = new DefaultHttpContext();

            RequestDelegate requestDelegate = c =>
            {
                c.Items.Add(nameof(requestDelegate), string.Empty);

                return(Task.CompletedTask);
            };

            context.Items.Add(ScriptConstants.JobHostMiddlewarePipelineRequestDelegate, requestDelegate);

            await pipeline.Pipeline(context);

            Assert.Contains(nameof(requestDelegate), context.Items);
        }